##// END OF EJS Templates
bundle2.unpackermixin: control for underlying file descriptor...
Eric Sumner -
r24026:3daef83a default
parent child Browse files
Show More
@@ -145,6 +145,7 b' future, dropping the stream may become a'
145 145 preserve.
146 146 """
147 147
148 import errno
148 149 import sys
149 150 import util
150 151 import struct
@@ -484,6 +485,8 b' class unpackermixin(object):'
484 485
485 486 def __init__(self, fp):
486 487 self._fp = fp
488 self._seekable = (util.safehasattr(fp, 'seek') and
489 util.safehasattr(fp, 'tell'))
487 490
488 491 def _unpack(self, format):
489 492 """unpack this struct format from the stream"""
@@ -494,6 +497,29 b' class unpackermixin(object):'
494 497 """read exactly <size> bytes from the stream"""
495 498 return changegroup.readexactly(self._fp, size)
496 499
500 def seek(self, offset, whence):
501 """move the underlying file pointer"""
502 if self._seekable:
503 return self._fp.seek(offset, whence)
504 else:
505 raise NotImplementedError(_('File pointer is not seekable'))
506
507 def tell(self):
508 """return the file offset, or None if file is not seekable"""
509 if self._seekable:
510 try:
511 return self._fp.tell()
512 except IOError, e:
513 if e.errno == errno.ESPIPE:
514 self._seekable = False
515 else:
516 raise
517 return None
518
519 def close(self):
520 """close underlying file"""
521 if util.safehasattr(self._fp, 'close'):
522 return self._fp.close()
497 523
498 524 class unbundle20(unpackermixin):
499 525 """interpret a bundle2 stream
General Comments 0
You need to be logged in to leave comments. Login now