patch the uncompress module to be able to deal with remote file
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
#cython: language_level=3
|
||||
|
||||
cdef class MagicKeyFile:
|
||||
cdef object stream
|
||||
cdef str stream_mode
|
||||
cdef object binary
|
||||
cdef bytes key
|
||||
cdef int keylength
|
||||
cdef int keylength
|
||||
cdef int pos
|
||||
|
||||
cpdef bytes read(self,int size=?)
|
||||
|
@ -15,17 +15,20 @@ import io
|
||||
cdef class MagicKeyFile:
|
||||
def __init__(self,stream,length=2):
|
||||
|
||||
self.stream_mode = None
|
||||
binary=stream
|
||||
self.stream = stream
|
||||
self.stream_mode = None
|
||||
if hasattr(stream, "mode"):
|
||||
self.stream_mode = stream.mode
|
||||
if 'b' in stream.mode:
|
||||
binary=stream
|
||||
elif hasattr(stream, "buffer") and 'b' in stream.buffer.mode:
|
||||
if (not 'b' in stream.mode and
|
||||
hasattr(stream, "buffer") and
|
||||
'b' in stream.buffer.mode):
|
||||
binary=stream.buffer
|
||||
else:
|
||||
self.stream_mode = None
|
||||
|
||||
if self.stream_mode is None:
|
||||
|
||||
if (self.stream_mode is None and
|
||||
not (hasattr(stream, 'headers') and
|
||||
hasattr(stream.headers, "keys") and
|
||||
'Content-type' in stream.headers)):
|
||||
raise TypeError("stream does not present the good interface")
|
||||
|
||||
self.binary=binary
|
||||
@ -94,9 +97,12 @@ cdef class CompressedFile:
|
||||
|
||||
if self.accessor is None:
|
||||
self.accessor = magic
|
||||
|
||||
|
||||
if 'b' not in magic.stream_mode:
|
||||
|
||||
if ((hasattr(stream, 'headers') and
|
||||
hasattr(stream.headers, "keys") and
|
||||
'Content-type' in stream.headers and
|
||||
stream.headers['Content-type'].startswith('text/')) or
|
||||
'b' not in magic.stream_mode):
|
||||
self.accessor = io.TextIOWrapper(self.accessor)
|
||||
|
||||
|
||||
@ -105,7 +111,4 @@ cdef class CompressedFile:
|
||||
|
||||
def __iter__(self):
|
||||
for x in self.accessor:
|
||||
yield x
|
||||
|
||||
|
||||
|
||||
yield x
|
Reference in New Issue
Block a user