當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。