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


Python purl.URL类代码示例

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


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

示例1: get

 def get(self, url, default=NO_DEFAULT, headers=None):
     """Retrieve a Response object for a given URL.
     """
     headers = headers or {}
     url = URL(url)
     row = self.db.execute(
         select([
             responses.c.created,
             responses.c.host,
             responses.c.request_url,
             responses.c.accept,
             responses.c.url,
             responses.c.headers,
             responses.c.content])
         .where(and_(
             responses.c.request_url == url.as_string(),
             responses.c.accept == headers.get('Accept', '')))
     ).fetchone()
     if not row:
         log.info('cache miss %s' % url)
         row = self.add(url, headers)
         if row is None:
             if default is NO_DEFAULT:
                 raise KeyError(url)
             log.info('invalid url %s' % url)
             return default
     else:
         log.info('cache hit %s' % url)
     return Response(*row)
开发者ID:clld,项目名称:clldclient,代码行数:29,代码来源:cache.py

示例2: Segments

class Segments(object):
    def __init__(self, base, path, segments, defaults):
        self.base = PURL(base, path=path)
        self.segments = OrderedDict(zip(segments, defaults))

    def build(self):
        segments = self.base.path_segments() + tuple(self.segments.values())
        url = self.base.path_segments(segments)
        return url

    def __str__(self):
        return self.build().as_string()

    def _get_segment(self, segment):
        return self.segments[segment]

    def _set_segment(self, segment, value):
        self.segments[segment] = value

    @classmethod
    def _segment(cls, segment):
        return property(
                fget=lambda x: cls._get_segment(x, segment),
                fset=lambda x, v: cls._set_segment(x, segment, v),
                )
开发者ID:wcmckee,项目名称:pyatakl,代码行数:25,代码来源:utils.py

示例3: __call__

    def __call__(self, request, extra_classes=None):
        """ Renders the element. """

        a = builder.A(request.translate(self.text))

        if self.request_method == 'GET':
            a.attrib['href'] = self.url

        if self.request_method == 'DELETE':
            url = URL(self.url).query_param(
                'csrf-token', request.new_csrf_token())

            a.attrib['ic-delete-from'] = url.as_string()

        if self.classes or extra_classes:
            classes = self.classes + (extra_classes or tuple())
            a.attrib['class'] = ' '.join(classes)

        # add the hidden from public hint if needed
        if self.is_hidden_from_public:

            # This snippet is duplicated in the hidden-from-public-hint macro!
            hint = builder.I()
            hint.attrib['class'] = 'hidden-from-public-hint'
            hint.attrib['title'] = request.translate(
                _("This site is hidden from the general public")
            )

            a.append(builder.I(' '))
            a.append(hint)

        for key, value in self.attributes.items():
            a.attrib[key] = request.translate(value)

        return tostring(a)
开发者ID:i18nHub,项目名称:onegov.town,代码行数:35,代码来源:elements.py

示例4: editbar_links

    def editbar_links(self):
        if self.request.is_logged_in:
            edit_url = URL(self.request.link(self.model.event, 'bearbeiten'))
            edit_url = edit_url.query_param(
                'return-to', self.request.link(self.model.event)
            )
            edit_link = Link(
                text=_("Edit"),
                url=edit_url.as_string(),
                classes=('edit-link', )
            )

            if self.event_deletable(self.model.event):
                delete_link = DeleteLink(
                    text=_("Delete"),
                    url=self.request.link(self.model.event),
                    confirm=_("Do you really want to delete this event?"),
                    yes_button_text=_("Delete event"),
                    redirect_after=self.events_url
                )
            else:
                delete_link = DeleteLink(
                    text=_("Delete"),
                    url=self.request.link(self.model.event),
                    confirm=_("This event can't be deleted."),
                    extra_information=_(
                        "To remove this event, go to the ticket and reject it."
                    )
                )

            return [edit_link, delete_link]
开发者ID:i18nHub,项目名称:onegov.town,代码行数:31,代码来源:layout.py

示例5: select

 def select(self, url):
     print "SELECTED!!"
     url = URL(url)
     field_name = '%s_exact' % self.facet_name
     url = url.append_query_param('selected_facets', '%s:%s' % (field_name, self.key))
     self.selected = True
     return url
开发者ID:bryandmc,项目名称:saleor,代码行数:7,代码来源:facet.py

示例6: get_links

    def get_links(self, request):

        edit_link = URL(request.link(self.submission))
        edit_link = edit_link.query_param("edit", "")
        edit_link = edit_link.query_param("return-to", request.url)

        return [Link(text=_("Edit submission"), url=edit_link.as_string(), classes=("edit-link",))]
开发者ID:i18nHub,项目名称:onegov.town,代码行数:7,代码来源:ticket.py

示例7: get_wikipedia

def get_wikipedia(args, name):
    url = URL(
        "http://en.wikipedia.org/w/api.php?format=json&action=query&prop=info&inprop=url")

    def get_result(res):
        """
{
    "query": {
        "pages": {
            "45724": {
                "contentmodel": "wikitext",
                "counter": "",
                "editurl":
                    "http://en.wikipedia.org/w/index.php?title=Panthera_leo&action=edit",
                "fullurl": "http://en.wikipedia.org/wiki/Panthera_leo",
                "lastrevid": 535861485,
                "length": 71,
                "ns": 0,
                "pageid": 45724,
                "pagelanguage": "en",
                "redirect": "",
                "title": "Panthera leo",
                "touched": "2014-02-27T02:04:39Z"
            }
        }
    }
}
        """
        res = res.json().get('query', {}).get('pages', {})
        return res.values()[0] if res else {}

    return get_data(args, name, 'wikipedia', url.query_param('titles', name), get_result)
开发者ID:kristinnts11,项目名称:tsammalex,代码行数:32,代码来源:wiki.py

示例8: get_bib

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,代码行数:30,代码来源:util.py

示例9: __init__

    def __init__(self, url, save_dir='tmp'):
        """
        @url: full url of a site
        @save_dir: dir to save site
        """
        # log
        self.logger = logger('file', 'sitelog.log', save_dir)
        self.logger.info('-' * 20)
        self.logger.info('start')
        self.logger.info('start func: __init__')
        self.logger.info('url: %s' % url)

        save_time = datetime.strftime(datetime.now(), '%Y%m%d%H%M')
        self.save_time = save_time
        self.save_dir = os.path.abspath(os.path.join(save_dir, save_time))
        # create dir if not exist
        if not os.path.isdir(self.save_dir):
            os.makedirs(self.save_dir)

        self.url = url
        u = URL(url)
        # get host like: http://m.sohu.xom
        self.host = u.scheme() + '://' + u.host()
        print '%s: saving %s' % (save_time, self.url)
        self.logger.info('end func: __init__')
开发者ID:basicworld,项目名称:sitedownloader,代码行数:25,代码来源:main.py

示例10: cc_link

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,代码行数:28,代码来源:helpers.py

示例11: cc_link

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,代码行数:29,代码来源:helpers.py

示例12: set_param

def set_param(request=None, url=None, **kwargs):
    if not request and not url:
        return '/'
    url = URL(path=request.path, query=request.META['QUERY_STRING']) if request else URL(url)
    for k, v in kwargs.items():
        url = url.query_param(k, v)
    return url.as_string()
开发者ID:pinkevich,项目名称:django-project-template,代码行数:7,代码来源:utils.py

示例13: activate

    def activate(self, *args, **kwargs):
        """
        Transition: inactive -> active

        Set github webhook and activate all Presentations.
        """
        try:
            provider = self.user.social_auth.get(provider="github")
        except UserSocialAuth.DoesNotExists:
            logger.error("No social auth provider for Github found on user")
            return
        github = Github(provider.access_token)
        try:
            repo = github.get_user().get_repo(self.name)
        except GithubException:
            logger.error("Could not find repository")
            return
        url = URL(
            scheme="https",
            host=self.site.domain,
            path=reverse("qraz:webhook", kwargs={"username": self.user.username, "repository": self.name}),
        )
        try:
            hook = repo.create_hook(
                "web",
                {"url": url.as_string(), "content_type": "json", "secret": self.secret},
                events=["push"],
                active=True,
            )
        except GithubException as excp:
            logger.error("Could not create webhook: %s", excp)
            return
        self.hook = hook.id
开发者ID:fladi,项目名称:qraz,代码行数:33,代码来源:models.py

示例14: get_data

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,代码行数:59,代码来源:app.py

示例15: info

    def info(self, url):
        """Interface method to be called when processing new images.

        This method ties together the DataProvider workflow.
        """
        url = URL(url)
        return self.postprocess(
            self.info_for_id(self.id_from_url(url, url.host(), url.path_segments())))
开发者ID:afehn,项目名称:tsammalex-data,代码行数:8,代码来源:image_providers.py


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