当前位置: 首页>>代码示例>>Python>>正文


Python util.sha1函数代码示例

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


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


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