Re: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ?

2009-01-12 Thread Steve Holden
Gabriel Genellina wrote:
> En Sun, 11 Jan 2009 08:12:27 -0200, Barak, Ron 
> escribió:
> 
>> I googled a bit, and found http://bugs.python.org/issue1355023.
>> It seems that this patch implemented fuller seek() for GzipFile around
>> November 2006 (including whence==2).
>> Do I misunderstand and this patch was not actually implemented,
>> namely, is seek(-n,2) not implemented in Python 2.5.2 ?
>>
>> The source of gzip.py on my system seems to suggest that negative
>> seeks are supported:
> 
> The source comments are misleading: "negative seeks" means seeking
> backwards (towards the beginning of the file), not offset<0.
> The second argument to seek (whence) was added in 2.6, and only accepts 0
> or 1; whence==2 isn't supported.
> 
Specifically in the case of a zip file that means the whole entry would
need to be expanded to allow such a seek to take place from the end of
the file; hence there are good pragmatic reasons for the restriction.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ?

2009-01-11 Thread Gabriel Genellina

En Sun, 11 Jan 2009 08:12:27 -0200, Barak, Ron 
escribió:


I googled a bit, and found http://bugs.python.org/issue1355023.
It seems that this patch implemented fuller seek() for GzipFile around  
November 2006 (including whence==2).
Do I misunderstand and this patch was not actually implemented, namely,  
is seek(-n,2) not implemented in Python 2.5.2 ?


The source of gzip.py on my system seems to suggest that negative seeks  
are supported:


The source comments are misleading: "negative seeks" means seeking
backwards (towards the beginning of the file), not offset<0.
The second argument to seek (whence) was added in 2.6, and only accepts 0
or 1; whence==2 isn't supported.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ?

2009-01-11 Thread Mark Tolonen
"Barak, Ron"  wrote in message 
news:7f0503cd69378f49be0dc30661c6ccf602494...@enbmail01.lsi.com...
The source of gzip.py on my system seems to suggest that negative seeks 
are supported:


def seek(self, offset):
if self.mode == WRITE:
if offset < self.offset:
raise IOError('Negative seek in write mode')
count = offset - self.offset
for i in range(count // 1024):
self.write(1024 * '\0')
self.write((count % 1024) * '\0')
elif self.mode == READ:
if offset < self.offset:
# for negative seek, rewind and do positive seek
self.rewind()
count = offset - self.offset
for i in range(count // 1024):
self.read(1024)
self.read(count % 1024)

Could any who're familiar with the inner working of gzip settle this issue 
?

Is seek from EOF supported for gzip files ?


Source from 2.6.1.  Seek from EOF not supported:

   def seek(self, offset, whence=0):
   if whence:
   if whence == 1:
   offset = self.offset + offset
   else:
   raise ValueError('Seek from end not supported')
   if self.mode == WRITE:
   if offset < self.offset:
   raise IOError('Negative seek in write mode')
   count = offset - self.offset
   for i in range(count // 1024):
   self.write(1024 * '\0')
   self.write((count % 1024) * '\0')
   elif self.mode == READ:
   if offset < self.offset:
   # for negative seek, rewind and do positive seek
   self.rewind()
   count = offset - self.offset
   for i in range(count // 1024):
   self.read(1024)
   self.read(count % 1024)

-Mark


--
http://mail.python.org/mailman/listinfo/python-list