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

Python util.sha函数代码示例

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

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



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

示例1: test_put_tiddler_via_recipe

def test_put_tiddler_via_recipe():
    http = httplib2.Http()
    json = simplejson.dumps(
        dict(
            text="i fight for the users 2",
            tags=["tagone", "tagtwo"],
            modifier="",
            modified="200803030303",
            created="200803030303",
        )
    )

    response, content = http.request(
        "http://our_test_domain:8001/recipes/long/tiddlers/FantasticVoyage",
        method="PUT",
        headers={"Content-Type": "application/json"},
        body=json,
    )

    assert response["status"] == "204"
    etag_hash = sha("GUEST:application/json").hexdigest()
    assert response["etag"] == '"bag1/FantasticVoyage/1;%s"' % etag_hash
    url = response["location"]

    reponse, content = http.request(url, method="GET", headers={"Accept": "application/json"})
    tiddler_dict = simplejson.loads(content)
    assert tiddler_dict["bag"] == "bag1"
    etag_hash = sha("GUEST:application/json").hexdigest()
    assert response["etag"] == '"bag1/FantasticVoyage/1;%s"' % etag_hash
开发者ID:jdlrobson,项目名称:tiddlyweb,代码行数:29,代码来源:test_web_tiddler.py


示例2: test_put_tiddler_cache_fakey

def test_put_tiddler_cache_fakey():
    [os.unlink('.test_cache/%s' % x) for x in os.listdir('.test_cache')]
    http_caching = httplib2.Http('.test_cache')
    http = httplib2.Http()

    json = simplejson.dumps(dict(text='i fight for the users 2', tags=['tagone','tagtwo'], modifier='', modified='200803030303', created='200803030303'))

    response, content = http_caching.request('http://our_test_domain:8001/recipes/long/tiddlers/CashForCache',
            method='PUT', headers={'Content-Type': 'application/json'}, body=json)
    assert response['status'] == '204'
    etag_hash = sha('GUEST:application/json').hexdigest()
    assert response['etag'] == '"bag1/CashForCache/1;%s"' % etag_hash

    response, content = http_caching.request('http://our_test_domain:8001/recipes/long/tiddlers/CashForCache',
            method='GET', headers={'Accept': 'application/json'})
    assert response['status'] == '200'
    etag_hash = sha('GUEST:application/json').hexdigest()
    assert response['etag'] == '"bag1/CashForCache/1;%s"' % etag_hash

    response, content = http.request('http://our_test_domain:8001/recipes/long/tiddlers/CashForCache',
            method='PUT', headers={'Content-Type': 'application/json'}, body=json)
    assert response['status'] == '204'
    etag_hash = sha('GUEST:application/json').hexdigest()
    assert response['etag'] == '"bag1/CashForCache/2;%s"' % etag_hash

    response, content = http_caching.request('http://our_test_domain:8001/recipes/long/tiddlers/CashForCache',
            method='PUT', headers={'Content-Type': 'application/json'}, body=json)
    assert response['status'] == '412'
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:28,代码来源:test_web_tiddler.py


示例3: test_put_tiddler_cache_fakey

def test_put_tiddler_cache_fakey():
    [os.unlink(".test_cache/%s" % x) for x in os.listdir(".test_cache")]
    http_caching = httplib2.Http(".test_cache")
    http = httplib2.Http()

    json = simplejson.dumps(
        dict(
            text="i fight for the users 2",
            tags=["tagone", "tagtwo"],
            modifier="",
            modified="200803030303",
            created="200803030303",
        )
    )

    response, content = http_caching.request(
        "http://our_test_domain:8001/recipes/long/tiddlers/CashForCache",
        method="PUT",
        headers={"Content-Type": "application/json"},
        body=json,
    )
    assert response["status"] == "204"
    etag_hash = sha("GUEST:application/json").hexdigest()
    assert response["etag"] == '"bag1/CashForCache/1;%s"' % etag_hash

    response, content = http_caching.request(
        "http://our_test_domain:8001/recipes/long/tiddlers/CashForCache",
        method="GET",
        headers={"Accept": "application/json"},
    )
    assert response["status"] == "200"
    etag_hash = sha("GUEST:application/json").hexdigest()
    assert response["etag"] == '"bag1/CashForCache/1;%s"' % etag_hash

    response, content = http.request(
        "http://our_test_domain:8001/recipes/long/tiddlers/CashForCache",
        method="PUT",
        headers={"Content-Type": "application/json"},
        body=json,
    )
    assert response["status"] == "204"
    etag_hash = sha("GUEST:application/json").hexdigest()
    assert response["etag"] == '"bag1/CashForCache/2;%s"' % etag_hash

    response, content = http_caching.request(
        "http://our_test_domain:8001/recipes/long/tiddlers/CashForCache",
        method="PUT",
        headers={"Content-Type": "application/json"},
        body=json,
    )
    assert response["status"] == "412"
开发者ID:jdlrobson,项目名称:tiddlyweb,代码行数:51,代码来源:test_web_tiddler.py


示例4: _validate_tiddler_list

def _validate_tiddler_list(environ, tiddlers):
    """
    Do Etag and Last modified checks on the
    collection of tiddlers.

    If ETag testing is done, no last modified handling
    is done, even if the ETag testing fails.

    If no 304 is raised, then just return last-modified
    and ETag for the caller to use in constructing
    its HTTP response.
    """
    last_modified_string = http_date_from_timestamp(tiddlers.modified)
    last_modified = ('Last-Modified', last_modified_string)

    username = environ.get('tiddlyweb.usersign', {}).get('name', '')

    try:
        _, mime_type = get_serialize_type(environ)
        mime_type = mime_type.split(';', 1)[0].strip()
    except TypeError:
        mime_type = ''
    etag_string = '"%s:%s"' % (tiddlers.hexdigest(),
            sha('%s:%s' % (username.encode('utf-8'), mime_type)).hexdigest())
    etag = ('Etag', etag_string)

    incoming_etag = check_incoming_etag(environ, etag_string)
    if not incoming_etag:  # only check last modified when no etag
        check_last_modified(environ, last_modified_string)

    return last_modified, etag
开发者ID:tup,项目名称:tiddlyweb,代码行数:31,代码来源:sendtiddlers.py


示例5: make_user

def make_user(username, password):
    user = User(username)
    user.set_password(password)
    store.put(user)

    secret_string = sha('%s%s' % (username, config['secret'])).hexdigest()
    return secret_string
开发者ID:FND,项目名称:tiddlyspace.old,代码行数:7,代码来源:test_web_new_space.py


示例6: test_validator_nonce_success

def test_validator_nonce_success():
    """
    test the validator directly
    ensure that it succeeds when the nonce passed in is correct
    """
    store = get_store(config)
    username = 'foo'
    spacename = 'foo'
    secret = '12345'
    timestamp = datetime.now().strftime('%Y%m%d%H')
    nonce = '%s:%s:%s' % (timestamp, username,
        sha('%s:%s:%s:%s' % (username, timestamp, spacename, secret)).
        hexdigest())
    environ = {
       'tiddlyweb.usersign': {'name': username},
       'tiddlyweb.config': {
           'secret': secret,
           'server_host': {
               'host': '0.0.0.0',
               'port': '8080'
           }
        },
        'HTTP_HOST': 'foo.0.0.0.0:8080'
    }
    make_fake_space(store, spacename)

    csrf = CSRFProtector({})
    result = csrf.check_csrf(environ, nonce)

    assert result == True
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:30,代码来源:test_post_validate.py


示例7: test_no_cookie_sent

def test_no_cookie_sent():
    """
    Test no cookie is sent if one is already present
    """
    store = get_store(config)
    space = 'foo'
    make_fake_space(store, space)
    user = User('foo')
    user.set_password('foobar')
    store.put(user)

    user_cookie = get_auth('foo', 'foobar')
    time = datetime.now().strftime('%Y%m%d%H')
    cookie = 'csrf_token=%s:%s:%s' % (time, user.usersign,
        sha('%s:%s:%s:%s' % (user.usersign,
        time, space, config['secret'])).hexdigest())

    response, _ = http.request('http://foo.0.0.0.0:8080/status',
        method='GET',
        headers={
            'Cookie': 'tiddlyweb_user="%s"; %s' % (user_cookie, cookie)
        })

    cookie = response.get('set-cookie')
    if cookie:
        assert 'csrf_token' not in cookie
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:26,代码来源:test_post_validate.py


示例8: test_cookie_set

def test_cookie_set():
    """
    test that we get a cookie relating to the space we are in
    """
    store = get_store(config)
    space = 'foo'
    make_fake_space(store, space)
    user = User('foo')
    user.set_password('foobar')
    store.put(user)

    user_cookie = get_auth('foo', 'foobar')

    response, content = http.request('http://foo.0.0.0.0:8080/status',
        method='GET',
        headers={
            'Cookie': 'tiddlyweb_user="%s"' % user_cookie
        })

    assert response['status'] == '200', content

    time = datetime.now().strftime('%Y%m%d%H')
    cookie = 'csrf_token=%s:%s:%s' % (time, user.usersign,
        sha('%s:%s:%s:%s' % (user.usersign,
        time, space, config['secret'])).hexdigest())
    assert response['set-cookie'] == cookie
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:26,代码来源:test_post_validate.py


示例9: test_cookie_set

def test_cookie_set():
    """
    test that we get a cookie relating to the space we are in
    """
    store = get_store(config)
    hostname = "foo.0.0.0.0:8080"
    user = User(u"f\u00F6o")
    user.set_password("foobar")
    store.put(user)

    user_cookie = get_auth(u"f\u00F6o", "foobar")

    response, content = http.request(
        "http://foo.0.0.0.0:8080/", method="GET", headers={"Cookie": 'tiddlyweb_user="%s"' % user_cookie}
    )

    assert response["status"] == "200", content

    time = datetime.utcnow().strftime("%Y%m%d%H")
    cookie = "csrf_token=%s:%s:%s" % (
        time,
        user.usersign,
        sha("%s:%s:%s:%s" % (user.usersign, time, hostname, config["secret"])).hexdigest(),
    )
    assert response["set-cookie"] == quote(cookie.encode("utf-8"), safe=".!~*'():=")
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.csrf,代码行数:25,代码来源:test_post_validate.py


示例10: validate_mapuser

def validate_mapuser(tiddler, environ):
    """
    If a tiddler is put to the MAPUSER bag clear
    out the tiddler and set fields['mapped_user']
    to the current username. There will always be
    a current username because the create policy
    for the bag is set to ANY.
    """
    if tiddler.bag == 'MAPUSER':
        try:
            user_cookie = environ['HTTP_COOKIE']
            cookie = Cookie.SimpleCookie()
            cookie.load(str(user_cookie))
            cookie_value = cookie['tiddlyweb_secondary_user'].value
            secret = environ['tiddlyweb.config']['secret']
            usersign, cookie_secret = cookie_value.rsplit(':', 1)
        except KeyError:
            raise InvalidTiddlerError('secondary cookie not present')

        if cookie_secret != sha('%s%s' % (usersign, secret)).hexdigest():
            raise InvalidTiddlerError('secondary cookie invalid')

        if usersign != tiddler.title:
            raise InvalidTiddlerError('secondary cookie mismatch')

        store = environ['tiddlyweb.store']
        # XXX this is a potentially expensive operation but let's not
        # early optimize
        if tiddler.title in (user.usersign for user in store.list_users()):
            raise InvalidTiddlerError('username exists')
        tiddler.text = ''
        tiddler.tags = []
        tiddler.fields = {}
        tiddler.fields['mapped_user'] = environ['tiddlyweb.usersign']['name']
    return tiddler
开发者ID:TiddlySpace,项目名称:tiddlyspace,代码行数:35,代码来源:validator.py


示例11: make_cookie

def make_cookie(name, value, mac_key=None, path=None, expires=None, httponly=True, domain=None):
    """
    Create a cookie string, optionally with a MAC, path and
    expires value. If ``expires`` is provided, its value should be
    in seconds.
    """
    cookie = SimpleCookie()

    value = encode_name(value)

    if mac_key:
        secret_string = sha("%s%s" % (value, mac_key)).hexdigest()
        cookie[name] = "%s:%s" % (value, secret_string)
    else:
        cookie[name] = value

    if path:
        cookie[name]["path"] = path

    if expires:
        cookie[name]["max-age"] = expires

    if domain:
        cookie[name]["domain"] = domain

    output = cookie.output(header="").lstrip().rstrip()
    if httponly:
        output += "; httponly"
    return output
开发者ID:gravesmedical,项目名称:tiddlyweb,代码行数:29,代码来源:util.py


示例12: send_entity

def send_entity(environ, start_response, entity):
    """
    Send a bag or recipe out HTTP, first serializing to
    the correct type.
    """
    username = environ['tiddlyweb.usersign']['name']
    try:
        serialize_type, mime_type = get_serialize_type(environ)
        serializer = Serializer(serialize_type, environ)
        serializer.object = entity
        content = serializer.to_string()
    except NoSerializationError:
        raise HTTP415('Content type %s not supported' % mime_type)

    etag_string = '"%s"' % (sha(_entity_etag(entity) +
        encode_name(username) + encode_name(mime_type)).hexdigest())

    start_response("200 OK",
            [('Content-Type', mime_type),
                ('ETag', etag_string),
                ('Vary', 'Accept')])

    if isinstance(content, basestring):
        return [content]
    else:
        return content
开发者ID:chancejiang,项目名称:tiddlyweb,代码行数:26,代码来源:sendentity.py


示例13: make_cookie

def make_cookie(name, value, mac_key=None, path=None,
        expires=None, httponly=True, domain=None):
    """
    Create a cookie string, optionally with a MAC, path and
    expires value. Expires is in seconds.
    """
    cookie = Cookie.SimpleCookie()

    value = value.encode('utf-8')

    if mac_key:
        secret_string = sha('%s%s' % (value, mac_key)).hexdigest()
        cookie[name] = '%s:%s' % (value, secret_string)
    else:
        cookie[name] = value

    if path:
        cookie[name]['path'] = path

    if expires:
        cookie[name]['max-age'] = expires

    if domain:
        cookie[name]['domain'] = domain

    output = cookie.output(header='').lstrip().rstrip()
    if httponly:
        output += '; httponly'
    return output
开发者ID:funkyeah,项目名称:tiddlyweb,代码行数:29,代码来源:util.py


示例14: test_get_tiddler_revision_3

def test_get_tiddler_revision_3():
    http = httplib2.Http()
    response, content = http.request('http://our_test_domain:8001/bags/bag1/tiddlers/TestOne/revisions/3',
            method='GET')
    assert response['status'] == '200'
    etag_hash = sha('GUEST:text/html').hexdigest()
    assert response['etag'] == '"bag1/TestOne/3;%s"' % etag_hash
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:7,代码来源:test_web_tiddler_revisions.py


示例15: _remotebag_key

def _remotebag_key(environ, uri):
    """
    Generate a tiddler title to use as the key in the REMOTEURI_BAG.
    """
    server_host = environ.get('tiddlyweb.config', {}).get(
            'server_host')['host']
    return sha(uri + server_host).hexdigest()
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.remotebag,代码行数:7,代码来源:remotebag.py


示例16: test_put_tiddler_txt_4

def test_put_tiddler_txt_4():
    http = httplib2.Http()
    encoded_body = text_put_body2.encode('utf-8')
    response, content = http.request('http://our_test_domain:8001/bags/bag1/tiddlers/TestOne',
            method='PUT', headers={'Content-Type': 'text/plain'}, body=encoded_body)
    assert response['status'] == '204'
    etag_hash = sha('GUEST:text/plain').hexdigest()
    assert response['etag'] == '"bag1/TestOne/4;%s"' % etag_hash
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:8,代码来源:test_web_tiddler_revisions.py


示例17: check_password

 def check_password(self, candidate_password):
     """
     Check the password for this user. Return ``True`` if correct.
     """
     if not self._password:
         return False
     crypted_thing = sha(candidate_password.strip()).hexdigest()
     return crypted_thing == self._password
开发者ID:24king,项目名称:tiddlyweb,代码行数:8,代码来源:user.py


示例18: check_password

 def check_password(self, candidate_password):
     """
     Check the password for this user. Return true if correct.
     """
     if self._password is None:
         return False
     crypted_thing = sha(candidate_password.strip().encode("utf-8")).hexdigest()
     return crypted_thing == self._password
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:8,代码来源:user.py


示例19: test_put_tiddler_via_recipe

def test_put_tiddler_via_recipe():
    http = httplib2.Http()
    json = simplejson.dumps(dict(text='i fight for the users 2', tags=['tagone','tagtwo'], modifier='', modified='200803030303', created='200803030303'))

    response, content = http.request('http://our_test_domain:8001/recipes/long/tiddlers/FantasticVoyage',
            method='PUT', headers={'Content-Type': 'application/json'}, body=json)

    assert response['status'] == '204'
    etag_hash = sha('GUEST:application/json').hexdigest()
    assert response['etag'] == '"bag1/FantasticVoyage/1;%s"' % etag_hash
    url = response['location']

    reponse, content = http.request(url, method='GET', headers={'Accept': 'application/json'})
    tiddler_dict = simplejson.loads(content)
    assert tiddler_dict['bag'] == 'bag1'
    etag_hash = sha('GUEST:application/json').hexdigest()
    assert response['etag'] == '"bag1/FantasticVoyage/1;%s"' % etag_hash
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:17,代码来源:test_web_tiddler.py


示例20: test_get_tiddler_etag_bag

def test_get_tiddler_etag_bag():
    http = httplib2.Http()
    response, content = http.request("http://our_test_domain:8001/bags/bag28/tiddlers/tiddler8.json", method="GET")

    etag_hash = sha("GUEST:application/json").hexdigest()
    assert response["status"] == "200"
    assert response["etag"] == '"bag28/tiddler8/1;%s"' % etag_hash
    tiddler_info = simplejson.loads(content)
    assert tiddler_info["bag"] == "bag28"
开发者ID:jdlrobson,项目名称:tiddlyweb,代码行数:9,代码来源:test_web_tiddler.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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