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


Python URL.path方法代码示例

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


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

示例1: append_path

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def append_path(url, url_path):
    target = URL(url_path)
    if url_path.startswith('/'):
        url = url.path(target.path())
    else:
        url = url.add_path_segment(target.path())
    if target.query():
        url = url.query(target.query())
    return url.as_string()
开发者ID:mikek,项目名称:behave-http,代码行数:11,代码来源:utils.py

示例2: append_path

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def append_path(url, path):
    target = URL(path)
    if target.path():
        url = add_multi_path_segments(url, target.path())
    if target.query():
        url = url.query(target.query())

    #print("Target: ", target.path)
    #raise NotImplementedError("target2: %r %r %r" % (target, target.query, url))

    return url.as_string()
开发者ID:kristinriebe,项目名称:uws-validator,代码行数:13,代码来源:utils.py

示例3: get_bib

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def get_bib(args):
    uploaded = load(args.data_file('repos', 'cdstar.json'))
    fname_to_cdstar = {}
    for type_ in ['texts', 'docs', 'data']:
        for hash_, paths in load(args.data_file('repos', type_ + '.json')).items():
            if hash_ in uploaded:
                for path in paths:
                    fname_to_cdstar[path.split('/')[-1]] = uploaded[hash_]
    for hash_, paths in load(args.data_file('repos', 'edmond.json')).items():
        if hash_ in uploaded:
            for path in paths:
                fname_to_cdstar[path.split('/')[-1]] = uploaded[hash_]
    db = Database.from_file(args.data_file('repos', 'Dogon.bib'), lowercase=True)
    for rec in db:
        doc = Document(rec)
        newurls = []
        for url in rec.get('url', '').split(';'):
            if not url.strip():
                continue
            if url.endswith('sequence=1'):
                newurls.append(url)
                continue
            url = URL(url.strip())
            if url.host() in ['dogonlanguages.org', 'github.com', '']:
                fname = url.path().split('/')[-1]
                doc.files.append((fname, fname_to_cdstar[fname]))
            else:
                newurls.append(url.as_string())
        doc.rec['url'] = '; '.join(newurls)
        yield doc
开发者ID:clld,项目名称:dogonlanguages,代码行数:32,代码来源:util.py

示例4: cc_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def cc_link(req, license_url, button='regular'):
    if license_url == 'https://en.wikipedia.org/wiki/Public_domain':
        license_url = 'https://creativecommons.org/publicdomain/zero/1.0/'
    license_url = URL(license_url)
    if license_url.host() != 'creativecommons.org':
        return

    comps = license_url.path().split('/')
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        'zero': 'Public Domain',
        'by': 'Creative Commons Attribution License',
        'by-nc': 'Creative Commons Attribution-NonCommercial License',
        'by-nc-nd': 'Creative Commons Attribution-NonCommercial-NoDerivatives License',
        'by-nc-sa': 'Creative Commons Attribution-NonCommercial-ShareAlike License',
        'by-nd': 'Creative Commons Attribution-NoDerivatives License',
        'by-sa': 'Creative Commons Attribution-ShareAlike License'}
    if comps[2] not in known:
        return

    icon = 'cc-' + comps[2] + ('-small' if button == 'small' else '') + '.png'
    img_attrs = dict(
        alt=known[comps[2]],
        src=req.static_url('clld:web/static/images/' + icon))
    height, width = (15, 80) if button == 'small' else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel='license')
开发者ID:clld,项目名称:clld,代码行数:31,代码来源:helpers.py

示例5: cc_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def cc_link(req, license_url, button="regular"):
    if license_url == "http://en.wikipedia.org/wiki/Public_domain":
        license_url = "http://creativecommons.org/publicdomain/zero/1.0/"
    license_url = URL(license_url)
    if license_url.host() != "creativecommons.org":
        return

    comps = license_url.path().split("/")
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        "zero": "Public Domain",
        "by": "Creative Commons Attribution License",
        "by-nc": "Creative Commons Attribution-NonCommercial License",
        "by-nc-nd": "Creative Commons Attribution-NonCommercial-NoDerivatives License",
        "by-nc-sa": "Creative Commons Attribution-NonCommercial-ShareAlike License",
        "by-nd": "Creative Commons Attribution-NoDerivatives License",
        "by-sa": "Creative Commons Attribution-ShareAlike License",
    }
    if comps[2] not in known:
        return

    icon = "cc-" + comps[2] + ("-small" if button == "small" else "") + ".png"
    img_attrs = dict(alt=known[comps[2]], src=req.static_url("clld:web/static/images/" + icon))
    height, width = (15, 80) if button == "small" else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel="license")
开发者ID:cevmartinez,项目名称:clld,代码行数:30,代码来源:helpers.py

示例6: get_data

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def get_data(q_link):
    url = URL(q_link)
    if url.domain() not in ['quora.com', 'www.quora.com']:
        return 'error, not quora'

    url = URL(
        scheme='https',
        host='www.quora.com',
        path=url.path(),
        query='share=1').as_string()

    soup = BeautifulSoup(requests.get(url).text)

    question = {}
    question['url'] = url
    question['title'] = soup.find("div", {"class": "question_text_edit"}).text
    question['topics'] = [topic.text for topic in soup.find_all("div", {"class": "topic_list_item"})]
    question['details'] = soup.find("div", {"class": "question_details_text"}).text

    answers = []

    divs = soup.find_all("div", {"class": "pagedlist_item"})
    
    try:
        ans_count = soup.find("div", {"class": "answer_header_text"}).text.strip()
        count = int(re.match(r'(\d+) Answers', ans_count).groups()[0])
    except:
        return jsonify(question=question, answers=answers)

    question['answer_count'] = count

    count = len(divs) - 1 if count < 6 else 6
    for i in range(count):
        one_answer = {
            'votes': '-1',
            'rank': 0,
            'answer': ''
        }
        try:
            author = {}
            author['name'] = divs[i].find("div", {"class": "answer_user"}).find("span", {"class": "answer_user_wrapper"}).find("a", {"class": "user"}).string
            author['bio'] = divs[i].find("div", {"class": "answer_user"}).find("span", {"class": "answer_user_wrapper"}).find_all("span", {"class": "rep"})[1].find("span", {"class": "hidden"}).text
        except:
            author['name'] = 'Anonymous'
            author['bio'] = ''
        one_answer['author'] = author

        one_answer['votes'] = divs[i].find("span", {"class":"numbers"}).text

        html_block = divs[i].find("div", {"id": re.compile("(.*)_container")}).contents
        answer_html = ''
        for p in range(len(html_block) - 1):
            answer_html += str(html_block[p])
        one_answer['answer_html'] = answer_html
        one_answer['answer'] = divs[i].find("div", {"class": "answer_content"}).text
        one_answer['rank'] = i + 1
        answers.append(one_answer)

    return jsonify(question=question, answers=answers)
开发者ID:GaneshPandey,项目名称:Qnowledge,代码行数:61,代码来源:app.py

示例7: test_facebook_login_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def test_facebook_login_url():
    facebook_client = FacebookClient(local_host='localhost')
    facebook_login_url = URL(facebook_client.get_login_uri())
    query = facebook_login_url.query_params()
    callback_url = URL(query['redirect_uri'][0])
    func, _args, kwargs = resolve(callback_url.path())
    assert func is oauth_callback
    assert kwargs['service'] == FACEBOOK
    assert query['scope'][0] == FacebookClient.scope
    assert query['client_id'][0] == str(FacebookClient.client_id)
开发者ID:3ka5-cat,项目名称:saleor,代码行数:12,代码来源:test_registration.py

示例8: test_google_login_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def test_google_login_url(google_client, settings):
    settings.GOOGLE_CLIENT_ID = '112233'
    google_login_url = URL(google_client.get_login_uri())
    params = google_login_url.query_params()
    callback_url = URL(params['redirect_uri'][0])
    func, _args, kwargs = resolve(callback_url.path())
    assert func is oauth_callback
    assert kwargs['service'] == GOOGLE
    assert params['scope'][0] == google_client.scope
    assert params['client_id'][0] == str(google_client.client_id)
开发者ID:AlexzanderIvanov,项目名称:saleor,代码行数:12,代码来源:test_registration.py

示例9: test_facebook_login_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def test_facebook_login_url(facebook_client, settings):
    settings.FACEBOOK_APP_ID = '112233'
    facebook_login_url = URL(facebook_client.get_login_uri())
    query = facebook_login_url.query_params()
    callback_url = URL(query['redirect_uri'][0])
    func, _args, kwargs = resolve(callback_url.path())
    assert func is oauth_callback
    assert kwargs['service'] == FACEBOOK
    assert query['scope'][0] == facebook_client.scope
    assert query['client_id'][0] == str(facebook_client.client_id)
开发者ID:AlexzanderIvanov,项目名称:saleor,代码行数:12,代码来源:test_registration.py

示例10: test_google_login_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def test_google_login_url():
    google_client = GoogleClient(local_host='local_host')
    google_login_url = URL(google_client.get_login_uri())
    params = google_login_url.query_params()
    callback_url = URL(params['redirect_uri'][0])
    func, _args, kwargs = resolve(callback_url.path())
    assert func is oauth_callback
    assert kwargs['service'] == GOOGLE
    assert params['scope'][0] == GoogleClient.scope
    assert params['client_id'][0] == str(GoogleClient.client_id)
开发者ID:3ka5-cat,项目名称:saleor,代码行数:12,代码来源:test_registration.py

示例11: test_google_login_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
 def test_google_login_url(self):
     """Google login url is properly generated"""
     google_client = GoogleClient(local_host='local_host')
     google_login_url = URL(google_client.get_login_uri())
     params = google_login_url.query_params()
     callback_url = URL(params['redirect_uri'][0])
     func, _args, kwargs = resolve(callback_url.path())
     self.assertEquals(func, oauth_callback)
     self.assertEquals(kwargs['service'], GOOGLE)
     self.assertIn(params['scope'][0], GoogleClient.scope)
     self.assertEqual(params['client_id'][0], GoogleClient.client_id)
开发者ID:D0han,项目名称:saleor,代码行数:13,代码来源:tests.py

示例12: test_facebook_login_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
 def test_facebook_login_url(self):
     """Facebook login url is properly generated"""
     facebook_client = FacebookClient(local_host='localhost')
     facebook_login_url = URL(facebook_client.get_login_uri())
     query = facebook_login_url.query_params()
     callback_url = URL(query['redirect_uri'][0])
     func, _args, kwargs = resolve(callback_url.path())
     self.assertEquals(func, oauth_callback)
     self.assertEquals(kwargs['service'], FACEBOOK)
     self.assertEqual(query['scope'][0], FacebookClient.scope)
     self.assertEqual(query['client_id'][0], FacebookClient.client_id)
开发者ID:D0han,项目名称:saleor,代码行数:13,代码来源:tests.py

示例13: license_name

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def license_name(license_url):
    if license_url == "http://commons.wikimedia.org/wiki/GNU_Free_Documentation_License":
        return 'GNU Free Documentation License'
    if license_url == 'http://en.wikipedia.org/wiki/Public_domain':
        license_url = 'http://creativecommons.org/publicdomain/zero/1.0/'
    license_url_ = URL(license_url)
    if license_url_.host() != 'creativecommons.org':
        return license_url

    comps = license_url_.path().split('/')
    if len(comps) < 3:
        return license_url

    return {
        'zero': 'Public Domain',
    }.get(comps[2], '(CC) %s' % comps[2].upper())
开发者ID:afehn,项目名称:tsammalex,代码行数:18,代码来源:util.py

示例14: SplinterTestCase

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
class SplinterTestCase(LiveServerTestCase):
    username = 'peter.griffin'
    email = '[email protected]'
    password = 'lazyonthecouch'
    is_anonymous = True
    is_staff = False
    is_logged_in = True

    def setUp(self):
        settings.DEBUG = True
        super(SplinterTestCase, self).setUp()
        self.user = None
        self.base_url = URL(self.live_server_url)
        self.browser = Browser(SPLINTER_WEBDRIVER)

        if self.is_anonymous and not self.is_staff:
            return

        self.user = factories.UserFactory(
            username=self.username,
            email=self.email,
            password=self.password,
            is_staff=self.is_staff,
        )

        if self.is_logged_in:
            self.goto(reverse('admin:index'))
            self.browser.fill_form({
                'username': self.username,
                'password': self.password,
            })
            self.browser.find_by_css("input[type='submit']").first.click()
            self.assertIn('Log out', self.browser.html)

    def tearDown(self):
        super(SplinterTestCase, self).tearDown()
        self.browser.quit()

    def goto(self, path):
        url = self.base_url.path(path)
        return self.browser.visit(url.as_string())
开发者ID:OliverRandell,项目名称:django-fancypages,代码行数:43,代码来源:testcases.py

示例15: get_questions

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path [as 别名]
def get_questions(s_link):
    url = URL(s_link)
    if url.domain() not in ['quora.com', 'www.quora.com']:
        return 'error, not quora'

    url = URL(
        scheme='https',
        host='www.quora.com',
        path=url.path(),
        query='share=1').as_string()

    soup = BeautifulSoup(requests.get(url).text)

    topic = {}
    topic['url'] = url
    topic['title'] = soup.find("span", {"class": "TopicName"}).text

    questions = []
    divs = soup.find_all("div", {"class": "pagedlist_item"})
    count = len(divs) - 1
    for i in range(count):
        one_question = {
            'url': '',
			'title': ''
        }
        try:
            one_question['url'] = divs[i].find("a", {"class": "question_link"})['href']
            one_question['title'] = divs[i].find("a", {"class": "question_link"}).find("span", {"class": "link_text"}).text
        except:
            jsonify(topic=topic, questions=questions, parse_failure=one_question)
        one_question['url'] = URL(
            scheme='https',
            host='www.quora.com',
            path=one_question['url']).as_string()

        if one_question['title'] != "":
            questions.append(one_question)

    return jsonify(topic=topic, questions=questions)
开发者ID:onerinas,项目名称:Qnowledge,代码行数:41,代码来源:app.py


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