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


Python builtins.str方法代码示例

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


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

示例1: _handle_text

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def _handle_text(self, msg):
        payload = msg.get_payload()
        if payload is None:
            return
        if not isinstance(payload, str):
            raise TypeError('string payload expected: %s' % type(payload))
        if _has_surrogates(msg._payload):
            charset = msg.get_param('charset')
            if charset is not None:
                del msg['content-transfer-encoding']
                msg.set_payload(payload, charset)
                payload = msg.get_payload()
        if self._mangle_from_:
            payload = fcre.sub('>From ', payload)
        self._write_lines(payload)

    # Default body handler 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:generator.py

示例2: _make_boundary

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def _make_boundary(cls, text=None):
        # Craft a random boundary.  If text is given, ensure that the chosen
        # boundary doesn't appear in the text.
        token = random.randrange(sys.maxsize)
        boundary = ('=' * 15) + (_fmt % token) + '=='
        if text is None:
            return boundary
        b = boundary
        counter = 0
        while True:
            cre = cls._compile_re('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
            if not cre.search(text):
                break
            b = boundary + '.' + str(counter)
            counter += 1
        return b 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:generator.py

示例3: cte_encode

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def cte_encode(self, charset, policy):
        res = []
        last_ew = None
        for part in self:
            spart = str(part)
            try:
                spart.encode('us-ascii')
                res.append(spart)
            except UnicodeEncodeError:
                if last_ew is None:
                    res.append(part.cte_encode(charset, policy))
                    last_ew = len(res)
                else:
                    tl = get_unstructured(''.join(res[last_ew:] + [spart]))
                    res.append(tl.as_encoded_word())
        return ''.join(res) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:_header_value_parser.py

示例4: _fold

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def _fold(self, folded):
        folded.append(str(self.pop(0)))
        folded.lastlen = len(folded.current[0])
        # The first line of the header is different from all others: we don't
        # want to start a new object on a new line if it has any fold points in
        # it that would allow part of it to be on the first header line.
        # Further, if the first fold point would fit on the new line, we want
        # to do that, but if it doesn't we want to put it on the first line.
        # Folded supports this via the stickyspace attribute.  If this
        # attribute is not None, it does the special handling.
        folded.stickyspace = str(self.pop(0)) if self[0].token_type == 'cfws' else ''
        rest = self.pop(0)
        if self:
            raise ValueError("Malformed Header token list")
        rest._fold(folded)


#
# Terminal classes and instances
# 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:22,代码来源:_header_value_parser.py

示例5: _set_content_length

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def _set_content_length(self, body):
        # Set the content-length based on the body.
        thelen = None
        try:
            thelen = str(len(body))
        except TypeError as te:
            # If this is a file-like object, try to
            # fstat its file descriptor
            try:
                thelen = str(os.fstat(body.fileno()).st_size)
            except (AttributeError, OSError):
                # Don't send a length if this failed
                if self.debuglevel > 0: print("Cannot stat!!")

        if thelen is not None:
            self.putheader('Content-Length', thelen) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:client.py

示例6: _send_request

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def _send_request(self, method, url, body, headers):
        # Honor explicitly requested Host: and Accept-Encoding: headers.
        header_names = dict.fromkeys([k.lower() for k in headers])
        skips = {}
        if 'host' in header_names:
            skips['skip_host'] = 1
        if 'accept-encoding' in header_names:
            skips['skip_accept_encoding'] = 1

        self.putrequest(method, url, **skips)

        if body is not None and ('content-length' not in header_names):
            self._set_content_length(body)
        for hdr, value in headers.items():
            self.putheader(hdr, value)
        if isinstance(body, str):
            # RFC 2616 Section 3.7.1 says that text default has a
            # default charset of iso-8859-1.
            body = body.encode('iso-8859-1')
        self.endheaders(body) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:22,代码来源:client.py

示例7: __repr__

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def __repr__(self):
        args = []
        for name in ("version", "name", "value",
                     "port", "port_specified",
                     "domain", "domain_specified", "domain_initial_dot",
                     "path", "path_specified",
                     "secure", "expires", "discard", "comment", "comment_url",
                     ):
            attr = getattr(self, name)
            ### Python-Future:
            # Avoid u'...' prefixes for unicode strings:
            if isinstance(attr, str):
                attr = str(attr)
            ###
            args.append(str("%s=%s") % (name, repr(attr)))
        args.append("rest=%s" % repr(self._rest))
        args.append("rfc2109=%s" % repr(self.rfc2109))
        return "Cookie(%s)" % ", ".join(args) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:20,代码来源:cookiejar.py

示例8: set_ok_port

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def set_ok_port(self, cookie, request):
        if cookie.port_specified:
            req_port = request_port(request)
            if req_port is None:
                req_port = "80"
            else:
                req_port = str(req_port)
            for p in cookie.port.split(","):
                try:
                    int(p)
                except ValueError:
                    _debug("   bad port %s (not numeric)", p)
                    return False
                if p == req_port:
                    break
            else:
                _debug("   request port (%s) not found in %s",
                       req_port, cookie.port)
                return False
        return True 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:22,代码来源:cookiejar.py

示例9: do_GET

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def do_GET(self):
        """Handles the HTTP GET request.

        Interpret all HTTP GET requests as requests for server
        documentation.
        """
        # Check that the path is legal
        if not self.is_rpc_path_valid():
            self.report_404()
            return

        response = self.server.generate_html_documentation().encode('utf-8')
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.send_header("Content-length", str(len(response)))
        self.end_headers()
        self.wfile.write(response) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:server.py

示例10: make_comparable

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def make_comparable(self, other):
        if isinstance(other, DateTime):
            s = self.value
            o = other.value
        elif isinstance(other, datetime):
            s = self.value
            o = _iso8601_format(other)
        elif isinstance(other, str):
            s = self.value
            o = other
        elif hasattr(other, "timetuple"):
            s = self.timetuple()
            o = other.timetuple()
        else:
            otype = (hasattr(other, "__class__")
                     and other.__class__.__name__
                     or type(other))
            raise TypeError("Can't compare %s and %s" %
                            (self.__class__.__name__, otype))
        return s, o 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:22,代码来源:client.py

示例11: send_content

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def send_content(self, connection, request_body):
        #optionally encode the request
        if (self.encode_threshold is not None and
            self.encode_threshold < len(request_body) and
            gzip):
            connection.putheader("Content-Encoding", "gzip")
            request_body = gzip_encode(request_body)

        connection.putheader("Content-Length", str(len(request_body)))
        connection.endheaders(request_body)

    ##
    # Parse response.
    #
    # @param file Stream.
    # @return Response tuple and target method. 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:client.py

示例12: __new__

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def __new__(cls, offset, name=_Omitted):
        if not isinstance(offset, timedelta):
            raise TypeError("offset must be a timedelta")
        if name is cls._Omitted:
            if not offset:
                return cls.utc
            name = None
        elif not isinstance(name, str):
            ###
            # For Python-Future:
            if PY2 and isinstance(name, native_str):
                name = name.decode()
            else:
                raise TypeError("name must be a string")
            ###
        if not cls._minoffset <= offset <= cls._maxoffset:
            raise ValueError("offset must be a timedelta"
                             " strictly between -timedelta(hours=24) and"
                             " timedelta(hours=24).")
        if (offset.microseconds != 0 or
            offset.seconds % 60 != 0):
            raise ValueError("offset must be a timedelta"
                             " representing a whole number of minutes")
        return cls._create(offset, name) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:26,代码来源:datetime.py

示例13: do_GET

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def do_GET(self, send_body=True):
        """Serve a GET request."""
        sock = self.rfile.raw._sock
        context = sock.context
        stats = {
            'session_cache': context.session_stats(),
            'cipher': sock.cipher(),
            'compression': sock.compression(),
            }
        body = pprint.pformat(stats)
        body = body.encode('utf-8')
        self.send_response(200)
        self.send_header("Content-type", "text/plain; charset=utf-8")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        if send_body:
            self.wfile.write(body) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:ssl_servers.py

示例14: __eq__

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def __eq__(self, other):
        # other may be a Header or a string.  Both are fine so coerce
        # ourselves to a unicode (of the unencoded header value), swap the
        # args and do another comparison.
        return other == str(self) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:7,代码来源:header.py

示例15: newline

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import str [as 别名]
def newline(self):
        end_of_line = self._current_line.pop()
        if end_of_line != (' ', ''):
            self._current_line.push(*end_of_line)
        if len(self._current_line) > 0:
            if self._current_line.is_onlyws():
                self._lines[-1] += str(self._current_line)
            else:
                self._lines.append(str(self._current_line))
        self._current_line.reset() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:12,代码来源:header.py


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