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


Python settings.DEFAULT_CHARSET属性代码示例

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


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

示例1: _add_attachments

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def _add_attachments(self, message, msg_dict):
        if not message.attachments:
            return

        str_encoding = message.encoding or settings.DEFAULT_CHARSET
        mj_attachments = []
        mj_inline_attachments = []
        for attachment in message.attachments:
            att_dict, is_inline = self._make_attachment(attachment, str_encoding)
            if is_inline:
                mj_inline_attachments.append(att_dict)
            else:
                mj_attachments.append(att_dict)

        if mj_attachments:
            msg_dict['Attachments'] = mj_attachments
        if mj_inline_attachments:
            msg_dict['Inline_attachments'] = mj_inline_attachments 
开发者ID:kidig,项目名称:django-mailjet,代码行数:20,代码来源:backends.py

示例2: get

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def get(self, request, *args, **kwargs):  # pylint: disable=W0613
        """
        GET request
        """

        index = int(kwargs['index'])
        render_type = kwargs['type']

        obj = registry._registry[index](*registry._registry[index].get_demo_args())  # pylint: disable=W0212

        context = obj.get_context_data()

        content = obj.render(render_type, context)

        render_type = "plain" if render_type == "text" else render_type
        charset = settings.DEFAULT_CHARSET

        return HttpResponse(content, content_type='text/{}; charset={}'.format(render_type, charset)) 
开发者ID:worthwhile,项目名称:django-herald,代码行数:20,代码来源:views.py

示例3: encode_file

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def encode_file(boundary, key, file):
    to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET)
    filename = os.path.basename(file.name) if hasattr(file, 'name') else ''
    if hasattr(file, 'content_type'):
        content_type = file.content_type
    elif filename:
        content_type = mimetypes.guess_type(filename)[0]
    else:
        content_type = None

    if content_type is None:
        content_type = 'application/octet-stream'
    if not filename:
        filename = key
    return [
        to_bytes('--%s' % boundary),
        to_bytes('Content-Disposition: form-data; name="%s"; filename="%s"'
                 % (key, filename)),
        to_bytes('Content-Type: %s' % content_type),
        b'',
        to_bytes(file.read())
    ] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:client.py

示例4: forbid_multi_line_headers

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def forbid_multi_line_headers(name, val, encoding):
    """Forbids multi-line headers, to prevent header injection."""
    encoding = encoding or settings.DEFAULT_CHARSET
    val = force_text(val)
    if '\n' in val or '\r' in val:
        raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))
    try:
        val.encode('ascii')
    except UnicodeEncodeError:
        if name.lower() in ADDRESS_HEADERS:
            val = ', '.join(sanitize_address(addr, encoding)
                for addr in getaddresses((val,)))
        else:
            val = Header(val, encoding).encode()
    else:
        if name.lower() == 'subject':
            val = Header(val).encode()
    return str(name), val 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:message.py

示例5: message

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def message(self):
        encoding = self.encoding or settings.DEFAULT_CHARSET
        msg = SafeMIMEText(self.body, self.content_subtype, encoding)
        msg = self._create_message(msg)
        msg['Subject'] = self.subject
        msg['From'] = self.extra_headers.get('From', self.from_email)
        msg['To'] = self.extra_headers.get('To', ', '.join(self.to))
        if self.cc:
            msg['Cc'] = ', '.join(self.cc)
        if self.reply_to:
            msg['Reply-To'] = self.extra_headers.get('Reply-To', ', '.join(self.reply_to))

        # Email header names are case-insensitive (RFC 2045), so we have to
        # accommodate that when doing comparisons.
        header_names = [key.lower() for key in self.extra_headers]
        if 'date' not in header_names:
            msg['Date'] = formatdate()
        if 'message-id' not in header_names:
            # Use cached DNS_NAME for performance
            msg['Message-ID'] = make_msgid(domain=DNS_NAME)
        for name, value in self.extra_headers.items():
            if name.lower() in ('from', 'to'):  # From and To are already handled
                continue
            msg[name] = value
        return msg 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:message.py

示例6: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def __init__(self, query_string=None, mutable=False, encoding=None):
        super().__init__()
        if not encoding:
            encoding = settings.DEFAULT_CHARSET
        self.encoding = encoding
        query_string = query_string or ''
        parse_qsl_kwargs = {
            'keep_blank_values': True,
            'fields_limit': settings.DATA_UPLOAD_MAX_NUMBER_FIELDS,
            'encoding': encoding,
        }
        if isinstance(query_string, bytes):
            # query_string normally contains URL-encoded data, a subset of ASCII.
            try:
                query_string = query_string.decode(encoding)
            except UnicodeDecodeError:
                # ... but some user agents are misbehaving :-(
                query_string = query_string.decode('iso-8859-1')
        for key, value in limited_parse_qsl(query_string, **parse_qsl_kwargs):
            self.appendlist(key, value)
        self._mutable = mutable 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:request.py

示例7: generic

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def generic(self, method, path, data='',
                content_type='application/octet-stream', secure=False,
                **extra):
        """Construct an arbitrary HTTP request."""
        parsed = urlparse(str(path))  # path can be lazy
        data = force_bytes(data, settings.DEFAULT_CHARSET)
        r = {
            'PATH_INFO': self._get_path(parsed),
            'REQUEST_METHOD': method,
            'SERVER_PORT': '443' if secure else '80',
            'wsgi.url_scheme': 'https' if secure else 'http',
        }
        if data:
            r.update({
                'CONTENT_LENGTH': len(data),
                'CONTENT_TYPE': content_type,
                'wsgi.input': FakePayload(data),
            })
        r.update(extra)
        # If QUERY_STRING is absent or empty, we want to extract it from the URL.
        if not r.get('QUERY_STRING'):
            # WSGI requires latin-1 encoded strings. See get_path_info().
            query_string = force_bytes(parsed[4]).decode('iso-8859-1')
            r['QUERY_STRING'] = query_string
        return self.request(**r) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:client.py

示例8: parse

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def parse(self, stream, media_type=None, parser_context=None):
        """
        Parses the incoming bytestream as XML and returns the resulting data.
        """
        assert etree, "XMLParser requires defusedxml to be installed"

        parser_context = parser_context or {}
        encoding = parser_context.get("encoding", settings.DEFAULT_CHARSET)
        parser = etree.DefusedXMLParser(encoding=encoding)
        try:
            tree = etree.parse(stream, parser=parser, forbid_dtd=True)
        except (etree.ParseError, ValueError) as exc:
            raise ParseError("XML parse error - %s" % str(exc))
        data = self._xml_convert(tree.getroot())

        return data 
开发者ID:jpadilla,项目名称:django-rest-framework-xml,代码行数:18,代码来源:parsers.py

示例9: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def __init__(self, query_string=None, mutable=False, encoding=None):
        super().__init__()
        self.encoding = encoding or settings.DEFAULT_CHARSET
        query_string = query_string or ''
        parse_qsl_kwargs = {
            'keep_blank_values': True,
            'fields_limit': settings.DATA_UPLOAD_MAX_NUMBER_FIELDS,
            'encoding': self.encoding,
        }
        if isinstance(query_string, bytes):
            # query_string normally contains URL-encoded data, a subset of ASCII.
            try:
                query_string = query_string.decode(self.encoding)
            except UnicodeDecodeError:
                # ... but some user agents are misbehaving :-(
                query_string = query_string.decode('iso-8859-1')
        for key, value in limited_parse_qsl(query_string, **parse_qsl_kwargs):
            self.appendlist(key, value)
        self._mutable = mutable 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:21,代码来源:request.py

示例10: generic

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def generic(self, method, path, data='',
                content_type='application/octet-stream', secure=False,
                **extra):
        """Construct an arbitrary HTTP request."""
        parsed = urlparse(str(path))  # path can be lazy
        data = force_bytes(data, settings.DEFAULT_CHARSET)
        r = {
            'PATH_INFO': self._get_path(parsed),
            'REQUEST_METHOD': method,
            'SERVER_PORT': '443' if secure else '80',
            'wsgi.url_scheme': 'https' if secure else 'http',
        }
        if data:
            r.update({
                'CONTENT_LENGTH': len(data),
                'CONTENT_TYPE': content_type,
                'wsgi.input': FakePayload(data),
            })
        r.update(extra)
        # If QUERY_STRING is absent or empty, we want to extract it from the URL.
        if not r.get('QUERY_STRING'):
            # WSGI requires latin-1 encoded strings. See get_path_info().
            query_string = parsed[4].encode().decode('iso-8859-1')
            r['QUERY_STRING'] = query_string
        return self.request(**r) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:27,代码来源:client.py

示例11: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def __init__(self, query_string, mutable=False, encoding=None):
        super(QueryDict, self).__init__()
        if not encoding:
            encoding = settings.DEFAULT_CHARSET
        self.encoding = encoding
        if six.PY3:
            if isinstance(query_string, bytes):
                # query_string contains URL-encoded data, a subset of ASCII.
                query_string = query_string.decode()
            for key, value in parse_qsl(query_string or '',
                                        keep_blank_values=True,
                                        encoding=encoding):
                self.appendlist(key, value)
        else:
            for key, value in parse_qsl(query_string or '',
                                        keep_blank_values=True):
                self.appendlist(force_text(key, encoding, errors='replace'),
                                force_text(value, encoding, errors='replace'))
        self._mutable = mutable 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:request.py

示例12: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def __init__(self, content_type=None, status=None, mimetype=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._charset = settings.DEFAULT_CHARSET
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        if mimetype:
            warnings.warn("Using mimetype keyword argument is deprecated, use"
                          " content_type instead", PendingDeprecationWarning)
            content_type = mimetype
        if not content_type:
            content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
                    self._charset)
        self.cookies = SimpleCookie()
        if status:
            self.status_code = status

        self['Content-Type'] = content_type 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:response.py

示例13: generic

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def generic(self, method, path,
                data='', content_type='application/octet-stream', **extra):
        parsed = urlparse(path)
        data = force_bytes(data, settings.DEFAULT_CHARSET)
        r = {
            'PATH_INFO':      self._get_path(parsed),
            'QUERY_STRING':   force_str(parsed[4]),
            'REQUEST_METHOD': str(method),
        }
        if data:
            r.update({
                'CONTENT_LENGTH': len(data),
                'CONTENT_TYPE':   str(content_type),
                'wsgi.input':     FakePayload(data),
            })
        r.update(extra)
        return self.request(**r) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:19,代码来源:client.py

示例14: message

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def message(self):
        encoding = self.encoding or settings.DEFAULT_CHARSET
        msg = SafeMIMEText(self.body, self.content_subtype, encoding)
        msg = self._create_message(msg)
        msg['Subject'] = self.subject
        msg['From'] = self.extra_headers.get('From', self.from_email)
        msg['To'] = self.extra_headers.get('To', ', '.join(self.to))
        if self.cc:
            msg['Cc'] = ', '.join(self.cc)

        # Email header names are case-insensitive (RFC 2045), so we have to
        # accommodate that when doing comparisons.
        header_names = [key.lower() for key in self.extra_headers]
        if 'date' not in header_names:
            msg['Date'] = formatdate()
        if 'message-id' not in header_names:
            msg['Message-ID'] = make_msgid()
        for name, value in self.extra_headers.items():
            if name.lower() in ('from', 'to'):  # From and To are already handled
                continue
            msg[name] = value
        return msg 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:message.py

示例15: parse

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CHARSET [as 别名]
def parse(self, stream, media_type=None, parser_context=None):
        """
        Parses the incoming bytestream as a multipart encoded form,
        and returns a DataAndFiles object.

        `.data` will be a `QueryDict` containing all the form parameters.
        `.files` will be a `QueryDict` containing all the form files.
        """
        parser_context = parser_context or {}
        request = parser_context['request']
        encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
        meta = request.META.copy()
        meta['CONTENT_TYPE'] = media_type
        upload_handlers = request.upload_handlers

        try:
            parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding)
            data, files = parser.parse()
            return DataAndFiles(data, files)
        except MultiPartParserError as exc:
            raise ParseError('Multipart form parse error - %s' % six.text_type(exc)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:23,代码来源:parsers.py


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