changeset 30821:7005c03f7387

util: add length argument to util.buffer() util.buffer() either returns inbuilt buffer function or defines a new one which slices. The inbuilt buffer() also has a length argument which is missing from the ones we defined. This patch adds that length argument.
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 14 Jan 2017 20:05:15 +0530
parents 6a70cf94d1b5
children b54a2984cdd4
files mercurial/util.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Sun Jan 15 13:17:05 2017 +0530
+++ b/mercurial/util.py	Sat Jan 14 20:05:15 2017 +0530
@@ -238,10 +238,14 @@
     buffer = buffer
 except NameError:
     if not pycompat.ispy3:
-        def buffer(sliceable, offset=0):
+        def buffer(sliceable, offset=0, length=None):
+            if length is not None:
+                return sliceable[offset:offset + length]
             return sliceable[offset:]
     else:
-        def buffer(sliceable, offset=0):
+        def buffer(sliceable, offset=0, length=None):
+            if length is not None:
+                return memoryview(sliceable)[offset:offset + length]
             return memoryview(sliceable)[offset:]
 
 closefds = pycompat.osname == 'posix'