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

Python util.sha1函数代码示例

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

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



在下文中一共展示了sha1函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _bundle

def _bundle(repo, bases, heads, node, suffix, compress=True):
    """create a bundle with the specified revisions as a backup"""
    usebundle2 = (repo.ui.config('experimental', 'bundle2-exp', True) and
                  repo.ui.config('experimental', 'strip-bundle2-version'))
    if usebundle2:
        cgversion = repo.ui.config('experimental', 'strip-bundle2-version')
        if cgversion not in changegroup.packermap:
            repo.ui.warn(_('unknown strip-bundle2-version value %r; '
                            'should be one of %r\n') %
                         (cgversion, sorted(changegroup.packermap.keys()),))
            cgversion = '01'
            usebundle2 = False
    else:
        cgversion = '01'

    cg = changegroup.changegroupsubset(repo, bases, heads, 'strip',
                                       version=cgversion)
    backupdir = "strip-backup"
    vfs = repo.vfs
    if not vfs.isdir(backupdir):
        vfs.mkdir(backupdir)

    # Include a hash of all the nodes in the filename for uniqueness
    allcommits = repo.set('%ln::%ln', bases, heads)
    allhashes = sorted(c.hex() for c in allcommits)
    totalhash = util.sha1(''.join(allhashes)).hexdigest()
    name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix)

    if usebundle2:
        bundletype = "HG20"
    elif compress:
        bundletype = "HG10BZ"
    else:
        bundletype = "HG10UN"
    return changegroup.writebundle(repo.ui, cg, name, bundletype, vfs)
开发者ID:pierfort123,项目名称:mercurial,代码行数:35,代码来源:repair.py


示例2: hexsha1

def hexsha1(data):
    """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like
    object data"""
    h = util.sha1()
    for chunk in util.filechunkiter(data):
        h.update(chunk)
    return h.hexdigest()
开发者ID:ZanderZhang,项目名称:Andriod-Learning,代码行数:7,代码来源:lfutil.py


示例3: debuggethostfingerprint

def debuggethostfingerprint(ui, repo, source='default'):
    """retrieve a fingerprint of the server certificate

    The server certificate is not verified.
    """
    source = ui.expandpath(source)
    u = util.url(source)
    scheme = (u.scheme or '').split('+')[-1]
    host = u.host
    port = util.getport(u.port or scheme or '-1')
    if scheme != 'https' or not host or not (0 <= port <= 65535):
        raise util.Abort(_('unsupported URL: %s') % source)

    sock = socket.socket()
    try:
        sock.connect((host, port))
        sock = sslutil.wrapsocket(sock, None, None, ui, serverhostname=host)
        peercert = sock.getpeercert(True)
        if not peercert:
            raise util.Abort(_('%s certificate error: no certificate received')
                             % host)
    finally:
        sock.close()

    s = util.sha1(peercert).hexdigest()
    ui.write(':'.join([s[x:x + 2] for x in xrange(0, len(s), 2)]), '\n')
开发者ID:seewindcn,项目名称:tortoisehg,代码行数:26,代码来源:hgcommands.py


示例4: buildtemprevlog

def buildtemprevlog(repo, file):
    # get filename key
    filekey = util.sha1(file).hexdigest()
    filedir = os.path.join(repo.path, 'store/data', filekey)

    # sort all entries based on linkrev
    fctxs = []
    for filenode in os.listdir(filedir):
        fctxs.append(repo.filectx(file, fileid=bin(filenode)))

    fctxs = sorted(fctxs, key=lambda x: x.linkrev())

    # add to revlog
    temppath = repo.sjoin('data/temprevlog.i')
    if os.path.exists(temppath):
        os.remove(temppath)
    r = filelog.filelog(repo.sopener, 'temprevlog')

    class faket(object):
        def add(self, a,b,c):
            pass
    t = faket()
    for fctx in fctxs:
        if fctx.node() not in repo:
            continue

        p = fctx.filelog().parents(fctx.filenode())
        meta = {}
        if fctx.renamed():
            meta['copy'] = fctx.renamed()[0]
            meta['copyrev'] = hex(fctx.renamed()[1])

        r.add(fctx.data(), meta, t, fctx.linkrev(), p[0], p[1])

    return r
开发者ID:pycontribs,项目名称:remotefilelog,代码行数:35,代码来源:debugcommands.py


示例5: _obsrelsethashtree

def _obsrelsethashtree(repo, encodeonemarker):
    cache = []
    unfi = repo.unfiltered()
    markercache = {}
    for i in unfi:
        ctx = unfi[i]
        entry = 0
        sha = util.sha1()
        # add data from p1
        for p in ctx.parents():
            p = p.rev()
            if p < 0:
                p = node.nullid
            else:
                p = cache[p][1]
            if p != node.nullid:
                entry += 1
                sha.update(p)
        tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
        if tmarkers:
            bmarkers = []
            for m in tmarkers:
                if not m in markercache:
                    markercache[m] = encodeonemarker(m)
                bmarkers.append(markercache[m])
            bmarkers.sort()
            for m in bmarkers:
                entry += 1
                sha.update(m)
        if entry:
            cache.append((ctx.node(), sha.digest()))
        else:
            cache.append((ctx.node(), node.nullid))
    return cache
开发者ID:dan-passaro,项目名称:hgrc,代码行数:34,代码来源:simple4server.py


示例6: __init__

    def __init__(self, alias, url):
        if hg.islocal(url.encode('utf-8')):
            url = p(url).abspath()
            # Force git to use an absolute path in the future
            cmd = ['git', 'config', 'remote.%s.url' % alias, "gitifyhg::%s" % url]
            subprocess.call(cmd)

        # use hash of URL as unique identifier in various places.
        # this has the advantage over 'alias' that it stays constant
        # when the user does a "git remote rename old new".
        self.uuid = sha1(url.encode('utf-8')).hexdigest()

        gitdir = p(os.environ['GIT_DIR'].decode('utf-8'))
        self.remotedir = gitdir.joinpath('hg', self.uuid)
        self.marks_git_path = self.remotedir.joinpath('marks-git')
        self.marks = HGMarks(self.remotedir.joinpath('marks-hg'))
        self.parsed_refs = {}
        self.blob_marks = {}
        self.branches = {}
        self.bookmarks = {}

        self.prefix = 'refs/hg/%s' % alias
        self.alias = alias
        self.url = url
        self.build_repo(url)
开发者ID:jedbrown,项目名称:gitifyhg,代码行数:25,代码来源:gitifyhg.py


示例7: __init__

    def __init__(self, alias, url):
        if hg.islocal(url.encode("utf-8")):
            url = p(url).abspath()
            # Force git to use an absolute path in the future
            remote_name = os.path.basename(sys.argv[0]).replace("git-remote-", "")
            cmd = ["git", "config", "remote.%s.url" % alias, "%s::%s" % (remote_name, url)]
            subprocess.call(cmd)

        # use hash of URL as unique identifier in various places.
        # this has the advantage over 'alias' that it stays constant
        # when the user does a "git remote rename old new".
        if hg_version() >= "4.0.1":
            d = digester(["md5", "sha1"])
            d.update(url.encode("utf-8"))
            self.uuid = d["sha1"]
        else:
            self.uuid = sha1(url.encode("utf-8")).hexdigest()

        gitdir = p(os.environ["GIT_DIR"].decode("utf-8"))
        self.remotedir = gitdir.joinpath("hg", self.uuid)
        self.marks_git_path = self.remotedir.joinpath("marks-git")
        self.marks_hg_path = self.remotedir.joinpath("marks-hg")
        self.marks = HGMarks(self.marks_hg_path)
        self.git_marks = GitMarks(self.marks_git_path)
        self.parsed_refs = {}
        self.blob_marks = {}
        self.branches = {}
        self.bookmarks = {}

        self.prefix = "refs/hg/%s" % alias
        self.alias = alias
        self.url = url
        self.build_repo(url)
开发者ID:buchuki,项目名称:gitifyhg,代码行数:33,代码来源:gitifyhg.py


示例8: filesha

def filesha(repo, file):
    '''returns a sha1 of file contents'''
    f = util.pathto(repo.root, None, file)
    if os.path.exists(f):
        contents = open(f).read()
    else:
        contents = '';
    return util.sha1(contents).hexdigest()
开发者ID:Evanlec,项目名称:config,代码行数:8,代码来源:tasks.py


示例9: copyandhash

def copyandhash(instream, outfile):
    '''Read bytes from instream (iterable) and write them to outfile,
    computing the SHA-1 hash of the data along the way. Return the hash.'''
    hasher = util.sha1('')
    for data in instream:
        hasher.update(data)
        outfile.write(data)
    return hasher.hexdigest()
开发者ID:ZanderZhang,项目名称:Andriod-Learning,代码行数:8,代码来源:lfutil.py


示例10: storeuntracked

def storeuntracked(repo, untracked):
    if not untracked:
        return
    os.mkdir(repo.join('tasks/untrackedbackup'))
    for f in untracked:
        shaname = util.sha1(f).hexdigest()
        util.copyfile(util.pathto(repo.root, None, f),
            repo.join('tasks/untrackedbackup/%s' % shaname))
        util.unlink(util.pathto(repo.root, None, f))
开发者ID:Evanlec,项目名称:config,代码行数:9,代码来源:tasks.py


示例11: hg_sha1

def hg_sha1(url):
    encoded = url.encode('utf-8')

    if hg_version() >= '3.2':
        d = digester(['md5', 'sha1'])
        d.update(encoded)
        return d['sha1']
    else:
        return sha1(encoded).hexdigest()
开发者ID:buchuki,项目名称:gitifyhg,代码行数:9,代码来源:apiwrapper.py


示例12: hashfile

def hashfile(file):
    if not os.path.exists(file):
        return ''
    hasher = util.sha1('')
    fd = open(file, 'rb')
    for data in util.filechunkiter(fd, 128 * 1024):
        hasher.update(data)
    fd.close()
    return hasher.hexdigest()
开发者ID:ZanderZhang,项目名称:Andriod-Learning,代码行数:9,代码来源:lfutil.py


示例13: hashfile

def hashfile(file):
    if not os.path.exists(file):
        return ''
    hasher = util.sha1('')
    fd = open(file, 'rb')
    for data in blockstream(fd):
        hasher.update(data)
    fd.close()
    return hasher.hexdigest()
开发者ID:sandeepprasanna,项目名称:ODOO,代码行数:9,代码来源:lfutil.py


示例14: __init__

    def __init__(self, patchpath, repo, pf=None, rev=None):
        """ Read patch context from file
        :param pf: currently ignored
            The provided handle is used to read the patch and
            the patchpath contains the name of the patch.
            The handle is NOT closed.
        """
        self._path = patchpath
        self._patchname = os.path.basename(patchpath)
        self._repo = repo
        self._rev = rev or 'patch'
        self._status = [[], [], []]
        self._fileorder = []
        self._user = ''
        self._desc = ''
        self._branch = ''
        self._node = node.nullid
        self._identity = node.nullid
        self._mtime = None
        self._fsize = 0
        self._parseerror = None
        self._phase = 'draft'

        try:
            self._mtime = os.path.getmtime(patchpath)
            self._fsize = os.path.getsize(patchpath)
            ph = mq.patchheader(self._path)
            self._ph = ph
            hash = util.sha1(self._path)
            hash.update(str(self._mtime))
            self._identity = hash.digest()
        except EnvironmentError:
            self._date = util.makedate()
            return

        try:
            self._branch = ph.branch or ''
            self._node = binascii.unhexlify(ph.nodeid)
            if self._repo.ui.configbool('mq', 'secret'):
                self._phase = 'secret'
        except TypeError:
            pass
        except AttributeError:
            # hacks to try to deal with older versions of mq.py
            self._branch = ''
            ph.diffstartline = len(ph.comments)
            if ph.message:
                ph.diffstartline += 1
        except error.ConfigError:
            pass

        self._user = ph.user or ''
        self._desc = ph.message and '\n'.join(ph.message).strip() or ''
        try:
            self._date = ph.date and util.parsedate(ph.date) or util.makedate()
        except error.Abort:
            self._date = util.makedate()
开发者ID:gilshwartz,项目名称:tortoisehg-caja,代码行数:57,代码来源:patchctx.py


示例15: __call__

    def __call__(self, sock, strict=False):
        host = self.host
        cacerts = self.ui.config('web', 'cacerts')
        hostfingerprint = self.ui.config('hostfingerprints', host)
        if not getattr(sock, 'getpeercert', False): # python 2.5 ?
            if hostfingerprint:
                raise util.Abort(_("host fingerprint for %s can't be "
                                   "verified (Python too old)") % host)
            if strict:
                raise util.Abort(_("certificate for %s can't be verified "
                                   "(Python too old)") % host)
            if self.ui.configbool('ui', 'reportoldssl', True):
                self.ui.warn(_("warning: certificate for %s can't be verified "
                               "(Python too old)\n") % host)
            return

        if not sock.cipher(): # work around http://bugs.python.org/issue13721
            raise util.Abort(_('%s ssl connection error') % host)
        try:
            peercert = sock.getpeercert(True)
            peercert2 = sock.getpeercert()
        except AttributeError:
            raise util.Abort(_('%s ssl connection error') % host)

        if not peercert:
            raise util.Abort(_('%s certificate error: '
                               'no certificate received') % host)
        peerfingerprint = util.sha1(peercert).hexdigest()
        nicefingerprint = ":".join([peerfingerprint[x:x + 2]
            for x in xrange(0, len(peerfingerprint), 2)])
        if hostfingerprint:
            if peerfingerprint.lower() != \
                    hostfingerprint.replace(':', '').lower():
                raise util.Abort(_('certificate for %s has unexpected '
                                   'fingerprint %s') % (host, nicefingerprint),
                                 hint=_('check hostfingerprint configuration'))
            self.ui.debug('%s certificate matched fingerprint %s\n' %
                          (host, nicefingerprint))
        elif cacerts:
            msg = _verifycert(peercert2, host)
            if msg:
                raise util.Abort(_('%s certificate error: %s') % (host, msg),
                                 hint=_('configure hostfingerprint %s or use '
                                        '--insecure to connect insecurely') %
                                      nicefingerprint)
            self.ui.debug('%s certificate successfully verified\n' % host)
        elif strict:
            raise util.Abort(_('%s certificate with fingerprint %s not '
                               'verified') % (host, nicefingerprint),
                             hint=_('check hostfingerprints or web.cacerts '
                                     'config setting'))
        else:
            self.ui.warn(_('warning: %s certificate with fingerprint %s not '
                           'verified (check hostfingerprints or web.cacerts '
                           'config setting)\n') %
                         (host, nicefingerprint))
开发者ID:areshero,项目名称:ThirdWorldApp,代码行数:56,代码来源:sslutil.py


示例16: copyandhash

def copyandhash(instream, outfile):
    '''Read bytes from instream (iterable) and write them to outfile,
    computing the SHA-1 hash of the data along the way.  Close outfile
    when done and return the binary hash.'''
    hasher = util.sha1('')
    for data in instream:
        hasher.update(data)
        outfile.write(data)

    # Blecch: closing a file that somebody else opened is rude and
    # wrong. But it's so darn convenient and practical! After all,
    # outfile was opened just to copy and hash.
    outfile.close()

    return hasher.digest()
开发者ID:sandeepprasanna,项目名称:ODOO,代码行数:15,代码来源:lfutil.py


示例17: _hashignore

def _hashignore(ignore):
    """Calculate hash for ignore patterns and filenames

    If this information changes between Mercurial invocations, we can't
    rely on Watchman information anymore and have to re-scan the working
    copy.

    """
    sha1 = util.sha1()
    if util.safehasattr(ignore, "includepat"):
        sha1.update(ignore.includepat)
    sha1.update("\0\0")
    if util.safehasattr(ignore, "excludepat"):
        sha1.update(ignore.excludepat)
    sha1.update("\0\0")
    if util.safehasattr(ignore, "patternspat"):
        sha1.update(ignore.patternspat)
    sha1.update("\0\0")
    if util.safehasattr(ignore, "_files"):
        for f in ignore._files:
            sha1.update(f)
    sha1.update("\0")
    return sha1.hexdigest()
开发者ID:cmjonze,项目名称:mercurial,代码行数:23,代码来源:__init__.py


示例18: __call__

 def __call__(self, sock):
     host = self.host
     cacerts = self.ui.config('web', 'cacerts')
     hostfingerprint = self.ui.config('hostfingerprints', host)
     if cacerts and not hostfingerprint:
         msg = _verifycert(sock.getpeercert(), host)
         if msg:
             raise util.Abort(_('%s certificate error: %s '
                                '(use --insecure to connect '
                                'insecurely)') % (host, msg))
         self.ui.debug('%s certificate successfully verified\n' % host)
     else:
         if getattr(sock, 'getpeercert', False):
             peercert = sock.getpeercert(True)
             peerfingerprint = util.sha1(peercert).hexdigest()
             nicefingerprint = ":".join([peerfingerprint[x:x + 2]
                 for x in xrange(0, len(peerfingerprint), 2)])
             if hostfingerprint:
                 if peerfingerprint.lower() != \
                         hostfingerprint.replace(':', '').lower():
                     raise util.Abort(_('invalid certificate for %s '
                                        'with fingerprint %s') %
                                      (host, nicefingerprint))
                 self.ui.debug('%s certificate matched fingerprint %s\n' %
                               (host, nicefingerprint))
             else:
                 self.ui.warn(_('warning: %s certificate '
                                'with fingerprint %s not verified '
                                '(check hostfingerprints or web.cacerts '
                                'config setting)\n') %
                              (host, nicefingerprint))
         else: # python 2.5 ?
             if hostfingerprint:
                 raise util.Abort(_("host fingerprint for %s can't be "
                                    "verified (Python too old)") % host)
             self.ui.warn(_("warning: certificate for %s can't be "
                            "verified (Python too old)\n") % host)
开发者ID:rybesh,项目名称:mysite-lib,代码行数:37,代码来源:sslutil.py


示例19: hashfile

def hashfile(file):
    hasher = util.sha1('')
    with open(file, 'rb') as fd:
        for data in blockstream(fd):
            hasher.update(data)
    return hasher.hexdigest()
开发者ID:sergio,项目名称:dotfiles,代码行数:6,代码来源:bfutil.py


示例20: _lfconvert_addchangeset

def _lfconvert_addchangeset(rsrc, rdst, ctx, revmap, lfiles, normalfiles,
        matcher, size, lfiletohash):
    # Convert src parents to dst parents
    parents = _convertparents(ctx, revmap)

    # Generate list of changed files
    files = _getchangedfiles(ctx, parents)

    dstfiles = []
    for f in files:
        if f not in lfiles and f not in normalfiles:
            islfile = _islfile(f, ctx, matcher, size)
            # If this file was renamed or copied then copy
            # the largefile-ness of its predecessor
            if f in ctx.manifest():
                fctx = ctx.filectx(f)
                renamed = fctx.renamed()
                renamedlfile = renamed and renamed[0] in lfiles
                islfile |= renamedlfile
                if 'l' in fctx.flags():
                    if renamedlfile:
                        raise util.Abort(
                            _('renamed/copied largefile %s becomes symlink')
                            % f)
                    islfile = False
            if islfile:
                lfiles.add(f)
            else:
                normalfiles.add(f)

        if f in lfiles:
            dstfiles.append(lfutil.standin(f))
            # largefile in manifest if it has not been removed/renamed
            if f in ctx.manifest():
                fctx = ctx.filectx(f)
                if 'l' in fctx.flags():
                    renamed = fctx.renamed()
                    if renamed and renamed[0] in lfiles:
                        raise util.Abort(_('largefile %s becomes symlink') % f)

                # largefile was modified, update standins
                m = util.sha1('')
                m.update(ctx[f].data())
                hash = m.hexdigest()
                if f not in lfiletohash or lfiletohash[f] != hash:
                    rdst.wwrite(f, ctx[f].data(), ctx[f].flags())
                    executable = 'x' in ctx[f].flags()
                    lfutil.writestandin(rdst, lfutil.standin(f), hash,
                        executable)
                    lfiletohash[f] = hash
        else:
            # normal file
            dstfiles.append(f)

    def getfilectx(repo, memctx, f):
        if lfutil.isstandin(f):
            # if the file isn't in the manifest then it was removed
            # or renamed, raise IOError to indicate this
            srcfname = lfutil.splitstandin(f)
            try:
                fctx = ctx.filectx(srcfname)
            except error.LookupError:
                return None
            renamed = fctx.renamed()
            if renamed:
                # standin is always a largefile because largefile-ness
                # doesn't change after rename or copy
                renamed = lfutil.standin(renamed[0])

            return context.memfilectx(repo, f, lfiletohash[srcfname] + '\n',
                                      'l' in fctx.flags(), 'x' in fctx.flags(),
                                      renamed)
        else:
            return _getnormalcontext(repo, ctx, f, revmap)

    # Commit
    _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap)
开发者ID:RayFerr000,项目名称:PLTL,代码行数:77,代码来源:lfcommands.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.shellquote函数代码示例发布时间:2022-05-27
下一篇:
Python util.safehasattr函数代码示例发布时间: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