def decompress_bz2(filepath):
download_photo(filepath)
try:
# Open the BZ2 file
zipfile = bz2.BZ2File(filepath)
# Get the decompressed data
data = zipfile.read()
# Assuming the filepath ends with .bz2
newfilepath = filepath[:-4]
# Write an uncompressed file
open(newfilepath, 'wb').write(data)
return newfilepath
except IOError as e:
print "[!] Please verifiy you entered the correct cookie value.\n"
print e
python类read()的实例源码
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def parsed_wheel_info(self):
"""Parse wheel metadata (the .data/WHEEL file)"""
return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
def searchUnpackKnownAr(filename, tempdir=None, scanenv={}, debug=False):
## first check if the file actually could be a valid ar file
arfile = open(filename, 'rb')
arfile.seek(0)
arheader = arfile.read(7)
arfile.close()
if arheader != fsmagic.fsmagic['ar']:
return ([], [], [], {})
## then try unpacking it.
res = searchUnpackAr(filename, tempdir, [], {'ar': [0]}, scanenv, debug)
(diroffsets, blacklist, newtags, hints) = res
failed = False
## there were results, so check if they were successful
if diroffsets != []:
if len(diroffsets) != 1:
failed = True
else:
(dirpath, startoffset, endoffset) = diroffsets[0]
if startoffset != 0 or endoffset != os.stat(filename).st_size:
failed = True
if failed:
for i in diroffsets:
(dirpath, startoffset, endoffset) = i
try:
shutil.rmtree(dirpath)
except:
pass
return ([], [], [], {})
else:
return (diroffsets, blacklist, newtags, hints)
return ([], [], [], {})
def gzipcrc32(filename):
datafile = open(filename, 'rb')
datafile.seek(0)
databuffer = datafile.read(10000000)
crc32 = binascii.crc32('')
while databuffer != '':
crc32 = binascii.crc32(databuffer, crc32)
databuffer = datafile.read(10000000)
datafile.close()
crc32 = crc32 & 0xffffffff
return crc32
def searchUnpackKnownGzip(filename, tempdir=None, scanenv={}, debug=False):
## first check if the file actually could be a valid gzip file
gzipfile = open(filename, 'rb')
gzipfile.seek(0)
gzipheader = gzipfile.read(3)
gzipfile.close()
if gzipheader != fsmagic.fsmagic['gzip']:
return ([], [], [], {})
## then try unpacking it.
res = searchUnpackGzip(filename, tempdir, [], {'gzip': [0]}, scanenv, debug)
(diroffsets, blacklist, newtags, hints) = res
failed = False
## there were results, so check if they were successful
if diroffsets != []:
if len(diroffsets) != 1:
failed = True
else:
(dirpath, startoffset, endoffset) = diroffsets[0]
if startoffset != 0 or endoffset != os.stat(filename).st_size:
failed = True
if failed:
for i in diroffsets:
(dirpath, startoffset, endoffset) = i
try:
shutil.rmtree(dirpath)
except:
pass
return ([], [], [], {})
else:
return (diroffsets, blacklist, newtags, hints)
return ([], [], [], {})
def searchUnpackRZIP(filename, tempdir=None, blacklist=[], offsets={}, scanenv={}, debug=False):
hints = {}
if not 'rzip' in offsets:
return ([], blacklist, [], hints)
if offsets['rzip'] == []:
return ([], blacklist, [], hints)
if offsets['rzip'][0] != 0:
return ([], blacklist, [], hints)
if os.stat(filename).st_size < 10:
return ([], blacklist, [], hints)
diroffsets = []
tags = []
offset = 0
rzipfile = open(filename, 'rb')
rzipfile.seek(0)
rzipdata = rzipfile.read(10)
rzipfile.close()
rzipsize = struct.unpack('>L', rzipdata[6:10])[0]
blacklistoffset = extractor.inblacklist(offset, blacklist)
if blacklistoffset != None:
return (diroffsets, blacklist, tags, hints)
tmpdir = dirsetup(tempdir, filename, "rzip", 1)
res = unpackRZIP(filename, offset, rzipsize, tmpdir)
if res != None:
rzipdir = res
diroffsets.append((rzipdir, offset, 0))
#blacklist.append((offset, offset + unpackrzipsize))
#if offset == 0:
# tags.append("compressed")
# tags.append("rzip")
else:
## cleanup
os.rmdir(tmpdir)
return (diroffsets, blacklist, tags, hints)
def searchUnpackAndroidSparse(filename, tempdir=None, blacklist=[], offsets={}, scanenv={}, debug=False):
hints = {}
if not 'android-sparse' in offsets:
return ([], blacklist, [], hints)
if offsets['android-sparse'] == []:
return ([], blacklist, [], hints)
diroffsets = []
counter = 1
tags = []
for offset in offsets['android-sparse']:
blacklistoffset = extractor.inblacklist(offset, blacklist)
if blacklistoffset != None:
continue
## first see if the major version is correct
sparsefile = open(filename, 'rb')
sparsefile.seek(offset+4)
sparsedata = sparsefile.read(2)
sparsefile.close()
if len(sparsedata) != 2:
break
majorversion = struct.unpack('<H', sparsedata)[0]
if not majorversion == 1:
continue
tmpdir = dirsetup(tempdir, filename, "android-sparse", counter)
res = unpackAndroidSparse(filename, offset, tmpdir)
if res != None:
(sparsesize, sparsedir) = res
diroffsets.append((sparsedir, offset, sparsesize))
blacklist.append((offset, offset + sparsesize))
counter = counter + 1
else:
## cleanup
os.rmdir(tmpdir)
return (diroffsets, blacklist, tags, hints)