當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。