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


Python compat.nativeString方法代码示例

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


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

示例1: _prePathURL

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def _prePathURL(self, prepath):
        port = self.getHost().port
        if self.isSecure():
            default = 443
        else:
            default = 80
        if port == default:
            hostport = ''
        else:
            hostport = ':%d' % port
        prefix = networkString('http%s://%s%s/' % (
            self.isSecure() and 's' or '',
            nativeString(self.getRequestHostname()),
            hostport))
        path = b'/'.join([quote(segment, safe=b'') for segment in prepath])
        return prefix + path 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:server.py

示例2: __init__

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def __init__(self, uri):
        """
        Create a fake Urllib2 request.

        @param uri: Request URI.
        @type uri: L{bytes}
        """
        self.uri = nativeString(uri)
        self.headers = Headers()

        _uri = URI.fromBytes(uri)
        self.type = nativeString(_uri.scheme)
        self.host = nativeString(_uri.host)

        if (_uri.scheme, _uri.port) not in ((b'http', 80), (b'https', 443)):
            # If it's not a schema on the regular port, add the port.
            self.host += ":" + str(_uri.port)

        if _PY3:
            self.origin_req_host = nativeString(_uri.host)
            self.unverifiable = lambda _: False 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:client.py

示例3: inspect

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def inspect(self):
        """
        Return a multi-line, human-readable representation of this DN.

        @rtype: L{str}
        """
        l = []
        lablen = 0
        def uniqueValues(mapping):
            return set(mapping.values())
        for k in sorted(uniqueValues(_x509names)):
            label = util.nameToLabel(k)
            lablen = max(len(label), lablen)
            v = getattr(self, k, None)
            if v is not None:
                l.append((label, nativeString(v)))
        lablen += 2
        for n, (label, attr) in enumerate(l):
            l[n] = (label.rjust(lablen)+': '+ attr)
        return '\n'.join(l) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:_sslverify.py

示例4: connect

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def connect(self):
        """Start connection to remote server."""
        self.factory.doStart()
        self.factory.startedConnecting(self)

        if not self.servers:
            if self.domain is None:
                self.connectionFailed(error.DNSLookupError("Domain is not defined."))
                return
            d = client.lookupService('_%s._%s.%s' %
                    (nativeString(self.service),
                     nativeString(self.protocol),
                     self.domain))
            d.addCallbacks(self._cbGotServers, self._ebGotServers)
            d.addCallback(lambda x, self=self: self._reallyConnect())
            if self._defaultPort:
                d.addErrback(self._ebServiceUnknown)
            d.addErrback(self.connectionFailed)
        elif self.connector is None:
            self._reallyConnect()
        else:
            self.connector.connect() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:srvconnect.py

示例5: loadFile

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def loadFile(self, filename):
        """
        Load records from C{filename}.

        @param filename: file to read from
        @type filename: L{bytes}
        """
        fp = FilePath(filename)
        # Not the best way to set an origin. It can be set using $ORIGIN
        # though.
        self.origin = nativeString(fp.basename() + b'.')

        lines = fp.getContent().splitlines(True)
        lines = self.stripComments(lines)
        lines = self.collapseContinuations(lines)
        self.parseLines(lines) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:authority.py

示例6: parseConfig

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def parseConfig(self, resolvConf):
        servers = []
        for L in resolvConf:
            L = L.strip()
            if L.startswith(b'nameserver'):
                resolver = (nativeString(L.split()[1]), dns.PORT)
                servers.append(resolver)
                log.msg("Resolver added %r to server list" % (resolver,))
            elif L.startswith(b'domain'):
                try:
                    self.domain = L.split()[1]
                except IndexError:
                    self.domain = b''
                self.search = None
            elif L.startswith(b'search'):
                self.search = L.split()[1:]
                self.domain = None
        if not servers:
            servers.append(('127.0.0.1', dns.PORT))
        self.dynServers = servers 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:client.py

示例7: secureConnection

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def secureConnection(self):
        """
        Create and return a new SSH connection which has been secured and on
        which authentication has already happened.

        @return: A L{Deferred} which fires with the ready-to-use connection or
            with a failure if something prevents the connection from being
            setup, secured, or authenticated.
        """
        protocol = _CommandTransport(self)
        ready = protocol.connectionReady

        sshClient = TCP4ClientEndpoint(
            self.reactor, nativeString(self.hostname), self.port)

        d = connectProtocol(sshClient, protocol)
        d.addCallback(lambda ignored: ready)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:endpoints.py

示例8: test_getPasswordPrompt

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def test_getPasswordPrompt(self):
        """
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        using a different prompt.
        """
        options = ConchOptions()
        client = SSHUserAuthClient(b"user",  options, None)
        prompt = b"Give up your password"

        def getpass(p):
            self.assertEqual(p, nativeString(prompt))
            return 'bad password'

        self.patch(default.getpass, 'getpass', getpass)
        d = client.getPassword(prompt)
        d.addCallback(self.assertEqual, b'bad password')
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_default.py

示例9: requestReceived

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def requestReceived(self, requestType, data):
        """
        Called when a request is sent to this channel.  By default it delegates
        to self.request_<requestType>.
        If this function returns true, the request succeeded, otherwise it
        failed.

        @type requestType:  L{bytes}
        @type data:         L{bytes}
        @rtype:             L{bool}
        """
        foo = nativeString(requestType.replace(b'-', b'_'))
        f = getattr(self, 'request_%s'%foo, None)
        if f:
            return f(data)
        log.msg('unhandled request for %s'%requestType)
        return 0 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:channel.py

示例10: makeCertificate

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def makeCertificate(**kw):
    keypair = PKey()
    keypair.generate_key(TYPE_RSA, 768)

    certificate = X509()
    certificate.gmtime_adj_notBefore(0)
    certificate.gmtime_adj_notAfter(60 * 60 * 24 * 365) # One year
    for xname in certificate.get_issuer(), certificate.get_subject():
        for (k, v) in kw.items():
            setattr(xname, k, nativeString(v))

    certificate.set_serial_number(counter())
    certificate.set_pubkey(keypair)
    certificate.sign(keypair, "md5")

    return keypair, certificate 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_sslverify.py

示例11: test_emptyChildUnicodeParent

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def test_emptyChildUnicodeParent(self):
        """
        The C{u''} child of a L{File} which corresponds to a directory
        whose path is text is a L{DirectoryLister} that renders to a
        binary listing.

        @see: U{https://twistedmatrix.com/trac/ticket/9438}
        """
        textBase = FilePath(self.mktemp()).asTextMode()
        textBase.makedirs()
        textBase.child(u"text-file").open('w').close()
        textFile = static.File(textBase.path)

        request = DummyRequest([b''])
        child = resource.getChildForRequest(textFile, request)
        self.assertIsInstance(child, static.DirectoryLister)

        nativePath = compat.nativeString(textBase.path)
        self.assertEqual(child.path, nativePath)

        response = child.render(request)
        self.assertIsInstance(response, bytes) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:24,代码来源:test_static.py

示例12: log

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def log(self, request):
        """
        Redirect logging of HTTPFactory.

        @param request: The request object about which to log.
        @type request: L{Request}
        """
        line = u'HTTP access: ' + self._logFormatter(self._logDateTime, request)
        if hasattr(self, '_nativeize') and self._nativeize:
            line = nativeString(line)
        else:
            line = line.encode("utf-8")
        log.debug(line) 
开发者ID:daq-tools,项目名称:kotori,代码行数:15,代码来源:http.py

示例13: decode_consumermetadata_response

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def decode_consumermetadata_response(cls, data):
        """
        Decode bytes to a ConsumerMetadataResponse

        :param bytes data: bytes to decode
        """
        (correlation_id, error_code, node_id), cur = \
            relative_unpack('>ihi', data, 0)
        host, cur = read_short_ascii(data, cur)
        (port,), cur = relative_unpack('>i', data, cur)

        return ConsumerMetadataResponse(
            error_code, node_id, nativeString(host), port) 
开发者ID:ciena,项目名称:afkak,代码行数:15,代码来源:kafkacodec.py

示例14: redirectTo

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def redirectTo(URL, request):
    """
    Generate a redirect to the given location.

    @param URL: A L{bytes} giving the location to which to redirect.
    @type URL: L{bytes}

    @param request: The request object to use to generate the redirect.
    @type request: L{IRequest<twisted.web.iweb.IRequest>} provider

    @raise TypeError: If the type of C{URL} a L{unicode} instead of L{bytes}.

    @return: A C{bytes} containing HTML which tries to convince the client agent
        to visit the new location even if it doesn't respect the I{FOUND}
        response code.  This is intended to be returned from a render method,
        eg::

            def render_GET(self, request):
                return redirectTo(b"http://example.com/", request)
    """
    if isinstance(URL, unicode) :
        raise TypeError("Unicode object not allowed as URL")
    request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
    request.redirect(URL)
    content =  """
<html>
    <head>
        <meta http-equiv=\"refresh\" content=\"0;URL=%(url)s\">
    </head>
    <body bgcolor=\"#FFFFFF\" text=\"#000000\">
    <a href=\"%(url)s\">click here</a>
    </body>
</html>
""" % {'url': nativeString(URL)}
    if _PY3:
        content = content.encode("utf8")
    return content 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:39,代码来源:util.py

示例15: handleEndHeaders

# 需要导入模块: from twisted.python import compat [as 别名]
# 或者: from twisted.python.compat import nativeString [as 别名]
def handleEndHeaders(self):
        self.factory.gotHeaders(self.headers)
        m = getattr(self, 'handleStatus_' + nativeString(self.status),
                    self.handleStatusDefault)
        m() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:client.py


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