Python django.utils.six.moves.urllib.parse 模块,urljoin() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.utils.six.moves.urllib.parse.urljoin()

项目:wagtail-schema.org    作者:takeflight    | 项目源码 | 文件源码
def image_ld(image, thumbnail_filter="max-200x200", base_url=None):
    # Support custom image models with a to_json_ld() method
    if hasattr(image, 'to_json_ld'):
        return image.ld_entity()

    thumbnail = image.get_rendition(thumbnail_filter)
    url = urljoin(base_url, image.file.url)

    return {
        '@context': 'http://schema.org',
        '@type': 'ImageObject',
        '@id': url,
        'name': image.title,
        'url': url,
        'contentUrl': url,
        'contentSize': str(image.file.size),
        'width': Distance('{} px'.format(image.width)),
        'height': Distance('{} px'.format(image.height)),
        'thumbnail': urljoin(base_url, thumbnail.url),
    }
项目:django-scim2    作者:15five    | 项目源码 | 文件源码
def test_search_for_user_with_username_filter(self):
        """
        Test POST /Users/.search/?filter=userName eq ""
        """
        url = reverse('scim:users-search')
        body = json.dumps({
            'schemas': [constants.SchemaURI.SERACH_REQUEST],
            'filter': 'userName eq ""',
        })
        resp = self.client.post(url, body, content_type=constants.SCIM_CONTENT_TYPE)
        self.assertEqual(resp.status_code, 200, resp.content.decode())
        location = urljoin(get_base_scim_location_getter()(), '/scim/v2/')
        location = urljoin(location, 'Users/.search')
        self.assertEqual(resp['Location'], location)

        result = json.loads(resp.content.decode())
        expected = {
            "schemas": [constants.SchemaURI.LIST_RESPONSE],
            "totalResults": 0,
            "itemsPerPage": 50,
            "startIndex": 1,
            "Resources": [],
        }
        self.assertEqual(expected, result)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def _handle_redirects(self, response, **extra):
        "Follows any redirects by requesting responses from the server using GET."

        response.redirect_chain = []
        while response.status_code in (301, 302, 303, 307):
            response_url = response.url
            redirect_chain = response.redirect_chain
            redirect_chain.append((response_url, response.status_code))

            url = urlsplit(response_url)
            if url.scheme:
                extra['wsgi.url_scheme'] = url.scheme
            if url.hostname:
                extra['SERVER_NAME'] = url.hostname
            if url.port:
                extra['SERVER_PORT'] = str(url.port)

            # Prepend the request path to handle relative path redirects
            path = url.path
            if not path.startswith('/'):
                path = urljoin(response.request['PATH_INFO'], path)

            response = self.get(path, QueryDict(url.query), follow=False, **extra)
            response.redirect_chain = redirect_chain

            if redirect_chain[-1] in redirect_chain[:-1]:
                # Check that we're not redirecting to somewhere we've already
                # been to, to prevent loops.
                raise RedirectCycleError("Redirect loop detected.", last_response=response)
            if len(redirect_chain) > 20:
                # Such a lengthy chain likely also means a loop, but one with
                # a growing path, changing view, or changing query argument;
                # 20 is the value of "network.http.redirection-limit" from Firefox.
                raise RedirectCycleError("Too many redirects.", last_response=response)

        return response
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def handle_simple(cls, path):
        return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:django    作者:alexsukhrin    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:django-cockatiel    作者:raphaelm    | 项目源码 | 文件源码
def _get_url(self, node, name):
        return urllib.parse.urljoin(node, name)
项目:django-cockatiel    作者:raphaelm    | 项目源码 | 文件源码
def url(self, name):
        if self.conf.get('PUBLIC_URL') is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.conf.get('PUBLIC_URL'), filepath_to_uri(name))
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:django-db-storage    作者:derekkwok    | 项目源码 | 文件源码
def url(self, name):
        return urljoin(self.base_url, filepath_to_uri(name))
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def get_images_url(self):
        return urljoin(self.url, self.IMAGE_LIST_URI)
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def get_image_manifest_url(self, uuid):
        return urljoin(self.url, self.IMAGE_URI % uuid)
项目:wagtailvideos    作者:takeflight    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:ims    作者:ims-team    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def _handle_redirects(self, response, **extra):
        "Follows any redirects by requesting responses from the server using GET."

        response.redirect_chain = []
        while response.status_code in (301, 302, 303, 307):
            response_url = response.url
            redirect_chain = response.redirect_chain
            redirect_chain.append((response_url, response.status_code))

            url = urlsplit(response_url)
            if url.scheme:
                extra['wsgi.url_scheme'] = url.scheme
            if url.hostname:
                extra['SERVER_NAME'] = url.hostname
            if url.port:
                extra['SERVER_PORT'] = str(url.port)

            # Prepend the request path to handle relative path redirects
            path = url.path
            if not path.startswith('/'):
                path = urljoin(response.request['PATH_INFO'], path)

            response = self.get(path, QueryDict(url.query), follow=False, **extra)
            response.redirect_chain = redirect_chain

            if redirect_chain[-1] in redirect_chain[:-1]:
                # Check that we're not redirecting to somewhere we've already
                # been to, to prevent loops.
                raise RedirectCycleError("Redirect loop detected.", last_response=response)
            if len(redirect_chain) > 20:
                # Such a lengthy chain likely also means a loop, but one with
                # a growing path, changing view, or changing query argument;
                # 20 is the value of "network.http.redirection-limit" from Firefox.
                raise RedirectCycleError("Too many redirects.", last_response=response)

        return response
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def handle_simple(cls, path):
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.storage import staticfiles_storage
            return staticfiles_storage.url(path)
        else:
            return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def get_media_url():
    return urljoin(settings.MEDIA_URL, get_cms_setting('MEDIA_PATH'))
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def _handle_redirects(self, response, **extra):
        "Follows any redirects by requesting responses from the server using GET."

        response.redirect_chain = []
        while response.status_code in (301, 302, 303, 307):
            response_url = response.url
            redirect_chain = response.redirect_chain
            redirect_chain.append((response_url, response.status_code))

            url = urlsplit(response_url)
            if url.scheme:
                extra['wsgi.url_scheme'] = url.scheme
            if url.hostname:
                extra['SERVER_NAME'] = url.hostname
            if url.port:
                extra['SERVER_PORT'] = str(url.port)

            # Prepend the request path to handle relative path redirects
            path = url.path
            if not path.startswith('/'):
                path = urljoin(response.request['PATH_INFO'], path)

            response = self.get(path, QueryDict(url.query), follow=False, **extra)
            response.redirect_chain = redirect_chain

            if redirect_chain[-1] in redirect_chain[:-1]:
                # Check that we're not redirecting to somewhere we've already
                # been to, to prevent loops.
                raise RedirectCycleError("Redirect loop detected.", last_response=response)
            if len(redirect_chain) > 20:
                # Such a lengthy chain likely also means a loop, but one with
                # a growing path, changing view, or changing query argument;
                # 20 is the value of "network.http.redirection-limit" from Firefox.
                raise RedirectCycleError("Too many redirects.", last_response=response)

        return response
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        return urljoin(self.base_url, filepath_to_uri(name))
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def _handle_redirects(self, response, **extra):
        "Follows any redirects by requesting responses from the server using GET."

        response.redirect_chain = []
        while response.status_code in (301, 302, 303, 307):
            response_url = response.url
            redirect_chain = response.redirect_chain
            redirect_chain.append((response_url, response.status_code))

            url = urlsplit(response_url)
            if url.scheme:
                extra['wsgi.url_scheme'] = url.scheme
            if url.hostname:
                extra['SERVER_NAME'] = url.hostname
            if url.port:
                extra['SERVER_PORT'] = str(url.port)

            # Prepend the request path to handle relative path redirects
            path = url.path
            if not path.startswith('/'):
                path = urljoin(response.request['PATH_INFO'], path)

            response = self.get(path, QueryDict(url.query), follow=False, **extra)
            response.redirect_chain = redirect_chain

            if redirect_chain[-1] in redirect_chain[:-1]:
                # Check that we're not redirecting to somewhere we've already
                # been to, to prevent loops.
                raise RedirectCycleError("Redirect loop detected.", last_response=response)
            if len(redirect_chain) > 20:
                # Such a lengthy chain likely also means a loop, but one with
                # a growing path, changing view, or changing query argument;
                # 20 is the value of "network.http.redirection-limit" from Firefox.
                raise RedirectCycleError("Too many redirects.", last_response=response)

        return response
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def handle_simple(cls, path):
        return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
项目:nav    作者:UNINETT    | 项目源码 | 文件源码
def index(request, uri):
    """
    Proxies render requests to graphite-web, as configured in graphite.conf
    """
    base = CONFIG.get('graphiteweb', 'base')

    if request.method in ('GET', 'HEAD'):
        query = _inject_default_arguments(request.GET)
        url = urljoin(base, uri + ('?' + query) if query else '')
        req = Request(url)
    elif request.method == 'POST':
        data = _inject_default_arguments(request.POST)
        url = urljoin(base, uri)
        req = Request(url, data)
    else:
        return HttpResponseNotAllowed(['GET', 'POST', 'HEAD'])

    LOGGER.debug("proxying request to %r", url)
    proxy = urlopen(req)
    headers = proxy.info()
    content_type = headers.getheader('Content-Type', 'text/html')

    if request.method == 'HEAD':
        response = HttpResponse(content_type=content_type)
        response['Content-Length'] = headers.getheader('Content-Length', '0')
    else:
        response = HttpResponse(proxy.read(), content_type=content_type)

    response['X-Where-Am-I'] = request.get_full_path()
    return response
项目:nav    作者:UNINETT    | 项目源码 | 文件源码
def raw_metric_query(query):
    """Runs a query for metric information against Graphite's REST API.

    :param query: A search string, e.g. "nav.devices.some-gw_example_org.*"
    :returns: A list of matching metrics, each represented by a dict.

    """
    base = CONFIG.get("graphiteweb", "base")
    url = urljoin(base, "/metrics/find")
    query = urlencode({'query': query})
    url = "%s?%s" % (url, query)

    req = Request(url)
    try:
        response = urlopen(req)
        return json.load(response)
    except URLError as err:
        raise errors.GraphiteUnreachableError(
            "{0} is unreachable".format(base), err)
    except ValueError:
        # response could not be decoded
        return []
    finally:
        try:
            response.close()
        except NameError:
            pass
项目:dach    作者:ffaraone    | 项目源码 | 文件源码
def render(self, context):
        # asvar, self.asvar = self.asvar, None
        path = super(AbsoluteURLNode, self).render(context)
        abs_url = urljoin(DACH_CONFIG['base_url'], path)

        if not self.asvar:
            return abs_url
        else:
            context[self.asvar] = abs_url
            return ''
项目:dach    作者:ffaraone    | 项目源码 | 文件源码
def url(self, context):
        path = self.path.resolve(context)
        return urljoin(DACH_CONFIG['base_url'], staticfiles_storage.url(path))
项目:dach    作者:ffaraone    | 项目源码 | 文件源码
def abs_static(path):
    base_url = getattr(settings, 'DACH_CONFIG')['base_url']
    return urljoin(base_url, staticfiles_storage.url(path))
项目:CSCE482-WordcloudPlus    作者:ggaytan00    | 项目源码 | 文件源码
def url(self, name):
        if self.base_url is None:
            raise ValueError("This file is not accessible via a URL.")
        url = filepath_to_uri(name)
        if url is not None:
            url = url.lstrip('/')
        return urljoin(self.base_url, url)
项目:tissuelab    作者:VirtualPlants    | 项目源码 | 文件源码
def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                 # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)