• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.binary函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mercurial.util.binary函数的典型用法代码示例。如果您正苦于以下问题:Python binary函数的具体用法?Python binary怎么用?Python binary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了binary函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:CSCI-362-02-2015,项目名称:RedTeam,代码行数:8,代码来源:test-simplemerge.py


示例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)
开发者ID:rybesh,项目名称:mysite-lib,代码行数:35,代码来源:keyword.py


示例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 []
开发者ID:CSCI-362-02-2015,项目名称:RedTeam,代码行数:34,代码来源:webcommands.py


示例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)
开发者ID:helloandre,项目名称:cr48,代码行数:7,代码来源:eol.py


示例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
开发者ID:c0ns0le,项目名称:cygwin,代码行数:30,代码来源:keyword.py


示例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
开发者ID:leetaizhu,项目名称:Odoo_ENV_MAC_OS,代码行数:7,代码来源:keyword.py


示例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
开发者ID:carlgao,项目名称:lenga,代码行数:35,代码来源:highlight.py


示例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()
开发者ID:codeskyblue,项目名称:gobuild-1,代码行数:7,代码来源:webcommands.py


示例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)}
开发者ID:Nurb432,项目名称:plan9front,代码行数:25,代码来源:webcommands.py


示例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
开发者ID:iluxa-c0m,项目名称:mercurial-crew-tonfa,代码行数:32,代码来源:keyword.py


示例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))
开发者ID:Nurb432,项目名称:plan9front,代码行数:30,代码来源:webcommands.py


示例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)
开发者ID:areshero,项目名称:ThirdWorldApp,代码行数:9,代码来源:eol.py


示例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
开发者ID:Distrotech,项目名称:mercurial,代码行数:53,代码来源:highlight.py


示例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()
开发者ID:davidshepherd7,项目名称:dotfiles,代码行数:12,代码来源:catnotate.py


示例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)
开发者ID:motlin,项目名称:cyg,代码行数:50,代码来源:keyword.py


示例16: commitctx

 def commitctx(self, ctx, error=False):
     for f in sorted(ctx.added() + ctx.modified()):
         if not self._eolfile(f):
             continue
         data = ctx[f].data()
         if util.binary(data):
             # We should not abort here, since the user should
             # be able to say "** = native" to automatically
             # have all non-binary files taken care of.
             continue
         if inconsistenteol(data):
             raise util.Abort(_("inconsistent newline style "
                                "in %s\n" % f))
     return super(eolrepo, self).commitctx(ctx, error)
开发者ID:helloandre,项目名称:cr48,代码行数:14,代码来源:eol.py


示例17: forbidnewline

def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
    halt = False
    seen = set()
    # we try to walk changesets in reverse order from newest to
    # oldest, so that if we see a file multiple times, we take the
    # newest version as canonical. this prevents us from blocking a
    # changegroup that contains an unacceptable commit followed later
    # by a commit that fixes the problem.
    tip = repo["tip"]
    for rev in xrange(len(repo) - 1, repo[node].rev() - 1, -1):
        c = repo[rev]
        for f in c.files():
            if f in seen or f not in tip or f not in c:
                continue
            seen.add(f)
            data = c[f].data()
            if not util.binary(data) and newline in data:
                if not halt:
                    ui.warn(
                        _("Attempt to commit or push text file(s) " "using %s line endings\n") % newlinestr[newline]
                    )
                ui.warn(_("in %s: %s\n") % (short(c.node()), f))
                halt = True
    if halt and hooktype == "pretxnchangegroup":
        crlf = newlinestr[newline].lower()
        filter = filterstr[newline]
        ui.warn(
            _(
                "\nTo prevent this mistake in your local repository,\n"
                "add to Mercurial.ini or .hg/hgrc:\n"
                "\n"
                "[hooks]\n"
                "pretxncommit.%s = python:hgext.win32text.forbid%s\n"
                "\n"
                "and also consider adding:\n"
                "\n"
                "[extensions]\n"
                "hgext.win32text =\n"
                "[encode]\n"
                "** = %sencode:\n"
                "[decode]\n"
                "** = %sdecode:\n"
            )
            % (crlf, crlf, filter, filter)
        )
    return halt
开发者ID:fuzxxl,项目名称:plan9front,代码行数:46,代码来源:win32text.py


示例18: pygmentize

def pygmentize(field, fctx, style, tmpl):

    # 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):
        try:
            lexer = guess_lexer(text[:1024], stripnl=False)
        except (ClassNotFound, ValueError):
            lexer = TextLexer(stripnl=False)

    formatter = HtmlFormatter(style=style)

    colorized = highlight(text, lexer, formatter)
    # strip wrapping div
    colorized = colorized[:colorized.find('\n</pre>')]
    colorized = colorized[colorized.find('<pre>') + 5:]
    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
开发者ID:RayFerr000,项目名称:PLTL,代码行数:45,代码来源:highlight.py


示例19: 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:
             if lookup:
                 ctx = self.linkctx(f, mf[f])
             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.wopener(f, "wb", atomictemp=True)
             fp.write(data)
             fp.close()
             if kwcmd:
                 self.repo.dirstate.normal(f)
             elif self.postcommit:
                 self.repo.dirstate.normallookup(f)
开发者ID:leetaizhu,项目名称:Odoo_ENV_MAC_OS,代码行数:41,代码来源:keyword.py


示例20: diffwith

 def diffwith(self, targetctx, match=None, showchanges=False):
     """diff and prepare fixups. update self.fixupmap, self.paths"""
     # only care about modified files
     self.status = self.stack[-1].status(targetctx, match)
     self.paths = []
     # but if --edit-lines is used, the user may want to edit files
     # even if they are not modified
     editopt = self.opts.get('edit_lines')
     if not self.status.modified and editopt and match:
         interestingpaths = match.files()
     else:
         interestingpaths = self.status.modified
     # prepare the filefixupstate
     seenfctxs = set()
     # sorting is necessary to eliminate ambiguity for the "double move"
     # case: "hg cp A B; hg cp A C; hg rm A", then only "B" can affect "A".
     for path in sorted(interestingpaths):
         if self.ui.debugflag:
             self.ui.write(_('calculating fixups for %s\n') % path)
         targetfctx = targetctx[path]
         fctxs, ctx2fctx = getfilestack(self.stack, path, seenfctxs)
         # ignore symbolic links or binary, or unchanged files
         if any(f.islink() or util.binary(f.data())
                for f in [targetfctx] + fctxs
                if not isinstance(f, emptyfilecontext)):
             continue
         if targetfctx.data() == fctxs[-1].data() and not editopt:
             continue
         seenfctxs.update(fctxs[1:])
         self.fctxmap[path] = ctx2fctx
         fstate = filefixupstate(fctxs, ui=self.ui, opts=self.opts)
         if showchanges:
             colorpath = self.ui.label(path, 'absorb.path')
             header = 'showing changes for ' + colorpath
             self.ui.write(header + '\n')
         fstate.diffwith(targetfctx, showchanges=showchanges)
         self.fixupmap[path] = fstate
         self.paths.append(path)
开发者ID:davidshepherd7,项目名称:dotfiles,代码行数:38,代码来源:__init__.py



注:本文中的mercurial.util.binary函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.copyfile函数代码示例发布时间:2022-05-27
下一篇:
Python util.atomictempfile函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap