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

Python web.determine_host函数代码示例

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

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



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

示例1: safe_mode

def safe_mode(environ, start_response):
    """
    Serve up a space in safe mode. Safe mode means that
    non-required plugins are turned off and plugins that
    duplicate those in the core bags (system and tiddlyspace)
    are deleted from the store of the space in question.
    """

    http_host, _ = determine_host(environ)
    space_name = determine_space(environ, http_host)
    recipe_name = determine_space_recipe(environ, space_name)
    if recipe_name != '%s_private' % space_name:
        raise HTTP403('membership required for safe mode')

    if environ['REQUEST_METHOD'] == 'GET':
        return _send_safe_mode(environ, start_response)

    store = environ['tiddlyweb.store']

    # Get the list of core plugins
    core_plugin_tiddler_titles = _get_core_plugins(store)

    # Delete those plugins in the space's recipes which
    # duplicate the core plugins
    recipe = _delete_duplicates(environ, core_plugin_tiddler_titles,
            recipe_name, space_name)

    # Process the recipe. For those tiddlers which do not have a bag
    # in CORE_RECIPE, remove the systemConfig tag.
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:34,代码来源:safemode.py


示例2: _status_gather_data

def _status_gather_data(environ):
    """
    Monkey patch twp.status to add additional information
    specific to TiddlySpace.
    """
    data = original_gather_data(environ)
    data['server_host'] = environ['tiddlyweb.config']['server_host']
    data['tiddlyspace_version'] = environ['tiddlyweb.config'][
            'tiddlyspace.version']

    # gather space data
    http_host, host_url = determine_host(environ)
    if http_host != host_url:
        space_name = determine_space(environ, http_host)
        try:
            recipe_name = determine_space_recipe(environ, space_name)
            data['space'] = {'name': space_name, 'recipe': recipe_name}
        except HTTP404:
            pass

    # ensure user is known
    usersign = environ['tiddlyweb.usersign']['name']
    store = environ['tiddlyweb.store']
    try:
        store.get(User(usersign))
    except NoUserError:
        data['username'] = 'GUEST'
        if usersign != 'GUEST':
            data['identity'] = usersign
    return data
开发者ID:FND,项目名称:tiddlyspace,代码行数:30,代码来源:fixups.py


示例3: _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


示例4: _same_space_required

def _same_space_required(environ, space_name):
    """
    Raise 403 unless the current space (http_host) is the same as the
    target space.
    """
    current_space = determine_space(environ, determine_host(environ)[0])
    if current_space != space_name:
        raise HTTP403('space membership changes only allowed from space')
开发者ID:FND,项目名称:tiddlyspace,代码行数:8,代码来源:spaces.py


示例5: __call__

 def __call__(self, environ, start_response):
     http_host, host_url = determine_host(environ)
     if http_host == host_url:
         space_name = DEFAULT_SPACE_NAME
     else:
         space_name = determine_space(environ, http_host)
     update_space_settings(environ, space_name)
     return self.application(environ, start_response)
开发者ID:bengillies,项目名称:tiddlyspace,代码行数:8,代码来源:serversettings.py


示例6: get_nonce_components

def get_nonce_components(environ):
    """
    return username, spacename, timestamp (from cookie) and secret
    """
    username = environ['tiddlyweb.usersign']['name']
    http_host = determine_host(environ)[0]
    spacename = determine_space(environ, http_host) or ''
    secret = environ['tiddlyweb.config']['secret']
    return (username, spacename, secret)
开发者ID:EnoX1,项目名称:tiddlyspace,代码行数:9,代码来源:csrf.py


示例7: home

def home(environ, start_response):
    """
    handles requests at /, serving either the front page or a space (public or
    private) based on whether a subdomain is used.

    relies on tiddlywebplugins.virtualhosting
    """
    http_host, host_url = determine_host(environ)
    if http_host == host_url:
        http_host = 'frontpage.' + http_host
    return serve_space(environ, start_response, http_host)
开发者ID:colmjude,项目名称:tiddlyspace,代码行数:11,代码来源:handler.py


示例8: list_tiddlers

 def list_tiddlers(self, tiddlers):
     """
     Override tiddlers.link so the location in noscript is to
     /tiddlers.
     """
     http_host, _ = determine_host(self.environ) 
     space_name = determine_space(self.environ, http_host)
     recipe_name = determine_space_recipe(self.environ, space_name)
     if '/recipes/%s' % recipe_name in tiddlers.link:
         tiddlers.link = '/tiddlers'
     return WikiSerialization.list_tiddlers(self, tiddlers)
开发者ID:pads,项目名称:tiddlyspace,代码行数:11,代码来源:betaserialization.py


示例9: host_meta

def host_meta(environ, start_response):
    """
    Send the host_meta information, so webfinger info can be found.
    """
    http_host, host_url = determine_host(environ)
    if http_host != host_url:
        # Or should it be a 302?
        raise HTTP404('No host-meta at this host: %s' % http_host)

    start_response('200 OK', [
        ('Content-Type', 'application/xrd+xml')])

    return send_template(environ, 'hostmeta.xml', {'host': http_host})
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:13,代码来源:profiles.py


示例10: host_meta

def host_meta(environ, start_response):
    """
    Send the host_meta information, so webfinger info can be found.
    """
    http_host, host_url = determine_host(environ)
    if http_host != host_url:
        # Or should it be a 302?
        raise HTTP404('No host-meta at this host: %s' % http_host)

    start_response('200 OK', [
        ('Content-Type', 'application/xrd+xml')])

    return [HOST_META_TEMPLATE % {'host': http_host, 'server_host':
        server_base_url(environ)}]
开发者ID:blaine,项目名称:tiddlyspace,代码行数:14,代码来源:profiles.py


示例11: send_template

def send_template(environ, template_name, template_data=None):
    """
    Set some defaults for a template and send the output.
    """
    if template_data == None:
        template_data = {}
    template = get_template(environ, template_name)

    store = environ['tiddlyweb.store']

    linked_resources = {
            'HtmlCss': ['/bags/common/tiddlers/profile.css'],
            'HtmlJavascript': []}

    # Load CSS and JavaScript overrides.
    current_space = determine_space(environ, determine_host(environ)[0])
    if current_space:
        recipe_name = determine_space_recipe(environ, current_space)
        try:
            recipe = store.get(Recipe(recipe_name))
            for title in linked_resources:
                try:
                    tiddler = Tiddler(title)
                    bag = control.determine_bag_from_recipe(recipe,
                            tiddler, environ)
                    tiddler.bag = bag.name
                    try:
                        tiddler = store.get(tiddler)
                        if 'Javascript' in title:
                            urls = tiddler.text.strip().rstrip().split('\n')
                            linked_resources[title] = urls
                        else:
                            url = '/bags/%s/tiddlers/%s' % (encode_name(
                                tiddler.bag), title)
                            linked_resources[title] = [url]
                    except StoreError:
                        continue
                except StoreError:
                    pass
        except StoreError:
            pass

    template_defaults = {
            'original_server_host': original_server_host_url(environ),
            'css': linked_resources['HtmlCss'],
            'js': linked_resources['HtmlJavascript'],
            'server_host': server_base_url(environ),
            }
    template_defaults.update(template_data)
    return template.generate(template_defaults)
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:50,代码来源:template.py


示例12: _setup_friendly_environ

def _setup_friendly_environ(environ):
    """
    Manipulate the environ so that we appear to be in the context of the
    recipe appropriate for this current space and the current membership
    status. Return space_name to caller.
    """
    http_host, host_url = determine_host(environ)
    if http_host == host_url:
        space_name = "frontpage"
    else:
        space_name = determine_space(environ, http_host)

    recipe_name = determine_space_recipe(environ, space_name)
    environ['wsgiorg.routing_args'][1]['recipe_name'] = recipe_name.encode(
        'UTF-8')
开发者ID:colmjude,项目名称:tiddlyspace,代码行数:15,代码来源:handler.py


示例13: friendly_uri

def friendly_uri(environ, start_response):
    """
    Transform a not alread mapped request at the root of a space
    into a request for a tiddler in the public or private recipe
    of the current space.
    """
    http_host, host_url = determine_host(environ)
    if http_host == host_url:
        raise HTTP404('No resource found')
    else:
        space_name = determine_space(environ, http_host)
        recipe_name = determine_space_recipe(environ, space_name)
        # tiddler_name already in uri
        environ['wsgiorg.routing_args'][1]['recipe_name'] = recipe_name.encode(
            'UTF-8')
        return get_tiddler(environ, start_response)
开发者ID:EnoX1,项目名称:tiddlyspace,代码行数:16,代码来源:handler.py


示例14: profile

def profile(environ, start_response):
    """
    Choose between an atom or html profile.
    """
    http_host, host_url = determine_host(environ)
    if http_host != host_url:
        # Or should it be a 302?
        raise HTTP404('No profiles at this host: %s' % http_host)

    _, mime_type = get_serialize_type(environ)
    if 'atom' in mime_type:
        return atom_profile(environ, start_response)
    elif 'html' in mime_type:
        return html_profile(environ, start_response)
    else:
        raise HTTP415('Atom and HTML only')
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:16,代码来源:profiles.py


示例15: _handle_dropping_privs

    def _handle_dropping_privs(self, environ, req_uri):
        if environ['tiddlyweb.usersign']['name'] == 'GUEST':
            return

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

        if space_name == None:
            return

        space = Space(space_name)

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

        if req_uri.startswith('/bags/'):
            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
                if container_name in ADMIN_BAGS:
                    return
            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

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

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


示例16: __call__

    def __call__(self, environ, start_response):
        req_uri = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '')
        disable_control_view = (
                environ.get('HTTP_X_CONTROLVIEW', '').lower() == 'false')
        http_host, host_url = determine_host(environ)

        if http_host != host_url:
            space_name = determine_space(environ, http_host)
            if (space_name is not None
                    and not disable_control_view
                    and (req_uri.startswith('/bags')
                        or req_uri.startswith('/search')
                        or req_uri.startswith('/recipes'))):
                response = self._handle_core_request(environ, req_uri,
                        space_name, start_response)
                if response:
                    return response

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


示例17: validate_mapspace

def validate_mapspace(tiddler, environ):
    """
    If a tiddler is put to the MAPSPACE bag clear
    out the tiddler and set fields['mapped_space']
    to the current space.

    Elsewhere in the space the mapped_space can map
    a alien domain to space.
    """
    if tiddler.bag == 'MAPSPACE':
        current_space = determine_space(environ, determine_host(environ)[0])
        recipe_name = determine_space_recipe(environ, current_space)
        if recipe_name != '%s_private' % current_space:
            raise InvalidTiddlerError('non member may not map space')

        tiddler.text = ''
        tiddler.tags = []
        tiddler.fields = {}
        tiddler.fields['mapped_space'] = current_space
    return tiddler
开发者ID:TiddlySpace,项目名称:tiddlyspace,代码行数:20,代码来源:validator.py


示例18: test_determine_host_common_port

def test_determine_host_common_port():
    server_host = {}
    config = {'server_host': server_host}
    environ = {'tiddlyweb.config': config}

    server_host.update({
            'scheme': 'http',
            'host': 'example.com',
            'port': '80',
            })

    http_host, host_url = determine_host(environ)
    assert http_host == 'example.com'
    assert host_url == 'example.com'

    environ['HTTP_HOST'] = 'something.example.com'

    http_host, host_url = determine_host(environ)
    assert http_host == 'something.example.com'
    assert host_url == 'example.com'

    server_host['port'] = '443'

    http_host, host_url = determine_host(environ)
    assert http_host == 'something.example.com'
    assert host_url == 'example.com'

    environ['HTTP_HOST'] = 'something.example.com:8080'
    server_host['port'] = '8080'

    http_host, host_url = determine_host(environ)
    assert http_host == 'something.example.com:8080'
    assert host_url == 'example.com:8080'
        
    environ['HTTP_HOST'] = 'something.example.com:8080'
    server_host['port'] = '80'

    http_host, host_url = determine_host(environ)
    assert http_host == 'something.example.com:8080'
    assert host_url == 'example.com'

    environ['HTTP_HOST'] = 'something.example.com:80'
    server_host['port'] = '80'

    http_host, host_url = determine_host(environ)
    assert http_host == 'something.example.com'
    assert host_url == 'example.com'
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:47,代码来源:test_web.py


示例19: webfinger

def webfinger(environ, start_response):
    """
    Display the webfinger information for a given user.
    """
    http_host, host_url = determine_host(environ)
    if http_host != host_url:
        raise HTTP404('No webfinger at this host: %s' % http_host)

    username = environ['tiddlyweb.query'].get('q', [None])[0]

    if not username:
        raise HTTP400('No account provided to webfinger query')

    if username.startswith('acct:'):
        username = username.split(':', 1)[1]
    username = username.split('@', 1)[0]

    start_response('200 OK', [
        ('Content-Type', 'application/xrd+xml')])

    return [WEBFINGER_TEMPLATE % {'username': username,
        'host': http_host, 'server_host': server_base_url(environ)}]
开发者ID:blaine,项目名称:tiddlyspace,代码行数:22,代码来源:profiles.py


示例20: home

def home(environ, start_response):
    """
    handles requests at /, serving either the front page or a space (public or
    private) based on whether a subdomain is used and whether a user is auth'd

    relies on tiddlywebplugins.virtualhosting
    """
    http_host, host_url = determine_host(environ)
    if http_host == host_url:
        usersign = environ['tiddlyweb.usersign']['name']
        try:
            store = environ['tiddlyweb.store']
            store.get(User(usersign))
        except NoUserError:
            usersign = 'GUEST'
        if usersign == 'GUEST':
            return serve_frontpage(environ, start_response)
        else:  # authenticated user
            scheme = environ['tiddlyweb.config']['server_host']['scheme']
            uri = '%s://%s.%s' % (scheme, usersign, host_url)
            raise HTTP302(uri)
    else:  # subdomain
        return serve_space(environ, start_response, http_host)
开发者ID:EnoX1,项目名称:tiddlyspace,代码行数:23,代码来源:handler.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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