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


Python compat.unicode方法代码示例

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


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

示例1: escapeForContent

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def escapeForContent(data):
    """
    Escape some character or UTF-8 byte data for inclusion in an HTML or XML
    document, by replacing metacharacters (C{&<>}) with their entity
    equivalents (C{&amp;&lt;&gt;}).

    This is used as an input to L{_flattenElement}'s C{dataEscaper} parameter.

    @type data: C{bytes} or C{unicode}
    @param data: The string to escape.

    @rtype: C{bytes}
    @return: The quoted form of C{data}.  If C{data} is unicode, return a utf-8
        encoded string.
    """
    if isinstance(data, unicode):
        data = data.encode('utf-8')
    data = data.replace(b'&', b'&amp;'
        ).replace(b'<', b'&lt;'
        ).replace(b'>', b'&gt;')
    return data 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:_flatten.py

示例2: attributeEscapingDoneOutside

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def attributeEscapingDoneOutside(data):
    """
    Escape some character or UTF-8 byte data for inclusion in the top level of
    an attribute.  L{attributeEscapingDoneOutside} actually passes the data
    through unchanged, because L{writeWithAttributeEscaping} handles the
    quoting of the text within attributes outside the generator returned by
    L{_flattenElement}; this is used as the C{dataEscaper} argument to that
    L{_flattenElement} call so that that generator does not redundantly escape
    its text output.

    @type data: C{bytes} or C{unicode}
    @param data: The string to escape.

    @return: The string, unchanged, except for encoding.
    @rtype: C{bytes}
    """
    if isinstance(data, unicode):
        return data.encode("utf-8")
    return data 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:_flatten.py

示例3: __init__

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def __init__(self, url, fileOrName,
                 method=b'GET', postdata=None, headers=None,
                 agent=b"Twisted client", supportPartial=False,
                 timeout=0, cookies=None, followRedirect=True,
                 redirectLimit=20, afterFoundGet=False):
        self.requestedPartial = 0
        if isinstance(fileOrName, (str, unicode)):
            self.fileName = fileOrName
            self.file = None
            if supportPartial and os.path.exists(self.fileName):
                fileLength = os.path.getsize(self.fileName)
                if fileLength:
                    self.requestedPartial = fileLength
                    if headers == None:
                        headers = {}
                    headers[b"range"] = b"bytes=" + intToBytes(fileLength) + b"-"
        else:
            self.file = fileOrName
        HTTPClientFactory.__init__(
            self, url, method=method, postdata=postdata, headers=headers,
            agent=agent, timeout=timeout, cookies=cookies,
            followRedirect=followRedirect, redirectLimit=redirectLimit,
            afterFoundGet=afterFoundGet) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:client.py

示例4: test_nameEncoding

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def test_nameEncoding(self):
        """
        Passing L{unicode} to any function that takes a header name will encode
        said header name as ISO-8859-1.
        """
        h = Headers()

        # We set it using a Unicode string.
        h.setRawHeaders(u"\u00E1", [b"foo"])

        # It's encoded to the ISO-8859-1 value, which we can use to access it
        self.assertTrue(h.hasHeader(b"\xe1"))
        self.assertEqual(h.getRawHeaders(b"\xe1"), [b'foo'])

        # We can still access it using the Unicode string..
        self.assertTrue(h.hasHeader(u"\u00E1")) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_http_headers.py

示例5: _encodeValues

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def _encodeValues(self, values):
        """
        Encode a L{list} of header values to a L{list} of UTF-8 encoded
        bytestrings if required.

        @param values: A list of HTTP header values.
        @type values: L{list} of L{bytes} or L{unicode} (mixed types allowed)

        @return: C{values}, with each item encoded if required
        @rtype: L{list} of L{bytes}
        """
        newValues = []

        for value in values:
            newValues.append(self._encodeValue(value))
        return newValues 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:http_headers.py

示例6: addRawHeader

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def addRawHeader(self, name, value):
        """
        Add a new raw value for the given header.

        @type name: L{bytes} or L{unicode}
        @param name: The name of the header for which to set the value.

        @type value: L{bytes} or L{unicode}
        @param value: The value to set for the named header.
        """
        values = self.getRawHeaders(name)

        if values is not None:
            values.append(value)
        else:
            values = [value]

        self.setRawHeaders(name, values) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:http_headers.py

示例7: getRawHeaders

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def getRawHeaders(self, name, default=None):
        """
        Returns a list of headers matching the given name as the raw string
        given.

        @type name: L{bytes} or L{unicode}
        @param name: The name of the HTTP header to get the values of.

        @param default: The value to return if no header with the given C{name}
            exists.

        @rtype: L{list} of strings, same type as C{name} (except when
            C{default} is returned).
        @return: If the named header is present, a L{list} of its
            values.  Otherwise, C{default}.
        """
        encodedName = self._encodeName(name)
        values = self._rawHeaders.get(encodedName, default)

        if isinstance(name, unicode) and values is not default:
            return self._decodeValues(values)
        return values 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:http_headers.py

示例8: _stringTags

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def _stringTags(self, tags):
        """
        Converts a tag dictionary to a string.

        @param tags: The tag dict passed to sendMsg.

        @rtype: L{unicode}
        @return: IRCv3-format tag string
        """
        self._validateTags(tags)
        tagStrings = []
        for tag, value in tags.items():
            if value:
                tagStrings.append("%s=%s" % (tag, self._escapeTagValue(value)))
            else:
                tagStrings.append(tag)
        return ";".join(tagStrings) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:irc.py

示例9: privmsg

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def privmsg(self, sender, recip, message):
        """
        Send a message to a channel or user

        @type sender: C{str} or C{unicode}
        @param sender: Who is sending this message.  Should be of the form
            username!ident@hostmask (unless you know better!).

        @type recip: C{str} or C{unicode}
        @param recip: The recipient of this message.  If a channel, it must
            start with a channel prefix.

        @type message: C{str} or C{unicode}
        @param message: The message being sent.
        """
        self.sendCommand("PRIVMSG", (recip, ":%s" % (lowQuote(message),)), sender) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:irc.py

示例10: notice

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def notice(self, sender, recip, message):
        """
        Send a "notice" to a channel or user.

        Notices differ from privmsgs in that the RFC claims they are different.
        Robots are supposed to send notices and not respond to them.  Clients
        typically display notices differently from privmsgs.

        @type sender: C{str} or C{unicode}
        @param sender: Who is sending this message.  Should be of the form
            username!ident@hostmask (unless you know better!).

        @type recip: C{str} or C{unicode}
        @param recip: The recipient of this message.  If a channel, it must
            start with a channel prefix.

        @type message: C{str} or C{unicode}
        @param message: The message being sent.
        """
        self.sendCommand("NOTICE", (recip, ":%s" % (message,)), sender) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:irc.py

示例11: topicAuthor

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def topicAuthor(self, user, channel, author, date):
        """
        Send the author of and time at which a topic was set for the given
        channel.

        This sends a 333 reply message, which is not part of the IRC RFC.

        @type user: C{str} or C{unicode}
        @param user: The user receiving the topic.  Only their nickname, not
            the full hostmask.

        @type channel: C{str} or C{unicode}
        @param channel: The channel for which this information is relevant.

        @type author: C{str} or C{unicode}
        @param author: The nickname (without hostmask) of the user who last set
            the topic.

        @type date: C{int}
        @param date: A POSIX timestamp (number of seconds since the epoch) at
            which the topic was last set.
        """
        self.sendLine(':%s %d %s %s %s %d' % (
            self.hostname, 333, user, channel, author, date)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:irc.py

示例12: part

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def part(self, who, where, reason=None):
        """
        Send a part message.

        @type who: C{str} or C{unicode}
        @param who: The name of the user joining.  Should be of the form
            username!ident@hostmask (unless you know better!).

        @type where: C{str} or C{unicode}
        @param where: The channel the user is joining.

        @type reason: C{str} or C{unicode}
        @param reason: A string describing the misery which caused this poor
            soul to depart.
        """
        if reason:
            self.sendLine(":%s PART %s :%s" % (who, where, reason))
        else:
            self.sendLine(":%s PART %s" % (who, where)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:irc.py

示例13: channelMode

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def channelMode(self, user, channel, mode, *args):
        """
        Send information about the mode of a channel.

        @type user: C{str} or C{unicode}
        @param user: The user receiving the name list.  Only their nickname,
            not the full hostmask.

        @type channel: C{str} or C{unicode}
        @param channel: The channel for which this is the namelist.

        @type mode: C{str}
        @param mode: A string describing this channel's modes.

        @param args: Any additional arguments required by the modes.
        """
        self.sendLine(":%s %s %s %s %s %s" % (
            self.hostname, RPL_CHANNELMODEIS, user, channel, mode, ' '.join(args))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:irc.py

示例14: _cbAuthQuery

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def _cbAuthQuery(self, iq):
        jid = self.xmlstream.authenticator.jid
        password = _coercedUnicode(self.xmlstream.authenticator.password)

        # Construct auth request
        reply = xmlstream.IQ(self.xmlstream, "set")
        reply.addElement(("jabber:iq:auth", "query"))
        reply.query.addElement("username", content = jid.user)
        reply.query.addElement("resource", content = jid.resource)

        # Prefer digest over plaintext
        if DigestAuthQry.matches(iq):
            digest = xmlstream.hashPassword(self.xmlstream.sid, password)
            reply.query.addElement("digest", content=unicode(digest))
        else:
            reply.query.addElement("password", content = password)

        d = reply.send()
        d.addCallbacks(self._cbAuth, self._ebAuth)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:client.py

示例15: XMPPClientFactory

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import unicode [as 别名]
def XMPPClientFactory(jid, password):
    """
    Client factory for XMPP 1.0 (only).

    This returns a L{xmlstream.XmlStreamFactory} with an L{XMPPAuthenticator}
    object to perform the stream initialization steps (such as authentication).

    @see: The notes at L{XMPPAuthenticator} describe how the L{jid} and
    L{password} parameters are to be used.

    @param jid: Jabber ID to connect with.
    @type jid: L{jid.JID}
    @param password: password to authenticate with.
    @type password: L{unicode}
    @return: XML stream factory.
    @rtype: L{xmlstream.XmlStreamFactory}
    """
    a = XMPPAuthenticator(jid, password)
    return xmlstream.XmlStreamFactory(a) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:client.py


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