##// END OF EJS Templates
statichttprepo: stop shadowing the `bytes` builtin...
Matt Harbison -
r52793:77a9c7d8 default
parent child Browse files
Show More
@@ -52,14 +52,14 class httprangereader:
52 def seek(self, pos):
52 def seek(self, pos):
53 self.pos = pos
53 self.pos = pos
54
54
55 def read(self, bytes: int = -1):
55 def read(self, n: int = -1):
56 req = urlreq.request(pycompat.strurl(self.url))
56 req = urlreq.request(pycompat.strurl(self.url))
57 end = ''
57 end = ''
58
58
59 if bytes == 0:
59 if n == 0:
60 return b''
60 return b''
61 elif bytes > 0:
61 elif n > 0:
62 end = "%d" % (self.pos + bytes - 1)
62 end = "%d" % (self.pos + n - 1)
63 if self.pos or end:
63 if self.pos or end:
64 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
64 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
65
65
@@ -79,14 +79,14 class httprangereader:
79 if code == 200:
79 if code == 200:
80 # HTTPRangeHandler does nothing if remote does not support
80 # HTTPRangeHandler does nothing if remote does not support
81 # Range headers and returns the full entity. Let's slice it.
81 # Range headers and returns the full entity. Let's slice it.
82 if bytes > 0 and (self.pos + bytes) < len(data):
82 if n > 0 and (self.pos + n) < len(data):
83 data = data[self.pos : self.pos + bytes]
83 data = data[self.pos : self.pos + n]
84 elif self.pos < len(data):
84 elif self.pos < len(data):
85 data = data[self.pos :]
85 data = data[self.pos :]
86 else:
86 else:
87 data = b''
87 data = b''
88 elif 0 < bytes < len(data):
88 elif 0 < n < len(data):
89 data = data[:bytes]
89 data = data[:n]
90 self.pos += len(data)
90 self.pos += len(data)
91 return data
91 return data
92
92
General Comments 0
You need to be logged in to leave comments. Login now