本文整理汇总了Python中util.filechunkiter函数的典型用法代码示例。如果您正苦于以下问题:Python filechunkiter函数的具体用法?Python filechunkiter怎么用?Python filechunkiter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filechunkiter函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: streamer
def streamer(repo, entries, total):
'''stream out all metadata files in repository.'''
yield '0\n' # success
repo.ui.debug('%d files, %d bytes to transfer\n' %
(len(entries), total_bytes))
yield '%d %d\n' % (len(entries), total_bytes)
sopener = repo.sopener
oldaudit = sopener.mustaudit
debugflag = repo.ui.debugflag
sopener.mustaudit = False
try:
for name, size in entries:
if debugflag:
repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
# partially encode name over the wire for backwards compat
yield '%s\0%d\n' % (store.encodedir(name), size)
if size <= 65536:
fp = sopener(name)
try:
data = fp.read(size)
finally:
fp.close()
yield data
else:
for chunk in util.filechunkiter(sopener(name), limit=size):
yield chunk
# replace with "finally:" when support for python 2.4 has been dropped
except Exception:
sopener.mustaudit = oldaudit
raise
sopener.mustaudit = oldaudit
示例2: stream_out
def stream_out(repo, untrusted=False):
'''stream out all metadata files in repository.
writes to file-like object, must support write() and optional flush().'''
if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
raise StreamException(1)
entries = []
total_bytes = 0
try:
# get consistent snapshot of repo, lock during scan
lock = repo.lock()
try:
repo.ui.debug(_('scanning\n'))
for name, ename, size in repo.store.walk():
# for backwards compat, name was partially encoded
entries.append((store.encodedir(name), size))
total_bytes += size
finally:
lock.release()
except error.LockError:
raise StreamException(2)
yield '0\n'
repo.ui.debug(_('%d files, %d bytes to transfer\n') %
(len(entries), total_bytes))
yield '%d %d\n' % (len(entries), total_bytes)
for name, size in entries:
repo.ui.debug(_('sending %s (%d bytes)\n') % (name, size))
yield '%s\0%d\n' % (name, size)
for chunk in util.filechunkiter(repo.sopener(name), limit=size):
yield chunk
示例3: zgenerator
def zgenerator(f):
zd = zlib.decompressobj()
try:
for chunk in util.filechunkiter(f):
yield zd.decompress(chunk)
except httplib.HTTPException, inst:
raise IOError(None, _('connection ended unexpectedly'))
示例4: _sendfile
def _sendfile(self, data):
# send a file
if isinstance(data, httpsendfile):
# if auth required, some data sent twice, so rewind here
data.seek(0)
for chunk in util.filechunkiter(data):
connection.send(self, chunk)
else:
connection.send(self, data)
示例5: zgenerator
def zgenerator(f):
zd = zlib.decompressobj()
try:
for chunk in util.filechunkiter(f):
while chunk:
yield zd.decompress(chunk, 2**18)
chunk = zd.unconsumed_tail
except httplib.HTTPException:
raise IOError(None, _('connection ended unexpectedly'))
yield zd.flush()
示例6: __init__
def __init__(self, ui, path, bundlename):
self._tempparent = None
try:
localrepo.localrepository.__init__(self, ui, path)
except error.RepoError:
self._tempparent = tempfile.mkdtemp()
localrepo.instance(ui, self._tempparent, 1)
localrepo.localrepository.__init__(self, ui, self._tempparent)
if path:
self._url = 'bundle:' + path + '+' + bundlename
else:
self._url = 'bundle:' + bundlename
self.tempfile = None
self.bundlefile = open(bundlename, "rb")
header = self.bundlefile.read(6)
if not header.startswith("HG"):
raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename)
elif not header.startswith("HG10"):
raise util.Abort(_("%s: unknown bundle version") % bundlename)
elif (header == "HG10BZ") or (header == "HG10GZ"):
fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-",
suffix=".hg10un", dir=self.path)
self.tempfile = temp
fptemp = os.fdopen(fdtemp, 'wb')
def generator(f):
if header == "HG10BZ":
zd = bz2.BZ2Decompressor()
zd.decompress("BZ")
elif header == "HG10GZ":
zd = zlib.decompressobj()
for chunk in f:
yield zd.decompress(chunk)
gen = generator(util.filechunkiter(self.bundlefile, 4096))
try:
fptemp.write("HG10UN")
for chunk in gen:
fptemp.write(chunk)
finally:
fptemp.close()
self.bundlefile.close()
self.bundlefile = open(self.tempfile, "rb")
# seek right after the header
self.bundlefile.seek(6)
elif header == "HG10UN":
# nothing to do
pass
else:
raise util.Abort(_("%s: unknown bundle compression type")
% bundlename)
# dict with the mapping 'filename' -> position in the bundle
self.bundlefilespos = {}
示例7: streamer
def streamer(repo, entries, total):
"""stream out all metadata files in repository."""
yield "0\n" # success
repo.ui.debug("%d files, %d bytes to transfer\n" % (len(entries), total_bytes))
yield "%d %d\n" % (len(entries), total_bytes)
for name, size in entries:
repo.ui.debug("sending %s (%d bytes)\n" % (name, size))
# partially encode name over the wire for backwards compat
yield "%s\0%d\n" % (store.encodedir(name), size)
for chunk in util.filechunkiter(repo.sopener(name), limit=size):
yield chunk
示例8: generator
def generator(f):
zd = bz2.BZ2Decompressor()
zd.decompress("BZ")
for chunk in util.filechunkiter(f, 4096):
yield zd.decompress(chunk)
示例9: generator
def generator(f):
zd = zlib.decompressobj()
for chunk in util.filechunkiter(f):
yield zd.decompress(chunk)
示例10: except
repolock = None
try:
try:
repolock = repo.lock()
except (lock.LockHeld, lock.LockUnavailable), inst:
repo.ui.warn('locking the repository failed: %s\n' % (inst,))
fileobj.write('2\n')
return
fileobj.write('0\n')
repo.ui.debug('scanning\n')
entries = []
total_bytes = 0
for name, size in walkrepo(repo.spath):
name = repo.decodefn(util.pconvert(name))
entries.append((name, size))
total_bytes += size
finally:
del repolock
repo.ui.debug('%d files, %d bytes to transfer\n' %
(len(entries), total_bytes))
fileobj.write('%d %d\n' % (len(entries), total_bytes))
for name, size in entries:
repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
fileobj.write('%s\0%d\n' % (name, size))
for chunk in util.filechunkiter(repo.sopener(name), limit=size):
fileobj.write(chunk)
flush = getattr(fileobj, 'flush', None)
if flush: flush()