##// END OF EJS Templates
typing: add type hints to mpatch implementations...
Matt Harbison -
r50494:94a79703 default
parent child Browse files
Show More
@@ -6,6 +6,8 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8
8
9 from typing import List
10
9 from ..pure.mpatch import *
11 from ..pure.mpatch import *
10 from ..pure.mpatch import mpatchError # silence pyflakes
12 from ..pure.mpatch import mpatchError # silence pyflakes
11 from . import _mpatch # pytype: disable=import-error
13 from . import _mpatch # pytype: disable=import-error
@@ -26,7 +28,7 b' def cffi_get_next_item(arg, pos):'
26 return container[0]
28 return container[0]
27
29
28
30
29 def patches(text, bins):
31 def patches(text: bytes, bins: List[bytes]) -> bytes:
30 lgt = len(bins)
32 lgt = len(bins)
31 all = []
33 all = []
32 if not lgt:
34 if not lgt:
@@ -9,6 +9,11 b''
9 import io
9 import io
10 import struct
10 import struct
11
11
12 from typing import (
13 List,
14 Tuple,
15 )
16
12
17
13 stringio = io.BytesIO
18 stringio = io.BytesIO
14
19
@@ -28,7 +33,9 b' class mpatchError(Exception):'
28 # temporary string buffers.
33 # temporary string buffers.
29
34
30
35
31 def _pull(dst, src, l): # pull l bytes from src
36 def _pull(
37 dst: List[Tuple[int, int]], src: List[Tuple[int, int]], l: int
38 ) -> None: # pull l bytes from src
32 while l:
39 while l:
33 f = src.pop()
40 f = src.pop()
34 if f[0] > l: # do we need to split?
41 if f[0] > l: # do we need to split?
@@ -39,7 +46,7 b' def _pull(dst, src, l): # pull l bytes '
39 l -= f[0]
46 l -= f[0]
40
47
41
48
42 def _move(m, dest, src, count):
49 def _move(m: stringio, dest: int, src: int, count: int) -> None:
43 """move count bytes from src to dest
50 """move count bytes from src to dest
44
51
45 The file pointer is left at the end of dest.
52 The file pointer is left at the end of dest.
@@ -50,7 +57,9 b' def _move(m, dest, src, count):'
50 m.write(buf)
57 m.write(buf)
51
58
52
59
53 def _collect(m, buf, list):
60 def _collect(
61 m: stringio, buf: int, list: List[Tuple[int, int]]
62 ) -> Tuple[int, int]:
54 start = buf
63 start = buf
55 for l, p in reversed(list):
64 for l, p in reversed(list):
56 _move(m, buf, p, l)
65 _move(m, buf, p, l)
@@ -58,7 +67,7 b' def _collect(m, buf, list):'
58 return (buf - start, start)
67 return (buf - start, start)
59
68
60
69
61 def patches(a, bins):
70 def patches(a: bytes, bins: List[bytes]) -> bytes:
62 if not bins:
71 if not bins:
63 return a
72 return a
64
73
@@ -111,7 +120,7 b' def patches(a, bins):'
111 return m.read(t[0])
120 return m.read(t[0])
112
121
113
122
114 def patchedsize(orig, delta):
123 def patchedsize(orig: int, delta: bytes) -> int:
115 outlen, last, bin = 0, 0, 0
124 outlen, last, bin = 0, 0, 0
116 binend = len(delta)
125 binend = len(delta)
117 data = 12
126 data = 12
General Comments 0
You need to be logged in to leave comments. Login now