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


Python URL.as_string方法代码示例

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


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

示例1: get_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
    def get_links(self, request):
        if not self.event:
            return []

        links = []
        if self.event.state == "submitted":
            link = URL(request.link(self.event, "publish"))
            link = link.query_param("return-to", request.link(self.ticket))
            links.append(Link(text=_("Accept event"), url=link.as_string(), classes=("accept-link",)))

        links.append(
            DeleteLink(
                text=_("Reject event"),
                url=request.link(self.event),
                confirm=_("Do you really want to reject this event?"),
                extra_information=_("Rejecting this event can't be undone."),
                yes_button_text=_("Reject event"),
                redirect_after=request.link(self.ticket),
            )
        )

        link = URL(request.link(self.event, "bearbeiten"))
        link = link.query_param("return-to", request.url)
        links.append(Link(text=_("Edit event"), url=link.as_string(), classes=("edit-link",)))

        return links
开发者ID:i18nHub,项目名称:onegov.town,代码行数:28,代码来源:ticket.py

示例2: get_camera

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
 def get_camera(self):
     if self.config.URL:
         url = URL(self.config.URL)
         auth = url.username(), url.password()
         if url.username is None and url.password is None:
             auth = None
         url = URL(url.as_string(), username='', password='')
         return FoscamHTTPCamera(url.as_string(), auth)
     else:
         return USBCamera(self.config.DEVICE)
开发者ID:unaizalakain,项目名称:lightweight-motion,代码行数:12,代码来源:command.py

示例3: get_bib

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [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: activate

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
    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,代码行数:35,代码来源:models.py

示例5: __call__

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
    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,代码行数:37,代码来源:elements.py

示例6: get

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
 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,代码行数:31,代码来源:cache.py

示例7: editbar_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
    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,代码行数:33,代码来源:layout.py

示例8: set_param

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
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,代码行数:9,代码来源:utils.py

示例9: url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
 def url(self):
     kwargs = {
         "username": self.repository.user.username,
         "repository": self.repository.name,
         "presentation": self.name,
     }
     url = URL(scheme="http", host=self.repository.site.domain, path=reverse("qraz:download", kwargs=kwargs))
     return url.as_string()
开发者ID:fladi,项目名称:qraz,代码行数:10,代码来源:models.py

示例10: handle_pending_submission

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
def handle_pending_submission(self, request):
    """ Renders a pending submission, takes it's input and allows the
    user to turn the submission into a complete submission, once all data
    is valid.

    Takes the following query parameters for customization::

        * ``edit`` no validation is done on the first load if present
        * ``return-to`` the view redirects to this url once complete if present
        * ``title`` a custom title (required if external submission)
        * ``quiet`` no success messages are rendered if present

    """
    collection = FormCollection(request.app.session())

    form = request.get_form(self.form_class, data=self.data)
    form.action = request.link(self)

    if 'edit' not in request.GET:
        form.validate()

    if not request.POST:
        form.ignore_csrf_error()
    else:
        collection.submissions.update(self, form)

    # these parameters keep between form requests (the rest throw away)
    for param in {'return-to', 'title', 'quiet'}:
        if param in request.GET:
            action = URL(form.action).query_param(param, request.GET[param])
            form.action = action.as_string()

    completable = not form.errors and 'edit' not in request.GET

    if completable and 'return-to' in request.GET:

        if 'quiet' not in request.GET:
            request.success(_("Your changes were saved"))

        return morepath.redirect(request.GET['return-to'])

    if 'title' in request.GET:
        title = request.GET['title']
    else:
        title = self.form.title

    return {
        'layout': FormSubmissionLayout(self, request, title),
        'title': title,
        'form': form,
        'completable': completable,
        'edit_link': request.link(self) + '?edit',
        'complete_link': request.link(self, 'complete'),
        'is_pending': self.state == 'pending',
        'readonly': 'readonly' in request.GET,
    }
开发者ID:i18nHub,项目名称:onegov.town,代码行数:58,代码来源:form_submission.py

示例11: get_submission_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
def get_submission_link(request, submission, confirm_link):
    url = URL(request.link(submission))
    url = url.query_param('return-to', confirm_link)
    url = url.query_param('title', request.translate(
        _("Details about the reservation"))
    )
    url = url.query_param('edit', 1)
    url = url.query_param('quiet', 1)

    return url.as_string()
开发者ID:i18nHub,项目名称:onegov.town,代码行数:12,代码来源:reservation.py

示例12: get_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
    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:Gitlab11,项目名称:onegov.town,代码行数:15,代码来源:ticket.py

示例13: blog_feed

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
def blog_feed(request):
    """
    Proxy feeds from the blog, so they can be accessed via XHR requests.

    We also convert RSS to ATOM so that clld's javascript Feed component can read them.
    """
    if not request.params.get('path'):
        raise HTTPNotFound()
    path = URL(request.params['path'])
    assert not path.host()
    try:
        return atom_feed(request, request.blog.url(path.as_string()))
    except ConnectionError:
        raise HTTPNotFound()
开发者ID:clld,项目名称:wals3,代码行数:16,代码来源:views.py

示例14: get

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
 def get(self, url, **kw):
     url = URL(url)
     content = get_resource(
         url.path_segment(-1) if url.path_segments() else 'dataset', self.prefix)
     if content:
         return MagicMock(
             mimetype='application/rdf+xml',
             content=content,
             links=[dict(
                 url='{0}.html'.format(url.as_string),
                 ext='.html',
                 rel='alternate',
                 type='text/html')],
             canonical_url=url.as_string())
开发者ID:LinguList,项目名称:clldclient,代码行数:16,代码来源:util.py

示例15: get_resource_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import as_string [as 别名]
    def get_resource_url(self, id=None, action=None):
        """
        Get a base URL for the resource with the given id and/or action.
        :return: A string URL with the full path to the resource
        """
        base_url = URL(Configuration.BASE_API_URL).add_path_segment(self._resource_name)

        if id:
            base_url = base_url.add_path_segment(id)

        if action:
            base_url = base_url.add_path_segment(action)

        return base_url.as_string()
开发者ID:jccotou,项目名称:OneCodex-Python,代码行数:16,代码来源:OneCodexAPIURLBuilder.py


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