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


Python space.Space类代码示例

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


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

示例1: _valid_bag

    def _valid_bag(self, environ, space, container_name):
        """
        Return True if the requested entity is part of the current
        space's recipe or an ADMIN BAG. Otherwise return False
        indicating that privileges will be dropped.
        """
        store = environ['tiddlyweb.store']
        recipe_name = determine_space_recipe(environ, space.name)
        space_recipe = store.get(Recipe(recipe_name))
        template = recipe_template(environ)
        recipe_bags = [bag for bag, _ in space_recipe.get_recipe(template)]
        recipe_bags.extend(space.extra_bags())
        if environ['REQUEST_METHOD'] == 'GET':
            if container_name in recipe_bags:
                return True
            if container_name in ADMIN_BAGS:
                return True
        else:
            base_bags = space.list_bags()
            # add bags in the recipe which may have been added
            # by the recipe mgt. That is: bags which are not
            # included and not core.
            acceptable_bags = [bag for bag in recipe_bags if not (
                Space.bag_is_public(bag) or Space.bag_is_private(bag)
                or Space.bag_is_associate(bag))]
            acceptable_bags.extend(base_bags)
            acceptable_bags.extend(ADMIN_BAGS)
            if container_name in acceptable_bags:
                return True

        return False
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:31,代码来源:controlview.py

示例2: list_spaces

def list_spaces(environ, start_response):
    """
    List all the spaces on the service, as a JSON list.

    If a "mine" parameter is present, just get the current
    user's spaces.
    """
    store = environ['tiddlyweb.store']
    mine = environ['tiddlyweb.query'].get('mine', [None])[0]
    current_user = environ['tiddlyweb.usersign']['name']
    if mine:
        spaces = []
        try:
            recipe_names = store.storage.cached_storage.user_spaces(
                    current_user)
        except AttributeError:
            recipe_names = store.storage.user_spaces(current_user)
        for recipe in recipe_names:
            spaces.append(Space.name_from_recipe(recipe))
    else:
        spaces = [Space.name_from_recipe(recipe.name) for
                recipe in store.list_recipes() if
                Space.recipe_is_public(recipe.name)]
    start_response('200 OK', [
        ('Cache-Control', 'no-cache'),
        ('Content-Type', 'application/json; charset=UTF-8')])
    return simplejson.dumps([{'name': space, 'uri': space_uri(environ, space)}
        for space in sorted(spaces)])
开发者ID:FND,项目名称:tiddlyspace,代码行数:28,代码来源:spaces.py

示例3: update_space_settings

def update_space_settings(environ, name):
    """
    Read a tiddler named by SPACE_SERVER_SETTINGS in the current
    space's public bag. Parse each line as a key:value pair which
    is then injected tiddlyweb.query. The goal here is to allow
    a space member to force incoming requests to use specific
    settings, such as alpha or externalized.
    """
    store = environ['tiddlyweb.store']
    space = Space(name)
    bag_name = space.public_bag()
    tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name)
    data_text = ''
    try:
        tiddler = store.get(tiddler)
        data_text = tiddler.text
    except StoreError:
        pass

    for line in data_text.split('\n'):
        try:
            key, value = line.split(':', 1)
            key = key.rstrip().lstrip()
            value = value.rstrip().lstrip()
            try:
                environ['tiddlyweb.query'][key].append(value)
            except KeyError:
                environ['tiddlyweb.query'][key] = [value]
        except ValueError:
            pass
开发者ID:blaine,项目名称:tiddlyspace,代码行数:30,代码来源:handler.py

示例4: web_tiddler_url

def web_tiddler_url(environ, tiddler, container='bags', full=True):
    """
    Override default tiddler_url to be space+host aware.

    If the bag or recipe of the tiddler is of a space, switch to
    that space's host for the duration of uri creation.

    Do this all the time, so that we get the right URIs even
    when working around ControlView.

    If the bag does not fit in a space, then make is URI be at
    the server_host domain. If/when auxbags are made to work this
    will need to be reviewed.
    """
    if '_canonical_uri' in tiddler.fields:
        return tiddler.fields['_canonical_uri']

    saved_host = environ.get('HTTP_HOST', '')
    try:
        if container == 'recipes':
            space_name = Space.name_from_recipe(tiddler.recipe)
        else:
            space_name = Space.name_from_bag(tiddler.bag)
        space_name = space_name + '.'
    except ValueError, exc:
        space_name = ''
开发者ID:bengillies,项目名称:tiddlyspace,代码行数:26,代码来源:fixups.py

示例5: _handle_dropping_privs

    def _handle_dropping_privs(self, environ, req_uri):
        """
        Determin if this request is to be considered "in space" or
        not. If it is not and the current user is not GUEST we need
        to pretend that the current user is GUEST, effectively
        "dropping" privileges.
        """
        if environ['tiddlyweb.usersign']['name'] == 'GUEST':
            return

        http_host, _ = determine_host(environ)
        space_name = determine_space(environ, http_host)

        if space_name is None:
            return

        space = Space(space_name)

        container_name = req_uri.split('/')[2]

        if (req_uri.startswith('/bags/')
                and self._valid_bag(environ, space, container_name)):
            return

        if (req_uri.startswith('/recipes/')
                and container_name in space.list_recipes()):
            return

        self._drop_privs(environ)
        return
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:30,代码来源:controlview.py

示例6: determine_space_recipe

def determine_space_recipe(environ, space_name):
    """
    Given a space name, check if the current user is a member of that
    named space. If so, use the private recipe.
    """
    store = environ['tiddlyweb.store']
    usersign = environ['tiddlyweb.usersign']
    try:
        space = Space(space_name)
        recipe = Recipe(space.public_recipe())
        recipe = store.get(recipe)
    except (ValueError, StoreError), exc:
        raise HTTP404('Space for %s does not exist: %s' % (space_name, exc))
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:13,代码来源:web.py

示例7: _validate_subscription

def _validate_subscription(environ, name, recipe):
    """
    Determine if this space can be subscribed to.

    We know that the space exists, what we want to determine here is if
    it has been blacklisted or already been subscribed.
    """
    space = Space(name)
    if name in environ['tiddlyweb.config'].get('blacklisted_spaces', []):
        raise HTTP409('Subscription not allowed to space: %s' % name)
    elif [space.public_bag(), ''] in recipe:
        raise HTTP409('Space already subscribed: %s' % name)
    return space
开发者ID:FND,项目名称:tiddlyspace,代码行数:13,代码来源:spaces.py

示例8: make_space

def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    info_tiddler = Tiddler('SiteInfo', space.public_bag())
    info_tiddler.text = 'Space %s' % space_name
    store.put(info_tiddler)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
开发者ID:ramanathanr,项目名称:tiddlyspace,代码行数:26,代码来源:spaces.py

示例9: update_space_settings

def update_space_settings(environ, name):
    """
    Read a tiddler named by SPACE_SERVER_SETTINGS in the current
    space's public bag. Parse each line as a key:value pair which
    is then injected tiddlyweb.query. The goal here is to allow
    a space member to force incoming requests to use specific
    settings, such as alpha or externalized.
    """
    store = environ['tiddlyweb.store']
    space = Space(name)
    bag_name = space.public_bag()
    tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name)
    data_text = ''
    try:
        tiddler = store.get(tiddler)
        data_text = tiddler.text
    except StoreError:
        return _figure_default_index(environ, bag_name, space), False

    query_strings = []
    index = ''
    lazy = False
    for line in data_text.split('\n'):
        try:
            key, value = line.split(':', 1)
            key = key.rstrip().lstrip()
            value = value.rstrip().lstrip()
            if key == 'index':
                index = value
            elif key == 'lazy':
                if value.lower() == 'true':
                    lazy = True
            else:
                query_strings.append('%s=%s' % (key, value))
        except ValueError:
            pass

    index = _figure_default_index(environ, bag_name, space, index)

    query_string = ';'.join(query_strings)

    filters, leftovers = parse_for_filters(query_string, environ)
    environ['tiddlyweb.filters'].extend(filters)
    query_data = parse_qs(leftovers, keep_blank_values=True)
    environ['tiddlyweb.query'].update(dict(
        [(key, [value for value in values])
            for key, values in query_data.items()]))

    return index, lazy
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:49,代码来源:handler.py

示例10: confirm_space

def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = environ['wsgiorg.routing_args'][1]['space_name']
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except NoRecipeError:
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
开发者ID:FND,项目名称:tiddlyspace,代码行数:15,代码来源:spaces.py

示例11: confirm_space

def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = get_route_value(environ, 'space_name')
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except (NoRecipeError, ValueError):
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:15,代码来源:spaces.py

示例12: _do_unsubscriptions

def _do_unsubscriptions(space_name, unsubscriptions, public_recipe_list,
        private_recipe_list, store):
    """
    Remove unsubscriptions from the space represented by
    public_recipe_list and private_recipe_list.
    """
    for space in unsubscriptions:
        if space == space_name:
            raise HTTP409('Attempt to unsubscribe self')
        try:
            unsubscribed_space = Space(space)
            bag = unsubscribed_space.public_bag()
            public_recipe_list.remove([bag, ""])
            private_recipe_list.remove([bag, ""])
        except ValueError, exc:
            raise HTTP409('Invalid content for unsubscription: %s' % exc)
开发者ID:FND,项目名称:tiddlyspace,代码行数:16,代码来源:spaces.py

示例13: get_space_tiddlers

def get_space_tiddlers(environ, start_response):
    """
    Get the tiddlers that make up the current space in
    whatever the reqeusted representation is. Choose recipe
    based on membership status.
    """
    _setup_friendly_environ(environ)
    _extra_query_update(environ)

    ext = environ.get('tiddlyweb.extension')
    types = environ['tiddlyweb.config']['extension_types']

    # If not a wiki, limit the tiddlers
    if 'text/x-tiddlywiki' not in environ['tiddlyweb.type']:
        # If filters not set, sort by -modified.
        if not environ['tiddlyweb.filters']:
            environ['tiddlyweb.filters'] = parse_for_filters(
                    'sort=-modified', environ)[0]

        # Filter out core bags.
        core_bag_filters = []
        for bag in Space.core_bags():
            core_bag_filters.append('select=bag:!%s' % bag)
        core_bag_filters = parse_for_filters(';'.join(core_bag_filters),
                environ)[0]
        environ['tiddlyweb.filters'].extend(core_bag_filters)

    if ext and ext not in types:
        environ['wsgiorg.routing_args'][1]['recipe_name'] += '.%s' % ext
    return get_tiddlers(environ, start_response)
开发者ID:colmjude,项目名称:tiddlyspace,代码行数:30,代码来源:handler.py

示例14: _make_space

def _make_space(environ, space_name):
    """
    The details of creating the bags and recipes that make up a space.
    """
    store = environ['tiddlyweb.store']
    member = environ['tiddlyweb.usersign']['name']

    # XXX stub out the clumsy way for now
    # can make this much more declarative

    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
开发者ID:carnotip,项目名称:tiddlyspace,代码行数:28,代码来源:spaces.py

示例15: web_tiddler_url

def web_tiddler_url(environ, tiddler, container='bags', full=True,
        friendly=False):
    """
    Override default tiddler_url to be space+host aware.

    If the bag or recipe of the tiddler is of a space, switch to
    that space's host for the duration of uri creation.

    Do this all the time, so that we get the right URIs even
    when working around ControlView.

    If the bag does not fit in a space, then make is URI be at
    the server_host domain. If/when auxbags are made to work this
    will need to be reviewed.
    """
    saved_host = environ.get('HTTP_HOST', '')
    try:
        if container == 'recipes':
            space_name = Space.name_from_recipe(tiddler.recipe)
        else:
            space_name = Space.name_from_bag(tiddler.bag)
        space_name = space_name + '.'
    except ValueError:
        space_name = ''

    host = environ['tiddlyweb.config']['server_host']['host']
    port = environ['tiddlyweb.config']['server_host']['port']
    if port is '443' or port is '80':
        port = ''
    else:
        port = ':%s' % port
    environ['HTTP_HOST'] = '%s%s%s' % (space_name.encode('utf-8'),
        host, port)

    if friendly and space_name:
        url = '%s/%s' % (tiddlyweb.web.util.server_base_url(environ),
                tiddlyweb.web.util.encode_name(tiddler.title))
    else:
        url = original_tiddler_url(environ, tiddler, container, full)
    if saved_host:
        environ['HTTP_HOST'] = saved_host
    elif 'HTTP_HOST' in environ:
        del environ['HTTP_HOST']
    return url
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:44,代码来源:fixups.py


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