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