本文整理汇总了Python中mercurial.util.binary函数的典型用法代码示例。如果您正苦于以下问题:Python binary函数的具体用法?Python binary怎么用?Python binary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了binary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, base, a, b):
basetext = '\n'.join([i.strip('\n') for i in base] + [''])
atext = '\n'.join([i.strip('\n') for i in a] + [''])
btext = '\n'.join([i.strip('\n') for i in b] + [''])
if util.binary(basetext) or util.binary(atext) or util.binary(btext):
raise error.Abort("don't know how to merge binary files")
simplemerge.Merge3Text.__init__(self, basetext, atext, btext,
base, a, b)
示例2: overwrite
def overwrite(self, ctx, candidates, lookup, expand, rekw=False):
'''Overwrites selected files expanding/shrinking keywords.'''
if self.restrict or lookup or self.record: # exclude kw_copy
candidates = self.iskwfile(candidates, ctx)
if not candidates:
return
kwcmd = self.restrict and lookup # kwexpand/kwshrink
if self.restrict or expand and lookup:
mf = ctx.manifest()
lctx = ctx
re_kw = (self.restrict or rekw) and self.rekw or self.rekwexp
msg = (expand and _('overwriting %s expanding keywords\n')
or _('overwriting %s shrinking keywords\n'))
for f in candidates:
if self.restrict:
data = self.repo.file(f).read(mf[f])
else:
data = self.repo.wread(f)
if util.binary(data):
continue
if expand:
if lookup:
lctx = self.linkctx(f, mf[f])
data, found = self.substitute(data, f, lctx, re_kw.subn)
elif self.restrict:
found = re_kw.search(data)
else:
data, found = _shrinktext(data, re_kw.subn)
if found:
self.ui.note(msg % f)
self.repo.wwrite(f, data, ctx.flags(f))
if kwcmd:
self.repo.dirstate.normal(f)
elif self.record:
self.repo.dirstate.normallookup(f)
示例3: rawfile
def rawfile(web, req, tmpl):
guessmime = web.configbool('web', 'guessmime', False)
path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
if not path:
content = manifest(web, req, tmpl)
req.respond(HTTP_OK, web.ctype)
return content
try:
fctx = webutil.filectx(web.repo, req)
except error.LookupError as inst:
try:
content = manifest(web, req, tmpl)
req.respond(HTTP_OK, web.ctype)
return content
except ErrorResponse:
raise inst
path = fctx.path()
text = fctx.data()
mt = 'application/binary'
if guessmime:
mt = mimetypes.guess_type(path)[0]
if mt is None:
if util.binary(text):
mt = 'application/binary'
else:
mt = 'text/plain'
if mt.startswith('text/'):
mt += '; charset="%s"' % encoding.encoding
req.respond(HTTP_OK, mt, path, body=text)
return []
示例4: tolf
def tolf(s, params, ui, **kwargs):
"""Filter to convert to LF EOLs."""
if util.binary(s):
return s
if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s):
return s
return eolre.sub('\n', s)
示例5: overwrite
def overwrite(self, node=None, expand=True, files=None):
'''Overwrites selected files expanding/shrinking keywords.'''
ctx = self.repo.changectx(node)
mf = ctx.manifest()
if node is not None: # commit
files = [f for f in ctx.files() if f in mf]
notify = self.ui.debug
else: # kwexpand/kwshrink
notify = self.ui.note
candidates = [f for f in files if self.iskwfile(f, mf.linkf)]
if candidates:
self.restrict = True # do not expand when reading
candidates.sort()
action = expand and 'expanding' or 'shrinking'
for f in candidates:
fp = self.repo.file(f)
data = fp.read(mf[f])
if util.binary(data):
continue
if expand:
changenode = node or self.getnode(f, mf[f])
data, found = self.substitute(data, f, changenode,
self.re_kw.subn)
else:
found = self.re_kw.search(data)
if found:
notify(_('overwriting %s %s keywords\n') % (f, action))
self.repo.wwrite(f, data, mf.flags(f))
self.repo.dirstate.normal(f)
self.restrict = False
示例6: shrinklines
def shrinklines(self, fname, lines):
'''Returns lines with keyword substitutions removed.'''
if self.match(fname):
text = ''.join(lines)
if not util.binary(text):
return _shrinktext(text, self.rekwexp.sub).splitlines(True)
return lines
示例7: pygmentize
def pygmentize(self, tmpl, fctx, field):
# append a <link ...> to the syntax highlighting css
old_header = ''.join(tmpl('header'))
if SYNTAX_CSS not in old_header:
new_header = old_header + SYNTAX_CSS
tmpl.cache['header'] = new_header
text = fctx.data()
if util.binary(text):
return
style = self.config("web", "pygments_style", "colorful")
# To get multi-line strings right, we can't format line-by-line
try:
lexer = guess_lexer_for_filename(fctx.path(), text,
encoding=util._encoding)
except (ClassNotFound, ValueError):
try:
lexer = guess_lexer(text, encoding=util._encoding)
except (ClassNotFound, ValueError):
lexer = TextLexer(encoding=util._encoding)
formatter = HtmlFormatter(style=style, encoding=util._encoding)
colorized = highlight(text, lexer, formatter)
# strip wrapping div
colorized = colorized[:colorized.find('\n</pre>')]
colorized = colorized[colorized.find('<pre>')+5:]
coloriter = iter(colorized.splitlines())
filters['colorize'] = lambda x: coloriter.next()
oldl = tmpl.cache[field]
newl = oldl.replace('line|escape', 'line|colorize')
tmpl.cache[field] = newl
示例8: filelines
def filelines(f):
if binary(f.data()):
mt = mimetypes.guess_type(f.path())[0]
if not mt:
mt = 'application/octet-stream'
return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))]
return f.data().splitlines()
示例9: annotate
def annotate(**map):
last = None
if binary(fctx.data()):
mt = (mimetypes.guess_type(fctx.path())[0]
or 'application/octet-stream')
lines = enumerate([((fctx.filectx(fctx.filerev()), 1),
'(binary:%s)' % mt)])
else:
lines = enumerate(fctx.annotate(follow=True, linenumber=True))
for lineno, ((f, targetline), l) in lines:
fnode = f.filenode()
if last != fnode:
last = fnode
yield {"parity": parity.next(),
"node": hex(f.node()),
"rev": f.rev(),
"author": f.user(),
"desc": f.description(),
"file": f.path(),
"targetline": targetline,
"line": l,
"lineid": "l%d" % (lineno + 1),
"linenumber": "% 6d" % (lineno + 1)}
示例10: overwrite
def overwrite(self, node, expand, files):
'''Overwrites selected files expanding/shrinking keywords.'''
ctx = self.repo[node]
mf = ctx.manifest()
if node is not None: # commit
files = [f for f in ctx.files() if f in mf]
notify = self.ui.debug
else: # kwexpand/kwshrink
notify = self.ui.note
candidates = [f for f in files if self.iskwfile(f, ctx.flags)]
if candidates:
self.restrict = True # do not expand when reading
msg = (expand and _('overwriting %s expanding keywords\n')
or _('overwriting %s shrinking keywords\n'))
for f in candidates:
fp = self.repo.file(f)
data = fp.read(mf[f])
if util.binary(data):
continue
if expand:
if node is None:
ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
data, found = self.substitute(data, f, ctx,
self.re_kw.subn)
else:
found = self.re_kw.search(data)
if found:
notify(msg % f)
self.repo.wwrite(f, data, mf.flags(f))
if node is None:
self.repo.dirstate.normal(f)
self.restrict = False
示例11: _filerevision
def _filerevision(web, tmpl, fctx):
f = fctx.path()
text = fctx.data()
parity = paritygen(web.stripecount)
if binary(text):
mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
text = '(binary:%s)' % mt
def lines():
for lineno, t in enumerate(text.splitlines(True)):
yield {"line": t,
"lineid": "l%d" % (lineno + 1),
"linenumber": "% 6d" % (lineno + 1),
"parity": parity.next()}
return tmpl("filerevision",
file=f,
path=webutil.up(f),
text=lines(),
rev=fctx.rev(),
node=hex(fctx.node()),
author=fctx.user(),
date=fctx.date(),
desc=fctx.description(),
branch=webutil.nodebranchnodefault(fctx),
parent=webutil.parents(fctx),
child=webutil.children(fctx),
rename=webutil.renamelink(fctx),
permissions=fctx.manifest().flags(f))
示例12: tocrlf
def tocrlf(s, params, ui, **kwargs):
"""Filter to convert to CRLF EOLs."""
if util.binary(s):
return s
if ui.configbool("eol", "only-consistent", True) and inconsistenteol(s):
return s
if ui.configbool("eol", "fix-trailing-newline", False) and s and s[-1] != "\n":
s = s + "\n"
return eolre.sub("\r\n", s)
示例13: pygmentize
def pygmentize(field, fctx, style, tmpl, guessfilenameonly=False):
# append a <link ...> to the syntax highlighting css
old_header = tmpl.load('header')
if SYNTAX_CSS not in old_header:
new_header = old_header + SYNTAX_CSS
tmpl.cache['header'] = new_header
text = fctx.data()
if util.binary(text):
return
# str.splitlines() != unicode.splitlines() because "reasons"
for c in "\x0c\x1c\x1d\x1e":
if c in text:
text = text.replace(c, '')
# Pygments is best used with Unicode strings:
# <http://pygments.org/docs/unicode/>
text = text.decode(encoding.encoding, 'replace')
# To get multi-line strings right, we can't format line-by-line
try:
lexer = guess_lexer_for_filename(fctx.path(), text[:1024],
stripnl=False)
except (ClassNotFound, ValueError):
# guess_lexer will return a lexer if *any* lexer matches. There is
# no way to specify a minimum match score. This can give a high rate of
# false positives on files with an unknown filename pattern.
if guessfilenameonly:
return
try:
lexer = guess_lexer(text[:1024], stripnl=False)
except (ClassNotFound, ValueError):
# Don't highlight unknown files
return
# Don't highlight text files
if isinstance(lexer, TextLexer):
return
formatter = HtmlFormatter(nowrap=True, style=style)
colorized = highlight(text, lexer, formatter)
coloriter = (s.encode(encoding.encoding, 'replace')
for s in colorized.splitlines())
tmpl.filters['colorize'] = lambda x: coloriter.next()
oldl = tmpl.cache[field]
newl = oldl.replace('line|escape', 'line|colorize')
tmpl.cache[field] = newl
示例14: write
def write(path):
fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
pathname=os.path.join(prefix, path))
data = ctx[path].data()
if not opts.get('text') and util.binary(data):
fp.write("%s: binary file\n" % path)
return
for (num, line) in enumerate(data.split("\n"), start=1):
line = line + "\n"
fp.write("%s:%s: %s" % (path, num, line))
fp.close()
示例15: overwrite
def overwrite(self, ctx, candidates, lookup, expand, rekw=False):
'''Overwrites selected files expanding/shrinking keywords.'''
if self.restrict or lookup or self.postcommit: # exclude kw_copy
candidates = self.iskwfile(candidates, ctx)
if not candidates:
return
kwcmd = self.restrict and lookup # kwexpand/kwshrink
if self.restrict or expand and lookup:
mf = ctx.manifest()
if self.restrict or rekw:
re_kw = self.rekw
else:
re_kw = self.rekwexp
if expand:
msg = _('overwriting %s expanding keywords\n')
else:
msg = _('overwriting %s shrinking keywords\n')
for f in candidates:
if self.restrict:
data = self.repo.file(f).read(mf[f])
else:
data = self.repo.wread(f)
if util.binary(data):
continue
if expand:
parents = ctx.parents()
if lookup:
ctx = self.linkctx(f, mf[f])
elif self.restrict and len(parents) > 1:
# merge commit
# in case of conflict f is in modified state during
# merge, even if f does not differ from f in parent
for p in parents:
if f in p and not p[f].cmp(ctx[f]):
ctx = p[f].changectx()
break
data, found = self.substitute(data, f, ctx, re_kw.subn)
elif self.restrict:
found = re_kw.search(data)
else:
data, found = _shrinktext(data, re_kw.subn)
if found:
self.ui.note(msg % f)
fp = self.repo.wvfs(f, "wb", atomictemp=True)
fp.write(data)
fp.close()
if kwcmd:
self.repo.dirstate.normal(f)
elif self.postcommit:
self.repo.dirstate.normallookup(f)