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


Python util.sha函数代码示例

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


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


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