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

Python util.sha1函数代码示例

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

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



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

示例1: _findexactmatches

def _findexactmatches(repo, added, removed):
    '''find renamed files that have no changes

    Takes a list of new filectxs and a list of removed filectxs, and yields
    (before, after) tuples of exact matches.
    '''
    numfiles = len(added) + len(removed)

    # Get hashes of removed files.
    hashes = {}
    for i, fctx in enumerate(removed):
        repo.ui.progress(_('searching for exact renames'), i, total=numfiles)
        h = util.sha1(fctx.data()).digest()
        hashes[h] = fctx

    # For each added file, see if it corresponds to a removed file.
    for i, fctx in enumerate(added):
        repo.ui.progress(_('searching for exact renames'), i + len(removed),
                total=numfiles)
        h = util.sha1(fctx.data()).digest()
        if h in hashes:
            yield (hashes[h], fctx)

    # Done
    repo.ui.progress(_('searching for exact renames'), None)
开发者ID:MezzLabs,项目名称:mercurial,代码行数:25,代码来源:similar.py


示例2: old_login

def old_login(username, md5_password):
    from api import agent_header
    exponent = int("010001", 16)
    modulus = int("AC69F5CCC8BDE47CD3D371603748378C9CFAD2938A6B021E0E191013975AD683F5CBF9ADE8BD7D46B4D2EC2D78A"
                  "F146F1DD2D50DC51446BB8880B8CE88D476694DFC60594393BEEFAA16F5DBCEBE22F89D640F5336E42F587DC4AF"
                  "EDEFEAC36CF007009CCCE5C1ACB4FF06FBA69802A8085C2C54BADD0597FC83E6870F1E36FD", 16)

    param = '{"cmdID":1,"isCompressed":0,"rsaKey":{"n":"AC69F5CCC8BDE47CD3D371603748378C9CFAD2938A6B0' \
            '21E0E191013975AD683F5CBF9ADE8BD7D46B4D2EC2D78AF146F1DD2D50DC51446BB8880B8CE88D476694DFC60594393BEEFAA16F' \
            '5DBCEBE22F89D640F5336E42F587DC4AFEDEFEAC36CF007009CCCE5C1ACB4FF06FBA69802A8085C2C54BADD0597FC83E6870F1E3' \
            '6FD","e":"010001"},"businessType":%s,"passWord":"%s","loginType":0,"sdkVersion":177588,' \
            '"appName":"ANDROID-com.xunlei.redcrystalandroid","platformVersion":1,"devicesign":"%s",' \
            '"sessionID":"","protocolVersion":%s,"userName":"%s","extensionList":"","sequenceNo":%s,' \
            '"peerID":"","clientVersion":"1.0.0"}'

    _chars = "0123456789ABCDEF"

    deviceid = username
    device_id = md5(deviceid)

    appName = 'com.xunlei.redcrystalandroid'
    businessType = '61'
    key = 'C2049664-1E4A-4E1C-A475-977F0E207C9C'
    key_md5 = md5(key)

    device_sign = "div100.%s%s" % (device_id, md5(sha1("%s%s%s%s" % (device_id, appName, businessType, key_md5))))

    hash_password = hex(pow_mod(StrToInt(md5_password), exponent, modulus))[2:].upper().zfill(256)

    params = param % (61, hash_password, device_sign, 108, username, 1000006)

    r = requests.post("https://login.mobile.reg2t.sandai.net/", data=params, headers=agent_header, verify=False)
    login_status = json.loads(r.text)

    return login_status
开发者ID:FANWENBIN,项目名称:crysadm,代码行数:35,代码来源:login.py


示例3: gitindex

 def gitindex(text):
     if not text:
         return "0" * 40
     l = len(text)
     s = util.sha1("blob %d\0" % l)
     s.update(text)
     return s.hexdigest()
开发者ID:pombredanne,项目名称:SmartNotes,代码行数:7,代码来源:patch.py


示例4: test_remapping

def test_remapping(metasync, opts):
    replication = 2
    config = [(0,2), (1,4), (2,4), (3,2)]
    hspace = 20
    detmap = DetMap2(config, hspace, replication)
    N = 50
    lst = []
    for _ in range(100):
        randstr = ''.join(random.choice(string.letters + string.digits) for _ in range(N))
        hashid = util.sha1(randstr)
        lst.append(hashid)

        #lst = detmap.get_mapping(hashid)
        #for i in lst:
        #    count[i] += 1
    detmap.reconfig(config, 3)
    assert len(detmap.mapinfo) == 2
    added, removed = detmap.get_remapping(lst)
    for i in removed:
        assert len(removed[i]) == 0
    import copy
    detmap = DetMap2(config, hspace, replication)
    config = copy.copy(config)
    config.pop()
    lst3 = []
    for hv in lst:
        if 3 in detmap.get_mapping(hv):
            lst3.append(hv)
    detmap.reconfig(config)
    added, removed = detmap.get_remapping(lst)
    assert len(removed[3]) == len(lst3)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:31,代码来源:test.py


示例5: post

 def post(self):
     name = self.get_argument("name", "")
     email = self.get_argument("email", "")
     password = self.get_argument("password", None)
     if not name or len(name) > 15:
         self.render("join.html", error=111, name=name, email=email)
         return
     match = re.search(r"[\w.-][email protected][\w.-]+", email)
     if not match:
         self.render("join.html", error=112, name=name, email=email)
         return
     if not password:
         self.render("join.html", error=110, name=name, email=email)
         return
     user = self.user_dal.get({"email": email})
     if user:
         self.render("join.html", error=113, name=name, email=email)
         return
     user = self.user_dal.template()
     user["name"] = name
     user["email"] = email
     user["password"] = sha1(password)
     user["remote_ip"] = self.request.remote_ip
     user_id = self.user_dal.insert(user)
     if not user_id:
         self.render("join.html", error=114)
         return
     self.set_secure_cookie("user", str(user_id), expires_days=30)
     self.redirect(self.get_argument("next", "/"))
开发者ID:kerneltravel,项目名称:diggit,代码行数:29,代码来源:home.py


示例6: unbundle

    def unbundle(self, cg, heads, source):
        '''Send cg (a readable file-like object representing the
        changegroup to push, typically a chunkbuffer object) to the
        remote server as a bundle. Return an integer indicating the
        result of the push (see localrepository.addchangegroup()).'''

        if heads != ['force'] and self.capable('unbundlehash'):
            heads = encodelist(['hashed',
                                util.sha1(''.join(sorted(heads))).digest()])
        else:
            heads = encodelist(heads)

        ret, output = self._callpush("unbundle", cg, heads=heads)
        if ret == "":
            raise error.ResponseError(
                _('push failed:'), output)
        try:
            ret = int(ret)
        except ValueError:
            raise error.ResponseError(
                _('push failed (unexpected response):'), ret)

        for l in output.splitlines(True):
            self.ui.status(_('remote: '), l)
        return ret
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:25,代码来源:wireproto.py


示例7: unbundle

    def unbundle(self, cg, heads, source):
        '''Send cg (a readable file-like object representing the
        changegroup to push, typically a chunkbuffer object) to the
        remote server as a bundle.

        When pushing a bundle10 stream, return an integer indicating the
        result of the push (see localrepository.addchangegroup()).

        When pushing a bundle20 stream, return a bundle20 stream.'''

        if heads != ['force'] and self.capable('unbundlehash'):
            heads = encodelist(['hashed',
                                util.sha1(''.join(sorted(heads))).digest()])
        else:
            heads = encodelist(heads)

        if util.safehasattr(cg, 'deltaheader'):
            # this a bundle10, do the old style call sequence
            ret, output = self._callpush("unbundle", cg, heads=heads)
            if ret == "":
                raise error.ResponseError(
                    _('push failed:'), output)
            try:
                ret = int(ret)
            except ValueError:
                raise error.ResponseError(
                    _('push failed (unexpected response):'), ret)

            for l in output.splitlines(True):
                self.ui.status(_('remote: '), l)
        else:
            # bundle2 push. Send a stream, fetch a stream.
            stream = self._calltwowaystream('unbundle', cg, heads=heads)
            ret = bundle2.unbundle20(self.ui, stream)
        return ret
开发者ID:areshero,项目名称:ThirdWorldApp,代码行数:35,代码来源:wireproto.py


示例8: hv

    def hv(self):
        # dirty, recompute the hv
        if self._dirty or self._hv is None:
            self._hv = util.sha1(self.dump())
            self._dirty = False
            self._updated()

        return self._hv
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:8,代码来源:blobs.py


示例9: post

 def post(self):
     user = self.current_user
     password = self.get_argument("pwd", "")
     new_pwd = self.get_argument("new_pwd", "")
     if user["password"] != sha1(password):
         self.render("account/pwd.html", error=141)
         return
     if new_pwd == "":
         self.render("account/pwd.html", error=142)
         return
     user["password"] = sha1(new_pwd)
     result = self.user_dal.update_user(user)
     if result:
         self.render("account/pwd.html", error=143)
         return
     current_user = user
     self.render("account/pwd.html", error=140)
开发者ID:crazyevan,项目名称:diggit,代码行数:17,代码来源:account.py


示例10: cachehash

def cachehash(repo, hideable):
    """return sha1 hash of repository data to identify a valid cache.

    We calculate a sha1 of repo heads and the content of the obsstore and write
    it to the cache. Upon reading we can easily validate by checking the hash
    against the stored one and discard the cache in case the hashes don't match.
    """
    h = util.sha1()
    h.update(''.join(repo.heads()))
    h.update(str(hash(frozenset(hideable))))
    return h.digest()
开发者ID:ZanderZhang,项目名称:Andriod-Learning,代码行数:11,代码来源:repoview.py


示例11: connect

        def connect(self):
            self.sock = _create_connection((self.host, self.port))

            host = self.host
            if self.realhostport: # use CONNECT proxy
                something = _generic_proxytunnel(self)
                host = self.realhostport.rsplit(':', 1)[0]

            cacerts = self.ui.config('web', 'cacerts')
            hostfingerprint = self.ui.config('hostfingerprints', host)

            if cacerts and not hostfingerprint:
                cacerts = util.expandpath(cacerts)
                if not os.path.exists(cacerts):
                    raise util.Abort(_('could not find '
                                       'web.cacerts: %s') % cacerts)
                self.sock = _ssl_wrap_socket(self.sock, self.key_file,
                    self.cert_file, cert_reqs=CERT_REQUIRED,
                    ca_certs=cacerts)
                msg = _verifycert(self.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:
                self.sock = _ssl_wrap_socket(self.sock, self.key_file,
                    self.cert_file)
                if hasattr(self.sock, 'getpeercert'):
                    peercert = self.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(_('no certificate for %s with '
                                           'configured hostfingerprint') % host)
                    self.ui.warn(_('warning: %s certificate not verified '
                                   '(check web.cacerts config setting)\n') %
                                 host)
开发者ID:MezzLabs,项目名称:mercurial,代码行数:54,代码来源:url.py


示例12: check_heads

def check_heads(repo, their_heads, context):
    """check if the heads of a repo have been modified

    Used by peer for unbundling.
    """
    heads = repo.heads()
    heads_hash = util.sha1(''.join(sorted(heads))).digest()
    if not (their_heads == ['force'] or their_heads == heads or
            their_heads == ['hashed', heads_hash]):
        # someone else committed/pushed/unbundled while we
        # were transferring data
        raise error.PushRaced('repository changed while %s - '
                              'please try again' % context)
开发者ID:ZanderZhang,项目名称:Andriod-Learning,代码行数:13,代码来源:exchange.py


示例13: test_map_pack

def test_map_pack(metasync, opts):
    config = [(0,2), (1,10), (2,4), (3,2)]
    hspace = 100 
    replication = 2
    N = 50
    detmap = DetMap2(config, hspace, replication)

    detmap2 = DetMap2(config, hspace, replication)
    detmap2.pack()

    for _ in range(100):
        randstr = ''.join(random.choice(string.letters + string.digits) for _ in range(N))
        hashid = util.sha1(randstr)
        assert detmap.get_mapping(hashid) == detmap2.get_mapping(hashid)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:14,代码来源:test.py


示例14: connect

        def connect(self):
            if hasattr(self, 'ui'):
                cacerts = self.ui.config('web', 'cacerts')
                if cacerts:
                    cacerts = util.expandpath(cacerts)
            else:
                cacerts = None

            hostfingerprint = self.ui.config('hostfingerprints', self.host)
            if cacerts and not hostfingerprint:
                sock = _create_connection((self.host, self.port))
                self.sock = _ssl_wrap_socket(sock, self.key_file,
                        self.cert_file, cert_reqs=CERT_REQUIRED,
                        ca_certs=cacerts)
                msg = _verifycert(self.sock.getpeercert(), self.host)
                if msg:
                    raise util.Abort(_('%s certificate error: %s '
                                       '(use --insecure to connect '
                                       'insecurely)') % (self.host, msg))
                self.ui.debug('%s certificate successfully verified\n' %
                              self.host)
            else:
                httplib.HTTPSConnection.connect(self)
                if hasattr(self.sock, 'getpeercert'):
                    peercert = self.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') %
                                             (self.host, nicefingerprint))
                        self.ui.debug('%s certificate matched fingerprint %s\n' %
                                      (self.host, nicefingerprint))
                    else:
                        self.ui.warn(_('warning: %s certificate '
                                       'with fingerprint %s not verified '
                                       '(check hostfingerprints or web.cacerts '
                                       'config setting)\n') %
                                     (self.host, nicefingerprint))
                else: # python 2.5 ?
                    if hostfingerprint:
                        raise util.Abort(_('no certificate for %s '
                                           'with fingerprint') % self.host)
                    self.ui.warn(_('warning: %s certificate not verified '
                                   '(check web.cacerts config setting)\n') %
                                 self.host)
开发者ID:helloandre,项目名称:cr48,代码行数:49,代码来源:url.py


示例15: executeQuery

def executeQuery(sparqlEndpoint, query, returnFormat = JSON):
  """
    Execute SPARQL @query on @sparqlEndpoint.
    Cache the query results temporarily in the tmp directory.
  """
  path = os.path.join(util.root(), "tmp", util.sha1(sparqlEndpoint.endpoint + query))
  if os.path.exists(path):
    with open(path, "rb") as file:
      return pickle.load(file)
  else:
    sparqlEndpoint.setQuery(unicode(query.decode("UTF-8")))
    sparqlEndpoint.setReturnFormat(returnFormat)
    results = sparqlEndpoint.query().convert()
    with open(path, "wb") as file:
      pickle.dump(results, file)
    return results
开发者ID:jindrichmynarz,项目名称:RDF-to-CKAN-import,代码行数:16,代码来源:sparql.py


示例16: add

    def add(self, fcl, fco, fca, fd):
        """add a new (potentially?) conflicting file the merge state
        fcl: file context for local,
        fco: file context for remote,
        fca: file context for ancestors,
        fd:  file path of the resulting merge.

        note: also write the local version to the `.hg/merge` directory.
        """
        hash = util.sha1(fcl.path()).hexdigest()
        self._repo.vfs.write('merge/' + hash, fcl.data())
        self._state[fd] = ['u', hash, fcl.path(),
                           fca.path(), hex(fca.filenode()),
                           fco.path(), hex(fco.filenode()),
                           fcl.flags()]
        self._dirty = True
开发者ID:RayFerr000,项目名称:PLTL,代码行数:16,代码来源:merge.py


示例17: old_login

def old_login(username, md5_password):

    hash_password = rsa_encode(md5_password)

    _chars = "0123456789ABCDEF"
    peer_id = ''.join(random.sample(_chars, 16))

    device_id = md5("%s23333" % md5_password) # just generate a 32bit string

    appName = 'com.xunlei.redcrystalandroid'
    key = 'C2049664-1E4A-4E1C-A475-977F0E207C9C'
    md5_key = md5(key)

    device_sign = 'div100.%s%s' % (device_id, md5(sha1("%s%s%s%s" % (device_id, appName, 61, md5_key))))

    payload = json.dumps({
            "protocolVersion": PROTOCOL_VERSION,
            "sequenceNo": 1000001,
            "platformVersion": 1,
            "sdkVersion": 177588,
            "peerID": peer_id,
            "businessType": 61,
            "clientVersion": APP_VERSION,
            "devicesign": device_sign,
            "isCompressed": 0,
            "cmdID": 1,
            "userName": username,
            "passWord": hash_password,
            "loginType": 0,
            "sessionID": "",
            "verifyKey": "",
            "verifyCode": "",
            "appName": "ANDROID-com.xunlei.redcrystalandroid",
            "rsaKey": {
                "e": "%06X" % rsa_pubexp,
                "n": long2hex(rsa_mod)
            },
            "extensionList": ""
    })

    headers = {'User-Agent': "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2"}
    r = requests.post("https://login.mobile.reg2t.sandai.net/", data=payload, headers=headers, verify=False)

    login_status = json.loads(r.text)

    return login_status
开发者ID:im1986,项目名称:crysadm-1,代码行数:46,代码来源:login.py


示例18: _load

    def _load(self):
        if self._entries is not None:
            return

        self._entries = {}
        pn = self.bs.get_path(self.hv)

        firstline = True
        for line in open(pn):
            # processing header line
            if firstline:
                self._eval_header(line)
                firstline = False
                continue
            # processing entries
            self._entries.update(self._eval_entry(line))

        # strong assert!
        assert self.hv == util.sha1(self.dump())
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:19,代码来源:blobs.py


示例19: test_mapping_fairness

def test_mapping_fairness(metasync, opts):
    "test the fairness of mapping scheme"

    import string
    import random

    def evaluate(count, config):
        N = sum(count)
        C = sum(map(lambda x: x[1], config))
        score = 0.0
        for srv in config:
            score += (1.0*count[srv[0]]/srv[1] - 1.0*N/C) ** 2
        return score

    config = [(0,2), (1,7), (2,10), (3,15)]
    nspace = sum(map(lambda x: x[1], config))
    result = [['replication', 'factor', 'result', 'fairness', 'score']]
    N = 50
    random.seed(0)

    for replication in range(1, 4):
        for factor in range(100, 1001, 100):

            hspace = factor * nspace
            detmap = DetMap2(config, hspace, replication)
            count = [0, 0, 0, 0]
            
            for _ in range(5000):
                randstr = ''.join(random.choice(string.letters + string.digits) for _ in range(N))
                hashid = util.sha1(randstr)

                lst = detmap.get_mapping(hashid)
                for i in lst:
                    count[i] += 1
            fairness = [1.0 * count[i] / config[i][1] for i in range(4)]
            score = evaluate(count, config)
            row = [replication, factor, count, fairness, score]
            result.append(row)

    for row in result:
        for e in row:
            print "%s\t" % e,
        print
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:43,代码来源:test.py


示例20: _hashfiltered

    def _hashfiltered(self, repo):
        """build hash of revision filtered in the current cache

        Tracking tipnode and tiprev is not enough to ensure validity of the
        cache as they do not help to distinct cache that ignored various
        revision bellow tiprev.

        To detect such difference, we build a cache of all ignored revisions.
        """
        cl = repo.changelog
        if not cl.filteredrevs:
            return None
        key = None
        revs = sorted(r for r in cl.filteredrevs if r <= self.tiprev)
        if revs:
            s = util.sha1()
            for rev in revs:
                s.update('%s;' % rev)
            key = s.digest()
        return key
开发者ID:areshero,项目名称:ThirdWorldApp,代码行数:20,代码来源:branchmap.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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