本文整理汇总了Python中twisted.web.http.HTTPChannel类的典型用法代码示例。如果您正苦于以下问题:Python HTTPChannel类的具体用法?Python HTTPChannel怎么用?Python HTTPChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dataReceived
def dataReceived(self, data):
if self.protocol:
# Pass the data off to the real protocol
return self.protocol.dataReceived(data)
# Try to determine the protocol requested
if self.data:
data = self.data + data
self.data = data
self.log.debug("Received %r", data)
if len(data) >= 4:
if "\0" in data:
# Binary data; use DCSP
self.switchProtocol(DaideServerProtocol())
self.transport.setTcpKeepAlive(True)
elif data.startswith("DPP/"):
self.switchProtocol(DppProtocol())
self.transport.setTcpKeepAlive(True)
else:
# Probably text; switch to HTTP
proto = HTTPChannel()
# Simulate Site.buildProtocol()
site = self.factory.site
proto.site = site
proto.requestFactory = site.requestFactory
proto.timeOut = site.timeOut
self.switchProtocol(proto)
示例2: YaybuChannel
class YaybuChannel(channel.SSHChannel):
name = 'session'
def __init__(self, task):
channel.SSHChannel.__init__(self)
self.protocol = HTTPChannel()
self.protocol.requestFactory = self.request_factory
self.protocol.transport = self
self.disconnecting = False
self.task = task
def request_factory(self):
return YaybuRequest(self.task)
def openFailed(self, reason):
print 'echo failed', reason
def channelOpen(self, ignoredData):
self.data = ''
d = self.conn.sendRequest(self, 'exec', common.NS('yaybu --remote -'), wantReply = 1)
#d.addCallback(self._cbRequest)
def _cbRequest(self, ignored):
#self.write('hello conch\n')
#self.conn.sendEOF(self)
pass
def dataReceived(self, data):
self.protocol.dataReceived(data)
def closed(self):
self.loseConnection()
reactor.stop()
示例3: __init__
def __init__(self, counter, method, path, headers, content):
channel = HTTPChannel()
host = IPv4Address(b"TCP", b"127.0.0.1", 80)
channel.makeConnection(StringTransport(hostAddress=host))
Request.__init__(self, channel, False)
# An extra attribute for identifying this fake request
self._counter = counter
# Attributes a Request is supposed to have but we have to set ourselves
# because the base class mixes together too much other logic with the
# code that sets them.
self.prepath = []
self.requestHeaders = headers
self.content = BytesIO(content)
self.requestReceived(method, path, b"HTTP/1.1")
# requestReceived initializes the path attribute for us (but not
# postpath).
self.postpath = list(map(unquote, self.path[1:].split(b'/')))
# Our own notifyFinish / finish state because the inherited
# implementation wants to write confusing stuff to the transport when
# the request gets finished.
self._finished = False
self._finishedChannel = EventChannel()
# Our own state for the response body so we don't have to dig it out of
# the transport.
self._responseBody = b""
示例4: __init__
def __init__(self, task):
channel.SSHChannel.__init__(self)
self.protocol = HTTPChannel()
self.protocol.requestFactory = self.request_factory
self.protocol.transport = self
self.disconnecting = False
self.task = task
示例5: test_client_sends_body
def test_client_sends_body(self):
self.cl.post_json("testserv:8008", "foo/bar", timeout=10000, data={"a": "b"})
self.pump()
clients = self.reactor.tcpClients
self.assertEqual(len(clients), 1)
client = clients[0][2].buildProtocol(None)
server = HTTPChannel()
client.makeConnection(FakeTransport(server, self.reactor))
server.makeConnection(FakeTransport(client, self.reactor))
self.pump(0.1)
self.assertEqual(len(server.requests), 1)
request = server.requests[0]
content = request.content.read()
self.assertEqual(content, b'{"a":"b"}')
示例6: dataReceived
def dataReceived(self, data):
if data.startswith("<policy-file-request/>"):
policy = (
'<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM '
'"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">'
'<cross-domain-policy><allow-access-from domain="*" '
'to-ports="*" /></cross-domain-policy>')
self.transport.write(policy)
self.transport.loseConnection()
else:
return HTTPChannel.dataReceived(self, data)
示例7: __init__
def __init__(self):
HTTPChannel.__init__(self)
示例8: allHeadersReceived
def allHeadersReceived(self):
HTTPChannel.allHeadersReceived(self)
req = self.requests[-1]
if hasattr(req, "requestHeadersReceived"):
req.requestHeadersReceived(self._command,
self._path, self._version)
示例9: connectionLost
def connectionLost(self, reason):
self.site.lostClient()
HTTPChannel.connectionLost(self, reason)
示例10: __init__
def __init__(self):
self.proxyConnection = None
HTTPChannel.__init__(self)
示例11: connectionLost
def connectionLost(self, reason):
HTTPChannel.connectionLost(self, reason)
self.site._lost_client()
示例12: __init__
def __init__(self):
self.ssl_context = tssl.DefaultOpenSSLContextFactory('data/cert/key.pem', 'data/cert/cert.pem')
HTTPChannel.__init__(self)
示例13: connectionLost
def connectionLost(self, reason):
logging.debug("Connection lost from client: " + str(reason))
if (self.proxyConnection is not None):
self.proxyConnection.transport.loseConnection()
HTTPChannel.connectionLost(self, reason)
示例14: __init__
def __init__(self):
HTTPChannel.__init__(self)
self.content_type = None
self.count_line_data = False
self.co = self.dataCoroutine()
self.co.next() # Start up the coroutine
示例15: connectionLost
def connectionLost(self, reason):
print "connectionLost in MyHTTPChannel. channel is ", self
HTTPChannel.connectionLost(self,reason)