class Engine: sentinal = bytes('ENCODED\n', 'utf-8') # used to determine if the correct key was used # to decrypt the file def __init__(self, filename, encrypter): self.name = filename self.fp = None self._sfp = None self.mode = None self.encrypter = encrypter def __del__(self): self.close() def __repr__(self): return '<%s "%s">' % (self.__class__.__name__, self.name) def open(self): try: from ioXXX import StringIO except ImportError: try: from cStringIO import StringIO except ImportError: from StringIO import StringIO self.fp = StringIO() self._sfp = open(self.name, self._filemode) self.mode = self._filemode.replace("b", "") def close(self): if self.fp: self.fp = None self.mode = None if self._sfp: self._sfp.close() self._sfp = None def seek(self, pos, whence=0): if self.fp: self.fp.seek(0, whence)
def open(self): try: from ioXXX import StringIO except ImportError: try: from cStringIO import StringIO except ImportError: from StringIO import StringIO self.fp = StringIO() self._sfp = open(self.name, self._filemode) self.mode = self._filemode.replace("b", "")