python类iri_to_uri()的实例源码

models.py 文件源码 项目:django-endless-pagination-vue 作者: mapeveri 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(
            self, request, number, current_number, total_number,
            querystring_key, label=None, default_number=1, override_path=None):
        self._request = request
        self.number = number
        self.label = utils.text(number) if label is None else label
        self.querystring_key = querystring_key

        self.is_current = number == current_number
        self.is_first = number == 1
        self.is_last = number == total_number

        self.url = utils.get_querystring_for_page(
            request, number, self.querystring_key,
            default_number=default_number)
        path = iri_to_uri(override_path or request.path)
        self.path = '{0}{1}'.format(path, self.url)
download.py 文件源码 项目:eoj3 作者: ultmaster 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def respond_as_attachment(request, file_path, original_filename, document_root=None):
    if document_root is not None:
        file_path = os.path.join(document_root, file_path)
    try:
        fp = open(file_path, 'rb')
        response = HttpResponse(fp.read())
        fp.close()
        type, encoding = mimetypes.guess_type(original_filename)
        if type is None:
            type = 'application/octet-stream'
        response['Content-Type'] = type
        response['Content-Length'] = str(os.stat(file_path).st_size)
        if encoding is not None:
            response['Content-Encoding'] = encoding
            url_encode()
        response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % iri_to_uri(original_filename)
        return response
    except Exception as e:
        raise Http404(e)
views.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not url.startswith(('http://', 'https://', 'mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url
models.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
defaultfilters.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def iriencode(value):
    """Escapes an IRI value for use in a URL."""
    return force_text(iri_to_uri(value))
cache.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _generate_cache_key(request, method, headerlist, key_prefix):
    """Returns a cache key from the headers given in the header list."""
    ctx = hashlib.md5()
    for header in headerlist:
        value = request.META.get(header)
        if value is not None:
            ctx.update(force_bytes(value))
    url = hashlib.md5(force_bytes(iri_to_uri(request.build_absolute_uri())))
    cache_key = 'views.decorators.cache.cache_page.%s.%s.%s.%s' % (
        key_prefix, method, url.hexdigest(), ctx.hexdigest())
    return _i18n_cache_key_suffix(request, cache_key)
cache.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _generate_cache_header_key(key_prefix, request):
    """Returns a cache key for the header cache."""
    url = hashlib.md5(force_bytes(iri_to_uri(request.build_absolute_uri())))
    cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
        key_prefix, url.hexdigest())
    return _i18n_cache_key_suffix(request, cache_key)
feedgenerator.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, url, length, mime_type):
        "All args are expected to be Python Unicode objects"
        self.length, self.mime_type = length, mime_type
        self.url = iri_to_uri(url)
static.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def handle_simple(cls, name):
        try:
            from django.conf import settings
        except ImportError:
            prefix = ''
        else:
            prefix = iri_to_uri(getattr(settings, name, ''))
        return prefix
views.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not url.startswith(('http://', 'https://', 'mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url
models.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
__init__.py 文件源码 项目:planet-b-saleor 作者: planet-b 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def build_absolute_uri(location, is_secure=False):
    # type: (str, bool, saleor.site.models.SiteSettings) -> str
    host = Site.objects.get_current().domain
    current_uri = '%s://%s' % ('https' if is_secure else 'http', host)
    location = urljoin(current_uri, location)
    return iri_to_uri(location)
treeitem.py 文件源码 项目:zing 作者: evernote 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def make_cache_key(self, name):
        return iri_to_uri('%s:%s' % (self.cache_key, name))
stats.py 文件源码 项目:zing 作者: evernote 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def make_cache_key(self, name):
        return iri_to_uri('%s:%s' % (self.path, name))
permissions.py 文件源码 项目:zing 作者: evernote 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def get_permissions_by_username(username, directory):
    pootle_path = directory.pootle_path
    path_parts = filter(None, pootle_path.split('/'))
    key = iri_to_uri('Permissions:%s' % username)
    permissions_cache = cache.get(key, {})

    if pootle_path not in permissions_cache:
        try:
            permissionset = PermissionSet.objects.filter(
                directory__in=directory.trail(),
                user__username=username).order_by('-directory__pootle_path')[0]
        except IndexError:
            permissionset = None

        if (len(path_parts) > 1 and path_parts[0] != 'projects' and
            (permissionset is None or
            len(filter(None, permissionset.directory.pootle_path.split('/'))) < 2)):
            # Active permission at language level or higher, check project
            # level permission
            try:
                project_path = '/projects/%s/' % path_parts[1]
                permissionset = PermissionSet.objects.get(
                    directory__pootle_path=project_path,
                    user__username=username)
            except PermissionSet.DoesNotExist:
                pass

        if permissionset:
            permissions_cache[pootle_path] = permissionset.to_dict()
        else:
            permissions_cache[pootle_path] = None

        cache.set(key, permissions_cache, settings.POOTLE_CACHE_TIMEOUT)

    return permissions_cache[pootle_path]
permissions.py 文件源码 项目:zing 作者: evernote 项目源码 文件源码 阅读 69 收藏 0 点赞 0 评论 0
def save(self, *args, **kwargs):
        super(PermissionSet, self).save(*args, **kwargs)
        # FIXME: can we use `post_save` signals or invalidate caches in model
        # managers, please?
        key = iri_to_uri('Permissions:%s' % self.user.username)
        cache.delete(key)
permissions.py 文件源码 项目:zing 作者: evernote 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def delete(self, *args, **kwargs):
        super(PermissionSet, self).delete(*args, **kwargs)
        # FIXME: can we use `post_delete` signals or invalidate caches in model
        # managers, please?
        key = iri_to_uri('Permissions:%s' % self.user.username)
        cache.delete(key)
views.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not url.startswith(('http://', 'https://', 'mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url
models.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
static.py 文件源码 项目:deb-python-coffin 作者: openstack 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_uri_setting(cls, name):
        try:
            from django.conf import settings
        except ImportError:
            prefix = ''
        else:
            prefix = iri_to_uri(getattr(settings, name, ''))
        return prefix
views.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not url.startswith(('http://', 'https://', 'mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url
models.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 62 收藏 0 点赞 0 评论 0
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
endless.py 文件源码 项目:django-endless-pagination-vue 作者: mapeveri 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def show_more(context, label=None, loading=settings.LOADING):
    """Show the link to get the next page in a Twitter-like pagination.

    Usage::

        {% show_more %}

    Alternatively you can override the label passed to the default template::

        {% show_more "even more" %}

    You can override the loading text too::

        {% show_more "even more" "working" %}

    Must be called after ``{% paginate objects %}``.
    """
    # This template tag could raise a PaginationError: you have to call
    # *paginate* or *lazy_paginate* before including the showmore template.
    data = utils.get_data_from_context(context)
    page = data['page']
    # show the template only if there is a next page
    if page.has_next():
        request = context['request']
        page_number = page.next_page_number()
        # Generate the querystring.
        querystring_key = data['querystring_key']
        querystring = utils.get_querystring_for_page(
            request, page_number, querystring_key,
            default_number=data['default_number'])
        return {
            'label': label,
            'loading': loading,
            'path': iri_to_uri(data['override_path'] or request.path),
            'querystring': querystring,
            'querystring_key': querystring_key,
            'request': request,
        }
    # No next page, nothing to see.
    return {}
rest_framework.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def add_query_param(request, key, val):
    """
    Add a query parameter to the current request url, and return the new url.
    """
    iri = request.get_full_path()
    uri = iri_to_uri(iri)
    return escape(replace_query_param(uri, key, val))
views.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not url.startswith(('http://', 'https://', 'mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url
models.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 89 收藏 0 点赞 0 评论 0
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
views.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not (url.startswith('http://')
            or url.startswith('https://')
            or url.startswith('mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url
models.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
rest_framework.py 文件源码 项目:jianshu-api 作者: strugglingyouth 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def add_query_param(request, key, val):
    """
    Add a query parameter to the current request url, and return the new url.
    """
    iri = request.get_full_path()
    uri = iri_to_uri(iri)
    return escape(replace_query_param(uri, key, val))
views.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def add_domain(domain, url, secure=False):
    protocol = 'https' if secure else 'http'
    if url.startswith('//'):
        # Support network-path reference (see #16753) - RSS requires a protocol
        url = '%s:%s' % (protocol, url)
    elif not url.startswith(('http://', 'https://', 'mailto:')):
        url = iri_to_uri('%s://%s%s' % (protocol, domain, url))
    return url


问题


面经


文章

微信
公众号

扫码关注公众号