def __init__(self, path): self.path = path if path == '-': source = sys.stdin else: try: source = file(path) self.mode = os.stat(path).st_mode except: rox.report_exception() sys.exit(1) self.path = path start = source.read(300) try: if source is sys.stdin: raise Exception("Always copy stdin!") source.seek(0) self.source = source except: # Input is not a regular, local, seekable file, so copy it # to a local temp file. import shutil tmp = Tmp() tmp.write(start) tmp.flush() shutil.copyfileobj(source, tmp) tmp.seek(0) tmp.flush() self.source = tmp self.default = self.guess_format(start) if path == '-': name = 'Data' else: name = path for ext in known_extensions: if path.endswith('.' + ext): new = path[:-len(ext)-1] if len(new) < len(name): name = new if self.default.add_extension: name += '.' + self.default.extension if name == path: # Default name is same as input. Change it somehow... if '.' in os.path.basename(name): name = name[:name.rindex('.')] else: name += '.unpacked' self.default_name = name