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


Python util.get_serialize_type函数代码示例

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


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

示例1: 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

示例2: put

def put(environ, start_response):
    """
    Put a bag to the server, meaning the description and
    policy of the bag, if policy allows.
    """
    bag_name = _determine_bag_name(environ)
    bag_name = web.handle_extension(environ, bag_name)

    bag = Bag(bag_name)
    store = environ["tiddlyweb.store"]
    length = environ["CONTENT_LENGTH"]

    usersign = environ["tiddlyweb.usersign"]

    try:
        bag = store.get(bag)
        bag.policy.allows(usersign, "manage")
    except NoBagError:
        create_policy_check(environ, "bag", usersign)

    try:
        serialize_type = web.get_serialize_type(environ)[0]
        serializer = Serializer(serialize_type, environ)
        serializer.object = bag
        content = environ["wsgi.input"].read(int(length))
        serializer.from_string(content.decode("utf-8"))

        bag.policy.owner = usersign["name"]

        _validate_bag(environ, bag)
        store.put(bag)
    except BagFormatError, exc:
        raise HTTP400("unable to put bag: %s" % exc)
开发者ID:jdlrobson,项目名称:tiddlyweb,代码行数:33,代码来源:bag.py

示例3: get

def get(environ, start_response):
    """
    Get a representation in some serialization of
    a bag (the bag itself not the tiddlers within).
    """
    bag_name = _determine_bag_name(environ)
    bag_name = web.handle_extension(environ, bag_name)
    bag = _get_bag(environ, bag_name, True)

    bag.policy.allows(environ['tiddlyweb.usersign'], 'manage')

    try:
        serialize_type, mime_type = web.get_serialize_type(environ)
        serializer = Serializer(serialize_type, environ)
        serializer.object = bag

        content = serializer.to_string()
    except NoSerializationError:
        raise HTTP415('Content type not supported: %s' % mime_type)

    start_response("200 Ok",
            [('Content-Type', mime_type),
                ('Vary', 'Accept')])

    return [content]
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:25,代码来源:bag.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: list

def list(environ, start_response):
    """
    List all the bags that the current user can read.
    """
    store = environ["tiddlyweb.store"]
    bags = store.list_bags()
    kept_bags = []
    for bag in bags:
        try:
            bag.skinny = True
            bag = store.get(bag)
            bag.policy.allows(environ["tiddlyweb.usersign"], "read")
            kept_bags.append(bag)
        except (UserRequiredError, ForbiddenError):
            pass

    try:
        serialize_type, mime_type = web.get_serialize_type(environ)
        serializer = Serializer(serialize_type, environ)

        content = serializer.list_bags(kept_bags)

    except NoSerializationError:
        raise HTTP415("Content type not supported: %s" % mime_type)

    start_response("200 OK", [("Content-Type", mime_type)])

    return [content]
开发者ID:ingydotnet,项目名称:tiddlyweb,代码行数:28,代码来源:bag.py

示例6: send_entity

def send_entity(environ, start_response, entity):
    """
    Send a :py:class:`bag <tiddlyweb.model.bag.Bag>` or :py:class:`recipe
    <tiddlyweb.model.recipe.Recipe>` out over HTTP, first
    :py:class:`serializing <tiddlyweb.serializer.Serializer>` to
    the correct type. If an incoming ``Etag`` validates, raise a
    ``304`` response.
    """
    etag_string = entity_etag(environ, entity)
    check_incoming_etag(environ, etag_string)

    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)

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

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

示例7: send_tiddlers

def send_tiddlers(environ, start_response, bag):
    """
    Output the tiddlers contained in the provided
    bag in a Negotiated representation. Often, but
    not always, a wiki.
    """
    last_modified = None
    etag = None
    bags_tiddlers = bag.list_tiddlers()
    download = environ['tiddlyweb.query'].get('download', [None])[0]

    if bags_tiddlers:
        last_modified, etag = _validate_tiddler_list(environ, bags_tiddlers)
    else:
        raise HTTP404('No tiddlers in container')

    serialize_type, mime_type = get_serialize_type(environ)
    serializer = Serializer(serialize_type, environ)

    content_header = ('Content-Type', mime_type)
    cache_header = ('Cache-Control', 'no-cache')
    response = [content_header, cache_header]

    if serialize_type == 'wiki':
        if download:
            response.append(('Content-Disposition',
                'attachment; filename="%s"' % download))
    if last_modified:
        response.append(last_modified)
    if etag:
        response.append(etag)

    output = serializer.list_tiddlers(bag)
    start_response("200 OK", response)
    return [output]
开发者ID:angeluseve,项目名称:tiddlyweb,代码行数:35,代码来源:sendtiddlers.py

示例8: _generate_response

def _generate_response(content, environ, start_response):
    serialize_type, mime_type = web.get_serialize_type(environ)  # XXX: not suitable here!?
    cache_header = ("Cache-Control", "no-cache")  # ensure accessing latest HEAD revision
    content_header = ("Content-Type", mime_type)  # XXX: should be determined by diff format
    response = [cache_header, content_header]
    start_response("200 OK", response)
    return [content]
开发者ID:cdent,项目名称:tiddlyweb-plugins,代码行数:7,代码来源:differ.py

示例9: _get_tiddler_content

def _get_tiddler_content(environ, tiddler):
    """
    Extract the content of the tiddler, either straight up if
    the content is not considered text, or serialized if it is.
    """
    config = environ['tiddlyweb.config']
    default_serializer = config['default_serializer']
    default_serialize_type = config['serializers'][default_serializer][0]
    serialize_type, mime_type = get_serialize_type(environ)
    extension = environ.get('tiddlyweb.extension')
    serialized = False

    # If this is a tiddler with a CANONICAL_URI_FIELD redirect
    # there unless we are requesting a json form
    if (CANONICAL_URI_FIELD in tiddler.fields
            and not CANONICAL_URI_PASS_TYPE in mime_type):
        raise HTTP302(tiddler.fields[CANONICAL_URI_FIELD])

    if not renderable(tiddler, environ):
        if (serialize_type == default_serialize_type or
                mime_type.startswith(tiddler.type) or
                extension == 'html'):
            mime_type = tiddler.type
            content = tiddler.text
            return content, mime_type, serialized

    serializer = Serializer(serialize_type, environ)
    serializer.object = tiddler

    try:
        content = serializer.to_string()
        serialized = True
    except (TiddlerFormatError, NoSerializationError) as exc:
        raise HTTP415(exc)
    return content, mime_type, serialized
开发者ID:psd,项目名称:tiddlyweb,代码行数:35,代码来源:tiddler.py

示例10: _process_request_body

def _process_request_body(environ, tiddler):
    """
    Read request body to set tiddler content.

    If a serializer exists for the content type, use it,
    otherwise treat the content as binary or pseudo-binary
    tiddler.
    """
    length, content_type = content_length_and_type(environ)
    content = read_request_body(environ, length)

    try:
        try:
            serialize_type = get_serialize_type(environ)[0]
            serializer = Serializer(serialize_type, environ)
            # Short circuit de-serialization attempt to avoid
            # decoding content multiple times.
            if hasattr(serializer.serialization, 'as_tiddler'):
                serializer.object = tiddler
                try:
                    serializer.from_string(content.decode('utf-8'))
                except TiddlerFormatError as exc:
                    raise HTTP400('unable to put tiddler: %s' % exc)
            else:
                raise NoSerializationError()
        except NoSerializationError:
            tiddler.type = content_type
            if pseudo_binary(tiddler.type):
                tiddler.text = content.decode('utf-8')
            else:
                tiddler.text = content
    except UnicodeDecodeError as exc:
        raise HTTP400('unable to decode tiddler, utf-8 expected: %s' % exc)
开发者ID:24king,项目名称:tiddlyweb,代码行数:33,代码来源:tiddler.py

示例11: _get_tiddler_content

def _get_tiddler_content(environ, tiddler):
    """
    Extract the content of the tiddler, either straight up if
    the content is not considered text, or serialized if it is
    """
    config = environ['tiddlyweb.config']
    default_serializer = config['default_serializer']
    default_serialize_type = config['serializers'][default_serializer][0]
    serialize_type, mime_type = web.get_serialize_type(environ)
    extension = environ.get('tiddlyweb.extension')

    if not renderable(tiddler, environ):
        if (serialize_type == default_serialize_type or
                mime_type.startswith(tiddler.type) or
                extension == 'html'):
            mime_type = tiddler.type
            content = tiddler.text
            return content, mime_type

    serializer = Serializer(serialize_type, environ)
    serializer.object = tiddler

    try:
        content = serializer.to_string()
    except (TiddlerFormatError, NoSerializationError), exc:
        raise HTTP415(exc)
开发者ID:JazzDeben,项目名称:tiddlyweb-xmobile,代码行数:26,代码来源:tiddler.py

示例12: put

def put(environ, start_response):
    """
    Put a bag to the server, meaning the description and
    policy of the bag, if policy allows.
    """
    bag_name = web.get_route_value(environ, 'bag_name')
    bag_name = web.handle_extension(environ, bag_name)

    bag = Bag(bag_name)
    store = environ['tiddlyweb.store']
    length, _ = web.content_length_and_type(environ)

    usersign = environ['tiddlyweb.usersign']

    try:
        bag = store.get(bag)
        bag.policy.allows(usersign, 'manage')
    except NoBagError:
        create_policy_check(environ, 'bag', usersign)

    try:
        serialize_type = web.get_serialize_type(environ)[0]
        serializer = Serializer(serialize_type, environ)
        serializer.object = bag
        content = web.read_request_body(environ, length)
        serializer.from_string(content.decode('utf-8'))

        bag.policy.owner = usersign['name']

        _validate_bag(environ, bag)
        store.put(bag)
    except BagFormatError, exc:
        raise HTTP400('unable to put bag: %s' % exc)
开发者ID:tup,项目名称:tiddlyweb,代码行数:33,代码来源:bag.py

示例13: send_entity

def send_entity(environ, start_response, entity):
    """
    Send a bag or recipe out HTTP, first serializing to
    the correct type. If the incoming etag matches, raise
    304.
    """
    etag_string = entity_etag(environ, entity)
    incoming_etag = environ.get('HTTP_IF_NONE_MATCH', None)
    if incoming_etag:
        if incoming_etag == etag_string:
            raise HTTP304(incoming_etag)

    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)

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

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

示例14: list_bags

def list_bags(environ, start_response):
    """
    List all the bags that the current user can read.
    """
    store = environ["tiddlyweb.store"]
    serialize_type, mime_type = web.get_serialize_type(environ)
    serializer = Serializer(serialize_type, environ)
    return list_entities(environ, start_response, mime_type, store.list_bags, serializer.list_bags)
开发者ID:jdlrobson,项目名称:tiddlyweb,代码行数:8,代码来源:bag.py

示例15: list_recipes

def list_recipes(environ, start_response):
    """
    Get a list of all recipes the current user can read.
    """
    store = environ['tiddlyweb.store']
    serialize_type, mime_type = web.get_serialize_type(environ)
    serializer = Serializer(serialize_type, environ)
    return list_entities(environ, start_response, mime_type, store.list_recipes,
            serializer.list_recipes)
开发者ID:chancejiang,项目名称:tiddlyweb,代码行数:9,代码来源:recipe.py


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