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


Python encoding.iri_to_uri方法代码示例

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


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

示例1: _get_cache_key

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def _get_cache_key(self, request):
        """
        Generate cache key that's exactly unique enough.

        Assumes that the response is determined by the request.method, authenticated user, and URL path.
        """
        # HTTP method
        method = request.method

        # Authenticated username
        if not request.user.is_authenticated or self.cache_ignore_auth:
            username = '*'
        else:
            username = request.user.username

        # URL path
        url = force_text(iri_to_uri(request.get_full_path()))

        # build a cache key out of that
        key = '#'.join(('CacheMixin', self.key_prefix, username, method, url))
        if len(key) > MAX_KEY_LENGTH:
            # make sure keys don't get too long
            key = key[:(MAX_KEY_LENGTH - 33)] + '-' + hashlib.md5(key.encode('utf8')).hexdigest()

        return key 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:rest.py

示例2: __init__

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def __init__(self, title, link, description, language=None, author_email=None,
                 author_name=None, author_link=None, subtitle=None, categories=None,
                 feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
        def to_str(s):
            return str(s) if s is not None else s
        if categories:
            categories = [str(c) for c in categories]
        self.feed = {
            'title': to_str(title),
            'link': iri_to_uri(link),
            'description': to_str(description),
            'language': to_str(language),
            'author_email': to_str(author_email),
            'author_name': to_str(author_name),
            'author_link': iri_to_uri(author_link),
            'subtitle': to_str(subtitle),
            'categories': categories or (),
            'feed_url': iri_to_uri(feed_url),
            'feed_copyright': to_str(feed_copyright),
            'id': feed_guid or link,
            'ttl': to_str(ttl),
        }
        self.feed.update(kwargs)
        self.items = [] 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:26,代码来源:feedgenerator.py

示例3: build_absolute_uri

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def build_absolute_uri(self, location=None):
        """
        Build an absolute URI from the location and the variables available in
        this request. If no ``location`` is specified, bulid the absolute URI
        using request.get_full_path(). If the location is absolute, convert it
        to an RFC 3987 compliant URI and return it. If location is relative or
        is scheme-relative (i.e., ``//example.com/``), urljoin() it to a base
        URL constructed from the request variables.
        """
        if location is None:
            # Make it an absolute url (but schemeless and domainless) for the
            # edge case that the path starts with '//'.
            location = '//%s' % self.get_full_path()
        bits = urlsplit(location)
        if not (bits.scheme and bits.netloc):
            current_uri = '{scheme}://{host}{path}'.format(scheme=self.scheme,
                                                           host=self.get_host(),
                                                           path=self.path)
            # Join the constructed URL with the provided location, which will
            # allow the provided ``location`` to apply query strings to the
            # base path as well as override the host, if it begins with //
            location = urljoin(current_uri, location)
        return iri_to_uri(location) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:25,代码来源:request.py

示例4: __init__

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def __init__(self, metadata, instances, path, site=None, language=None, subdomain=None):
        self.__metadata = metadata
        if metadata._meta.use_cache:
            if metadata._meta.use_sites and site:
                hexpath = hashlib.md5(iri_to_uri(site.domain + path).encode('utf-8')).hexdigest()
            else:
                hexpath = hashlib.md5(iri_to_uri(path).encode('utf-8')).hexdigest()
            prefix_bits = ['djangoseo', self.__metadata.__class__.__name__, hexpath]
            if metadata._meta.use_i18n:
                prefix_bits.append(language)
            if metadata._meta.use_subdomains and subdomain is not None:
                prefix_bits.append(subdomain)
            self.__cache_prefix = '.'.join(prefix_bits)
        else:
            self.__cache_prefix = None
        self.__instances_original = instances
        self.__instances_cache = [] 
开发者ID:whyflyru,项目名称:django-seo,代码行数:19,代码来源:base.py

示例5: __init__

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def __init__(self, request, number, current_number, *args, **kwargs):
        total_number = kwargs.get('total_number')
        querystring_key = kwargs.get('querystring_key', 'page')
        label = kwargs.get('label', None)
        default_number = kwargs.get('default_number', 1)
        override_path = kwargs.get('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) 
开发者ID:MicroPyramid,项目名称:django-simple-pagination,代码行数:22,代码来源:models.py

示例6: __init__

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def __init__(self, title, link, description, language=None, author_email=None,
                 author_name=None, author_link=None, subtitle=None, categories=None,
                 feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
        def to_str(s):
            return str(s) if s is not None else s
        categories = categories and [str(c) for c in categories]
        self.feed = {
            'title': to_str(title),
            'link': iri_to_uri(link),
            'description': to_str(description),
            'language': to_str(language),
            'author_email': to_str(author_email),
            'author_name': to_str(author_name),
            'author_link': iri_to_uri(author_link),
            'subtitle': to_str(subtitle),
            'categories': categories or (),
            'feed_url': iri_to_uri(feed_url),
            'feed_copyright': to_str(feed_copyright),
            'id': feed_guid or link,
            'ttl': to_str(ttl),
            **kwargs,
        }
        self.items = [] 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:25,代码来源:feedgenerator.py

示例7: handle_simple

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def handle_simple(cls, name):
        try:
            from django.conf import settings
        except ImportError:
            prefix = ''
        else:
            prefix = iri_to_uri(getattr(settings, name, ''))
        return prefix 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:static.py

示例8: __init__

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def __init__(self, title, link, description, language=None, author_email=None,
            author_name=None, author_link=None, subtitle=None, categories=None,
            feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
        to_unicode = lambda s: force_text(s, strings_only=True)
        if categories:
            categories = [force_text(c) for c in categories]
        if ttl is not None:
            # Force ints to unicode
            ttl = force_text(ttl)
        self.feed = {
            'title': to_unicode(title),
            'link': iri_to_uri(link),
            'description': to_unicode(description),
            'language': to_unicode(language),
            'author_email': to_unicode(author_email),
            'author_name': to_unicode(author_name),
            'author_link': iri_to_uri(author_link),
            'subtitle': to_unicode(subtitle),
            'categories': categories or (),
            'feed_url': iri_to_uri(feed_url),
            'feed_copyright': to_unicode(feed_copyright),
            'id': feed_guid or link,
            'ttl': ttl,
        }
        self.feed.update(kwargs)
        self.items = [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:28,代码来源:feedgenerator.py

示例9: add_item

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def add_item(self, title, link, description, author_email=None,
            author_name=None, author_link=None, pubdate=None, comments=None,
            unique_id=None, unique_id_is_permalink=None, enclosure=None,
            categories=(), item_copyright=None, ttl=None, updateddate=None, **kwargs):
        """
        Adds an item to the feed. All args are expected to be Python Unicode
        objects except pubdate and updateddate, which are datetime.datetime
        objects, and enclosure, which is an instance of the Enclosure class.
        """
        to_unicode = lambda s: force_text(s, strings_only=True)
        if categories:
            categories = [to_unicode(c) for c in categories]
        if ttl is not None:
            # Force ints to unicode
            ttl = force_text(ttl)
        item = {
            'title': to_unicode(title),
            'link': iri_to_uri(link),
            'description': to_unicode(description),
            'author_email': to_unicode(author_email),
            'author_name': to_unicode(author_name),
            'author_link': iri_to_uri(author_link),
            'pubdate': pubdate,
            'updateddate': updateddate,
            'comments': to_unicode(comments),
            'unique_id': to_unicode(unique_id),
            'unique_id_is_permalink': unique_id_is_permalink,
            'enclosure': enclosure,
            'categories': categories or (),
            'item_copyright': to_unicode(item_copyright),
            'ttl': ttl,
        }
        item.update(kwargs)
        self.items.append(item) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:36,代码来源:feedgenerator.py

示例10: _generate_cache_key

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
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, None)
        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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:cache.py

示例11: iriencode

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def iriencode(value):
    """Escapes an IRI value for use in a URL."""
    return force_text(iri_to_uri(value)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:defaultfilters.py

示例12: add_domain

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:views.py

示例13: get_absolute_url

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:models.py

示例14: add_item

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def add_item(self, title, link, description, author_email=None,
                 author_name=None, author_link=None, pubdate=None, comments=None,
                 unique_id=None, unique_id_is_permalink=None, categories=(),
                 item_copyright=None, ttl=None, updateddate=None, enclosures=None, **kwargs):
        """
        Add an item to the feed. All args are expected to be strings except
        pubdate and updateddate, which are datetime.datetime objects, and
        enclosures, which is an iterable of instances of the Enclosure class.
        """
        def to_str(s):
            return str(s) if s is not None else s
        if categories:
            categories = [to_str(c) for c in categories]
        item = {
            'title': to_str(title),
            'link': iri_to_uri(link),
            'description': to_str(description),
            'author_email': to_str(author_email),
            'author_name': to_str(author_name),
            'author_link': iri_to_uri(author_link),
            'pubdate': pubdate,
            'updateddate': updateddate,
            'comments': to_str(comments),
            'unique_id': to_str(unique_id),
            'unique_id_is_permalink': unique_id_is_permalink,
            'enclosures': enclosures or (),
            'categories': categories or (),
            'item_copyright': to_str(item_copyright),
            'ttl': to_str(ttl),
        }
        item.update(kwargs)
        self.items.append(item) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:34,代码来源:feedgenerator.py

示例15: _generate_cache_key

# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import iri_to_uri [as 别名]
def _generate_cache_key(request, method, headerlist, key_prefix):
    """Return 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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:cache.py


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