本文整理汇总了Python中zipfile.read函数的典型用法代码示例。如果您正苦于以下问题:Python read函数的具体用法?Python read怎么用?Python read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: read_metadata
def read_metadata(zipfile):
for info in zipfile.infolist():
basename = os.path.basename(info.filename)
if basename == METADATA_FILENAME:
meta_file = zipfile.read(info.filename)
return kbjson.loads(meta_file)
return {}
开发者ID:Shelvak,项目名称:kegbot-server,代码行数:7,代码来源:backup.py
示例2: save_extracted_file
def save_extracted_file(self, zipfile, filename):
"Extract the file to a temp directory for viewing"
try:
filebytes = zipfile.read(filename)
except BadZipfile, err:
print 'Error opening the zip file: %s' % (err)
return False
开发者ID:leonardcj,项目名称:read-sd-comics,代码行数:7,代码来源:readsdcomics.py
示例3: read_info_file
def read_info_file(zipfile, path, section):
"""Return a dictionary matching the contents of the config file at
path in zipfile"""
cp = SafeConfigParser()
info = StringIO(zipfile.read(path))
cp.readfp(info)
return dict(cp.items(section))
开发者ID:NROER,项目名称:xsce,代码行数:7,代码来源:__init__.py
示例4: extract_member
def extract_member(zipfile, member, dstdir):
"""Copied and adjusted from Python 2.6 stdlib zipfile.py module.
Extract the ZipInfo object 'member' to a physical
file on the path targetpath.
"""
assert dstdir.endswith(os.path.sep), "/ missing at end"
fn = member.filename
if isinstance(fn, str):
fn = unicode(fn, "utf-8")
targetpath = os.path.normpath(os.path.join(dstdir, fn))
if not targetpath.startswith(dstdir):
raise RuntimeError("bad filename in zipfile %r" % (targetpath,))
# Create all upper directories if necessary.
if member.filename.endswith("/"):
upperdirs = targetpath
else:
upperdirs = os.path.dirname(targetpath)
if not os.path.isdir(upperdirs):
os.makedirs(upperdirs)
if not member.filename.endswith("/"):
open(targetpath, "wb").write(zipfile.read(member.filename))
开发者ID:hexmode,项目名称:mwlib,代码行数:28,代码来源:nuwiki.py
示例5: _get_app_zip
def _get_app_zip(self, abs_nb_path):
'''
Creates a zip file containing a dashboard application bundle.
:param abs_nb_path:
'''
md = self._create_app_bundle(abs_nb_path)
converter.add_cf_manifest(
md['bundle_dir'],
md['kernel_server'],
md['notebook_basename'],
md['tmpnb_mode']
)
converter.add_dockerfile(
md['bundle_dir'],
md['kernel_server'],
md['tmpnb_mode']
)
# Make the zip Archive
converter.to_zip(md['bundle_dir'], md['bundle_dir'])
self.set_header('Content-Disposition', 'attachment; filename={}.zip'.format(md['notebook_basename']))
self.set_header('Content-Type', 'application/zip')
with open(md['bundle_dir'] + '.zip', 'rb') as zipfile:
self.write(zipfile.read())
self.flush()
self.finish()
开发者ID:Lull3rSkat3r,项目名称:dashboards,代码行数:26,代码来源:bundle_handler.py
示例6: read_metadata
def read_metadata(zipfile):
"""Reads and returns metadata from a backup zipfile."""
for info in zipfile.infolist():
basename = os.path.basename(info.filename)
if basename == METADATA_FILENAME:
meta_file = zipfile.read(info.filename)
return kbjson.loads(meta_file)
return {}
开发者ID:Indemnity83,项目名称:kegbot-server,代码行数:8,代码来源:backup.py
示例7: getzflo
def getzflo(zipfile, member_path):
# GET a Zipfile File-Like Object for passing to
# an XML parser
try:
return zipfile.open(member_path) # CPython 2.6 onwards
except AttributeError:
# old way
return BYTES_IO(zipfile.read(member_path))
开发者ID:zakstein,项目名称:gourmet_hack,代码行数:8,代码来源:xlsx.py
示例8: ziptodict
def ziptodict(self,zipfile):
contentdict ={}
list = zipfile.namelist()
for name in list:
if not name[-1] == '/':
contentdict[name]=zipfile.read(name)
print name
return contentdict
开发者ID:guruganesh26,项目名称:carvajal-integ,代码行数:8,代码来源:ziputil.py
示例9: save_extracted_file
def save_extracted_file(self, zipfile, filename):
"Extract the file to a temp directory for viewing"
filebytes = zipfile.read(filename)
f = open("/tmp/" + filename, 'w')
try:
f.write(filebytes)
finally:
f.close()
开发者ID:sugarlabs,项目名称:myosa-examples,代码行数:8,代码来源:ReadEtextsTTS.py
示例10: get_zip_data
def get_zip_data( self, zipfile ):
#data = data.replace( b'\xb5', b'\xc2\xb5' )
#data = data.replace( b'\xe9', b'\xc3\xa9' )
data = zipfile.read( self.fileName )
data = data.decode( encoding='ISO-8859-1' )
#data = data.encode( 'UTF-8' ).decode( 'UTF-8' )
#print( data )
data = data.splitlines()
return data
开发者ID:VincentLoy,项目名称:django-usda-sr27,代码行数:9,代码来源:load_sr27.py
示例11: verify
def verify(self, zipfile=None):
"""Configure the VerifyingZipFile `zipfile` by verifying its signature
and setting expected hashes for every hash in RECORD.
Caller must complete the verification process by completely reading
every file in the archive (e.g. with extractall)."""
sig = None
if zipfile is None:
zipfile = self.zipfile
zipfile.strict = True
record_name = '/'.join((self.distinfo_name, 'RECORD'))
sig_name = '/'.join((self.distinfo_name, 'RECORD.jws'))
# tolerate s/mime signatures:
smime_sig_name = '/'.join((self.distinfo_name, 'RECORD.p7s'))
zipfile.set_expected_hash(record_name, None)
zipfile.set_expected_hash(sig_name, None)
zipfile.set_expected_hash(smime_sig_name, None)
record = zipfile.read(record_name)
record_digest = urlsafe_b64encode(hashlib.sha256(record).digest())
try:
sig = from_json(native(zipfile.read(sig_name)))
except KeyError: # no signature
pass
if sig:
headers, payload = signatures.verify(sig)
if payload['hash'] != "sha256=" + native(record_digest):
msg = "RECORD.jws claimed RECORD hash {} != computed hash {}."
raise BadWheelFile(msg.format(payload['hash'],
native(record_digest)))
reader = csv.reader((native(r, 'utf-8') for r in record.splitlines()))
for row in reader:
filename = row[0]
hash = row[1]
if not hash:
if filename not in (record_name, sig_name):
print("%s has no hash!" % filename, file=sys.stderr)
continue
algo, data = row[1].split('=', 1)
assert algo == "sha256", "Unsupported hash algorithm"
zipfile.set_expected_hash(filename, urlsafe_b64decode(binary(data)))
开发者ID:jsirois,项目名称:pex,代码行数:44,代码来源:install.py
示例12: load
def load(self, srcpath):
"""Reads the metadata from an ebook file.
"""
content_xml = self._load_metadata(srcpath)
if content_xml is not None:
book = self._load_ops_data(content_xml)
if self._configuration['import']['hash']:
with open(srcpath, 'rb') as zipfile:
book['_sha_hash'] = sha1(zipfile.read()).hexdigest()
return book
开发者ID:TomRegan,项目名称:roots,代码行数:10,代码来源:format.py
示例13: importzip
def importzip(conn,filename,zipfile):
print 'Import ' + filename
files = filelist(zipfile)
cur = conn.cursor()
meta = metadata(zipfile.read(files['OPERDAY']))
if datetime.strptime(meta['ValidThru'].replace('-',''),'%Y%m%d') < (datetime.now() - timedelta(days=1)):
return meta
header = (zipfile.read(files['DEST']).split('\n')[0].split('|')[1] in versionheaders)
encoding = encodingof(meta['DataOwnerCode'])
for table in importorder:
if table in files:
f = zipfile.open(files[table])
table = table+'_delta'
if header:
cur.copy_expert("COPY %s FROM STDIN WITH DELIMITER AS '|' NULL AS '' CSV HEADER ENCODING '%s'" % (table,encoding),f)
else:
cur.copy_expert("COPY %s FROM STDIN WITH DELIMITER AS '|' NULL AS '' CSV ENCODING '%s'" % (table,encoding),f)
conn.commit()
cur.close()
return meta
开发者ID:handloomweaver,项目名称:ndovextract,代码行数:20,代码来源:manager.py
示例14: save_extracted_file
def save_extracted_file(self, zipfile, filename):
"Extract the file to a temp directory for viewing"
filebytes = zipfile.read(filename)
outfn = self.make_new_filename(filename)
if (outfn == ''):
return False
f = open(os.path.join(self.get_activity_root(), 'tmp', outfn), 'w')
try:
f.write(filebytes)
finally:
f.close()
开发者ID:sugarlabs,项目名称:myosa-examples,代码行数:11,代码来源:ReadEtextsActivity2.py
示例15: importzip
def importzip(conn,zipfile):
files = filelist(zipfile)
cur = conn.cursor()
if 'OPERDAY' in files:
meta = metadata(zipfile.read(files['OPERDAY']))
elif 'PUJO' in files:
meta = metadata(zipfile.read(files['PUJO']))
else:
raise Exception('OPERDAY mist')
header = (zipfile.read(files['DEST']).split('\r\n')[0].split('|')[1] in versionheaders)
encoding = encodingof(meta['dataownercode'])
del(meta['dataownercode'])
for table in importorder:
if table in files:
f = zipfile.open(files[table])
if header:
cur.copy_expert("COPY %s FROM STDIN WITH DELIMITER AS '|' NULL AS '' CSV HEADER ENCODING '%s'" % (table,encoding),f)
else:
cur.copy_expert("COPY %s FROM STDIN WITH DELIMITER AS '|' NULL AS '' CSV ENCODING '%s'" % (table,encoding),f)
cur.close()
return meta
开发者ID:bliksemlabs,项目名称:bliksemintegration,代码行数:21,代码来源:kv1_805.py
示例16: download_data
def download_data(self, year, month):
syear = str(year)
smonth = str(month)
if month < 10:
smonth = "0"+str(month)
base_url = "http://pogoda.by/zip/"
citi_code = "34504"
url = base_url+syear+"/"+citi_code+"_"+syear+"-"+smonth+".zip"
zip_name = self.zip_name(year, month)
zipfile = urllib2.urlopen(url)
with open(zip_name, 'w') as f:
f.write(zipfile.read())
开发者ID:maxchv,项目名称:MeteoData,代码行数:13,代码来源:MeteoData.py
示例17: handle_docs
def handle_docs(email, files):
# Assume zipper always succeed
docfiles = list_files_by_extension(files, "docx")
print "List of document files", docfiles
zipper(ZipFileName, docfiles)
zipfile = open(ZipFileName, "rb")
zip = MIMEBase("application", "zip", name=ZipFileName)
zip.set_payload(zipfile.read())
zipfile.close()
encoders.encode_base64(zip)
email.attach(zip)
delete_files(docfiles)
开发者ID:jubic,项目名称:RP-Misc,代码行数:15,代码来源:solution.py
示例18: _unzip
def _unzip(zipfile, path):
"""
Python 2.5 doesn't have extractall()
"""
isdir = os.path.isdir
join = os.path.join
norm = os.path.normpath
split = os.path.split
for each in zipfile.namelist():
if not each.endswith('/'):
root, name = split(each)
directory = norm(join(path, root))
if not isdir(directory):
os.makedirs(directory)
file(join(directory, name), 'wb').write(zipfile.read(each))
开发者ID:potatolondon,项目名称:appengine_installer,代码行数:16,代码来源:appengine-installer.py
示例19: _get_ipynb_with_files
def _get_ipynb_with_files(self, abs_nb_path):
'''
Creates a zip file containing the ipynb and associated files.
:param abs_nb_path: absolute path to the notebook file
'''
notebook_basename = os.path.basename(abs_nb_path)
notebook_basename = os.path.splitext(notebook_basename)[0]
# pick a tmp directory for the "bundle"
bundle_id = generate_id()
bundle_dir = os.path.join(self.tmp_dir,
bundle_id,
notebook_basename
)
zipfile_path = os.path.join(self.tmp_dir,
bundle_id,
notebook_basename
)
# Try up to three times to make the bundle directory
for i in range(3):
try:
os.makedirs(bundle_dir)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
raise exc
else:
break
else:
raise RuntimeError('could not create bundle directory')
referenced_files = converter.get_referenced_files(abs_nb_path, 4)
# make the zip Archive, is there a more efficient way that copy+zip?
converter.copylist(os.path.dirname(abs_nb_path), bundle_dir, referenced_files)
shutil.copy2(abs_nb_path, os.path.join(bundle_dir, os.path.basename(abs_nb_path)))
shutil.make_archive(zipfile_path, 'zip', bundle_dir)
# send the archive
self.set_header('Content-Disposition', 'attachment; filename={}.zip'.format(notebook_basename))
self.set_header('Content-Type', 'application/zip')
with open(zipfile_path + '.zip', 'rb') as zipfile:
self.write(zipfile.read())
self.flush()
self.finish()
开发者ID:Lull3rSkat3r,项目名称:dashboards,代码行数:46,代码来源:bundle_handler.py
示例20: load
def load(c, zipfile, fn):
data=zipfile.read(fn).split('\r\n')
i=0
stats.setStatName(fn)
for line in data:
i=i+1
datum=parseDatum(line)
if isinstance(datum, TigerTypes.ParsedField):
stats.start()
c.execute(datum.toSql())
stats.click()
stats.stop()
# os.write(1, ".")
if i % 80 == 0:
print stats.getStats()
elif datum == None:
pass
else:
print "WARNING: " + type(datum).__name__ + " isn't a ParsedField"
print ''
开发者ID:WongTai,项目名称:snippets,代码行数:20,代码来源:loader.py
注:本文中的zipfile.read函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论