From 034d2e4746f066de41ca1dbf94b02087507819ce Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Thu, 18 Apr 2013 14:19:45 +0200 Subject: [PATCH] - http_request: do not use a memoryview for python27 python27's mmap does not behave like a bytearray therefore we cannot directly pass it to the memoryview. --- osc/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osc/core.py b/osc/core.py index 039224a5..d7761e14 100644 --- a/osc/core.py +++ b/osc/core.py @@ -2871,6 +2871,13 @@ def makeurl(baseurl, l, query=[]): def http_request(method, url, headers={}, data=None, file=None, timeout=100): """wrapper around urllib2.urlopen for error handling, and to support additional (PUT, DELETE) methods""" + def create_memoryview(obj): + if sys.version_info < (2, 7, 99): + # obj might be a mmap and python 2.7's mmap does not + # behave like a bytearray (a bytearray in turn can be used + # to create the memoryview). For now simply return a buffer + return buffer(obj) + return memoryview(obj) filefd = None @@ -2914,7 +2921,7 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100): data = mmap.mmap(filefd.fileno(), os.path.getsize(file), mmap.MAP_SHARED, mmap.PROT_READ) else: data = mmap.mmap(filefd.fileno(), os.path.getsize(file)) - data = memoryview(data) + data = create_memoryview(data) except EnvironmentError as e: if e.errno == 19: sys.exit('\n\n%s\nThe file \'%s\' could not be memory mapped. It is ' \