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


Python urls.url_parse方法代码示例

本文整理汇总了Python中werkzeug.urls.url_parse方法的典型用法代码示例。如果您正苦于以下问题:Python urls.url_parse方法的具体用法?Python urls.url_parse怎么用?Python urls.url_parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.urls的用法示例。


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

示例1: match_url

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def match_url(url, method=None):
    appctx = _app_ctx_stack.top
    reqctx = _request_ctx_stack.top
    if appctx is None:
        raise RuntimeError('Attempted to match a URL without the '
                           'application context being pushed. This has to be '
                           'executed when application context is available.')

    if reqctx is not None:
        url_adapter = reqctx.url_adapter
    else:
        url_adapter = appctx.url_adapter
        if url_adapter is None:
            raise RuntimeError('Application was not able to create a URL '
                               'adapter for request independent URL matching. '
                               'You might be able to fix this by setting '
                               'the SERVER_NAME config variable.')
    parsed_url = url_parse(url)
    if parsed_url.netloc is not '' and \
                    parsed_url.netloc != url_adapter.server_name:
        raise NotFound()
    return url_adapter.match(parsed_url.path, method) 
开发者ID:miguelgrinberg,项目名称:api-pycon2014,代码行数:24,代码来源:helpers.py

示例2: login_page

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def login_page():
    if current_user.is_authenticated:
        return redirect(url_for('status_page'))
    loginform = LoginForm()
    if loginform.validate_on_submit():
        user = User('admin')
        password = loginform.password.data
        if not user.check_password(password):
            return abort(401)
        
        login_user(user, remember=loginform.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('status_page')

        return redirect(next_page)
        
    return render_template('login.html', title='Sign In', form=loginform) 
开发者ID:Stefal,项目名称:rtkbase,代码行数:20,代码来源:server.py

示例3: test_to_url

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def test_to_url(self, app):
        kwargs = {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': 2,
            'facets': True,
        }
        search_query = search.search_for(FakeSearch, **kwargs)
        with app.test_request_context('/an_url'):
            url = search_query.to_url()
        parsed_url = url_parse(url)
        qs = url_decode(parsed_url.query)

        assert parsed_url.path == '/an_url'
        assert_json_equal(multi_to_dict(qs), {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': '2',
        }) 
开发者ID:opendatateam,项目名称:udata,代码行数:21,代码来源:test_query.py

示例4: test_to_url_with_override

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def test_to_url_with_override(self, app):
        kwargs = {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': 2,
        }
        search_query = search.search_for(FakeSearch, **kwargs)
        with app.test_request_context('/an_url'):
            url = search_query.to_url(tag='tag3', other='value')
        parsed_url = url_parse(url)
        qs = url_decode(parsed_url.query)

        assert parsed_url.path == '/an_url'
        assert_json_equal(multi_to_dict(qs), {
            'q': 'test',
            'tag': ['tag1', 'tag2', 'tag3'],
            'other': 'value',
        }) 
开发者ID:opendatateam,项目名称:udata,代码行数:20,代码来源:test_query.py

示例5: test_to_url_with_override_and_replace

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def test_to_url_with_override_and_replace(self, app):
        kwargs = {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': 2,
        }
        search_query = search.search_for(FakeSearch, **kwargs)
        with app.test_request_context('/an_url'):
            url = search_query.to_url(tag='tag3', other='value', replace=True)
        parsed_url = url_parse(url)
        qs = url_decode(parsed_url.query)

        assert parsed_url.path == '/an_url'
        assert_json_equal(multi_to_dict(qs), {
            'q': 'test',
            'tag': 'tag3',
            'other': 'value',
        }) 
开发者ID:opendatateam,项目名称:udata,代码行数:20,代码来源:test_query.py

示例6: test_to_url_with_none

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def test_to_url_with_none(self, app):
        kwargs = {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': 2,
        }
        search_query = search.search_for(FakeSearch, **kwargs)
        with app.test_request_context('/an_url'):
            url = search_query.to_url(tag=None, other='value', replace=True)
        parsed_url = url_parse(url)
        qs = url_decode(parsed_url.query)

        assert parsed_url.path == '/an_url'
        assert_json_equal(multi_to_dict(qs), {
            'q': 'test',
            'other': 'value',
        }) 
开发者ID:opendatateam,项目名称:udata,代码行数:19,代码来源:test_query.py

示例7: test_to_url_with_specified_url

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def test_to_url_with_specified_url(self, app):
        kwargs = {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': 2,
        }
        search_query = search.search_for(FakeSearch, **kwargs)
        with app.test_request_context('/an_url'):
            url = search_query.to_url('/another_url')
        parsed_url = url_parse(url)
        qs = url_decode(parsed_url.query)

        assert parsed_url.path == '/another_url'
        assert_json_equal(multi_to_dict(qs), {
            'q': 'test',
            'tag': ['tag1', 'tag2'],
            'page': '2',
        }) 
开发者ID:opendatateam,项目名称:udata,代码行数:20,代码来源:test_query.py

示例8: login

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            error = 'Invalid username or password'
            return render_template('login.html', form=form, error=error)

        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('main.index')
        return redirect(next_page)

    return render_template('login.html', title='Sign In', form=form) 
开发者ID:okomarov,项目名称:dash_on_flask,代码行数:20,代码来源:webapp.py

示例9: __call__

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def __call__(self, environ, start_response):
        def start_wrapped(status, headers):
            referer = environ.get('HTTP_REFERER', '')
            parsed = urls.url_parse(referer)
            debug = parsed.query.count('debug') >= 1

            new_headers = []
            unwanted_keys = ['Last-Modified']
            if debug:
                new_headers = [('Cache-Control', 'no-cache')]
                unwanted_keys += ['Expires', 'Etag', 'Cache-Control']

            for k, v in headers:
                if k not in unwanted_keys:
                    new_headers.append((k, v))

            start_response(status, new_headers)
        return self.app(environ, start_wrapped) 
开发者ID:ocubexo,项目名称:odoo-dingtalk-connector,代码行数:20,代码来源:http.py

示例10: login

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def login():
    # 判断当前用户是否验证,如果通过的话返回首页
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = LoginForm()
    # user = None
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        # print("user", user)
        if user is None or not user.check_password(form.password.data):
            flash('无效的用户名或密码')

            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        # 此时的next_page记录的是跳转至登录页面是的地址
        next_page = request.args.get('next')
        # 如果next_page记录的地址不存在那么就返回首页
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        # 综上,登录后要么重定向至跳转前的页面,要么跳转至首页
        return redirect(next_page)
    # 一定要有返回体,原文作者未提及,否则用户未登陆时候会报错
    return render_template('login.html', title='登录', form=form) 
开发者ID:Liangchengdeye,项目名称:FlaskQuickStart,代码行数:26,代码来源:routes.py

示例11: test_url_attributes

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def test_url_attributes(self):
        rv = urls.url_parse('http://foo%3a:bar%3a@[::1]:80/123?x=y#frag')
        self.assert_strict_equal(rv.scheme, 'http')
        self.assert_strict_equal(rv.auth, 'foo%3a:bar%3a')
        self.assert_strict_equal(rv.username, u'foo:')
        self.assert_strict_equal(rv.password, u'bar:')
        self.assert_strict_equal(rv.raw_username, 'foo%3a')
        self.assert_strict_equal(rv.raw_password, 'bar%3a')
        self.assert_strict_equal(rv.host, '::1')
        self.assert_equal(rv.port, 80)
        self.assert_strict_equal(rv.path, '/123')
        self.assert_strict_equal(rv.query, 'x=y')
        self.assert_strict_equal(rv.fragment, 'frag')

        rv = urls.url_parse(u'http://\N{SNOWMAN}.com/')
        self.assert_strict_equal(rv.host, u'\N{SNOWMAN}.com')
        self.assert_strict_equal(rv.ascii_host, 'xn--n3h.com') 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:19,代码来源:urls.py

示例12: make_test_environ_builder

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs):
    """Creates a new test builder with some application defaults thrown in."""
    http_host = app.config.get('SERVER_NAME')
    app_root = app.config.get('APPLICATION_ROOT')
    if base_url is None:
        url = url_parse(path)
        base_url = 'http://%s/' % (url.netloc or http_host or 'localhost')
        if app_root:
            base_url += app_root.lstrip('/')
        if url.netloc:
            path = url.path
            if url.query:
                path += '?' + url.query
    return EnvironBuilder(path, base_url, *args, **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:16,代码来源:testing.py

示例13: make_environ

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def make_environ(self):
        request_url = url_parse(self.path)

        def shutdown_server():
            self.server.shutdown_signal = True

        url_scheme = self.server.ssl_context is None and 'http' or 'https'
        path_info = url_unquote(request_url.path)

        environ = {
            'wsgi.version':         (1, 0),
            'wsgi.url_scheme':      url_scheme,
            'wsgi.input':           self.rfile,
            'wsgi.errors':          sys.stderr,
            'wsgi.multithread':     self.server.multithread,
            'wsgi.multiprocess':    self.server.multiprocess,
            'wsgi.run_once':        False,
            'werkzeug.server.shutdown': shutdown_server,
            'SERVER_SOFTWARE':      self.server_version,
            'REQUEST_METHOD':       self.command,
            'SCRIPT_NAME':          '',
            'PATH_INFO':            wsgi_encoding_dance(path_info),
            'QUERY_STRING':         wsgi_encoding_dance(request_url.query),
            'CONTENT_TYPE':         self.headers.get('Content-Type', ''),
            'CONTENT_LENGTH':       self.headers.get('Content-Length', ''),
            'REMOTE_ADDR':          self.address_string(),
            'REMOTE_PORT':          self.port_integer(),
            'SERVER_NAME':          self.server.server_address[0],
            'SERVER_PORT':          str(self.server.server_address[1]),
            'SERVER_PROTOCOL':      self.request_version
        }

        for key, value in self.headers.items():
            key = 'HTTP_' + key.upper().replace('-', '_')
            if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'):
                environ[key] = value

        if request_url.scheme and request_url.netloc:
            environ['HTTP_HOST'] = request_url.netloc

        return environ 
开发者ID:jpush,项目名称:jbox,代码行数:43,代码来源:serving.py

示例14: make_environ

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def make_environ(self):
        request_url = url_parse(self.path)

        def shutdown_server():
            self.server.shutdown_signal = True

        url_scheme = self.server.ssl_context is None and 'http' or 'https'
        path_info = url_unquote(request_url.path)

        environ = {
            'wsgi.version':         (1, 0),
            'wsgi.url_scheme':      url_scheme,
            'wsgi.input':           self.rfile,
            'wsgi.errors':          sys.stderr,
            'wsgi.multithread':     self.server.multithread,
            'wsgi.multiprocess':    self.server.multiprocess,
            'wsgi.run_once':        False,
            'werkzeug.server.shutdown': shutdown_server,
            'SERVER_SOFTWARE':      self.server_version,
            'REQUEST_METHOD':       self.command,
            'SCRIPT_NAME':          '',
            'PATH_INFO':            wsgi_encoding_dance(path_info),
            'QUERY_STRING':         wsgi_encoding_dance(request_url.query),
            'REMOTE_ADDR':          self.address_string(),
            'REMOTE_PORT':          self.port_integer(),
            'SERVER_NAME':          self.server.server_address[0],
            'SERVER_PORT':          str(self.server.server_address[1]),
            'SERVER_PROTOCOL':      self.request_version
        }

        for key, value in self.headers.items():
            key = key.upper().replace('-', '_')
            if key not in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
                key = 'HTTP_' + key
            environ[key] = value

        if request_url.scheme and request_url.netloc:
            environ['HTTP_HOST'] = request_url.netloc

        return environ 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:42,代码来源:serving.py

示例15: referer_is_block

# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_parse [as 别名]
def referer_is_block(request):
    referrer = request.referrer
    if referrer is None:
        return False

    hostname = url_parse(referrer).host
    for r in config.ALLOWED_REFERER:
        if r.startswith("*.") and match(".*." + r.split(".", 1)[1], hostname):
            return False
        if r == hostname:
            return False
    return True 
开发者ID:honmaple,项目名称:maple-blog,代码行数:14,代码来源:util.py


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