migrate to new logging part II
This commit is contained in:
parent
71e85509cb
commit
e1e017fbc8
@ -131,9 +131,8 @@ class ApplicationRunner(object):
|
||||
cfg = ComponentConfig(self.realm, self.extra)
|
||||
try:
|
||||
session = make(cfg)
|
||||
except Exception as e:
|
||||
# the app component could not be created .. fatal
|
||||
print(e)
|
||||
except Exception:
|
||||
self.log.failure("App session could not be created! ")
|
||||
asyncio.get_event_loop().stop()
|
||||
else:
|
||||
session.debug_app = self.debug_app
|
||||
|
@ -86,12 +86,12 @@ class WebSocketAdapterProtocol(asyncio.Protocol):
|
||||
peer = transport.get_extra_info('peername')
|
||||
try:
|
||||
# FIXME: tcp4 vs tcp6
|
||||
self.peer = "tcp:%s:%d" % (peer[0], peer[1])
|
||||
self.peer = u"tcp:%s:%d" % (peer[0], peer[1])
|
||||
except:
|
||||
# e.g. Unix Domain sockets don't have host/port
|
||||
self.peer = "unix:{0}".format(peer)
|
||||
self.peer = u"unix:{0}".format(peer)
|
||||
except:
|
||||
self.peer = "?"
|
||||
self.peer = u"?"
|
||||
|
||||
self._connectionMade()
|
||||
|
||||
@ -107,8 +107,6 @@ class WebSocketAdapterProtocol(asyncio.Protocol):
|
||||
data = self.receive_queue.popleft()
|
||||
if self.transport:
|
||||
self._dataReceived(data)
|
||||
else:
|
||||
print("WebSocketAdapterProtocol._consume: no transport")
|
||||
self._consume()
|
||||
|
||||
self.waiter.add_done_callback(process)
|
||||
|
@ -26,6 +26,9 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import txaio
|
||||
txaio.use_twisted()
|
||||
|
||||
from twisted.python import usage
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
from twisted.internet.protocol import Factory, Protocol
|
||||
@ -35,17 +38,19 @@ from twisted.application import service
|
||||
|
||||
class DestEndpointForwardingProtocol(Protocol):
|
||||
|
||||
log = txaio.make_logger()
|
||||
|
||||
def connectionMade(self):
|
||||
# print("DestEndpointForwardingProtocol.connectionMade")
|
||||
self.log.debug("DestEndpointForwardingProtocol.connectionMade")
|
||||
pass
|
||||
|
||||
def dataReceived(self, data):
|
||||
# print("DestEndpointForwardingProtocol.dataReceived: {0}".format(data))
|
||||
self.log.debug("DestEndpointForwardingProtocol.dataReceived: {0}".format(data))
|
||||
if self.factory._sourceProtocol:
|
||||
self.factory._sourceProtocol.transport.write(data)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
# print("DestEndpointForwardingProtocol.connectionLost")
|
||||
self.log.debug("DestEndpointForwardingProtocol.connectionLost")
|
||||
if self.factory._sourceProtocol:
|
||||
self.factory._sourceProtocol.transport.loseConnection()
|
||||
|
||||
@ -64,21 +69,23 @@ class DestEndpointForwardingFactory(Factory):
|
||||
|
||||
class EndpointForwardingProtocol(Protocol):
|
||||
|
||||
log = txaio.make_logger()
|
||||
|
||||
@inlineCallbacks
|
||||
def connectionMade(self):
|
||||
# print("EndpointForwardingProtocol.connectionMade")
|
||||
self.log.debug("EndpointForwardingProtocol.connectionMade")
|
||||
self._destFactory = DestEndpointForwardingFactory(self)
|
||||
self._destEndpoint = clientFromString(self.factory.service._reactor,
|
||||
self.factory.service._destEndpointDescriptor)
|
||||
self._destEndpointPort = yield self._destEndpoint.connect(self._destFactory)
|
||||
|
||||
def dataReceived(self, data):
|
||||
# print("EndpointForwardingProtocol.dataReceived: {0}".format(data))
|
||||
self.log.debug("EndpointForwardingProtocol.dataReceived: {0}".format(data))
|
||||
if self._destFactory._proto:
|
||||
self._destFactory._proto.transport.write(data)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
# print("EndpointForwardingProtocol.connectionLost")
|
||||
self.log.debug("EndpointForwardingProtocol.connectionLost")
|
||||
if self._destFactory._proto:
|
||||
self._destFactory._proto.transport.loseConnection()
|
||||
|
||||
|
@ -261,7 +261,6 @@ class ApplicationRunner(object):
|
||||
|
||||
def __call__(self, failure):
|
||||
self.exception = failure.value
|
||||
# print(failure.getErrorMessage())
|
||||
reactor.stop()
|
||||
connect_error = ErrorCollector()
|
||||
d.addErrback(connect_error)
|
||||
|
@ -627,9 +627,3 @@ class ObservableMixin(object):
|
||||
if self._parent is not None:
|
||||
res.append(self._parent.fire(event, *args, **kwargs))
|
||||
return txaio.gather(res)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(generate_activation_code())
|
||||
print(generate_serial_number())
|
||||
print(generate_user_password())
|
||||
|
@ -113,7 +113,6 @@ def check_totp(secret, ticket):
|
||||
"""
|
||||
for offset in [0, 1, -1]:
|
||||
if ticket == compute_totp(secret, offset):
|
||||
print("check_totp matched at offset {}".format(offset))
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -404,19 +404,3 @@ class SSHAgentSigningKey(SigningKey):
|
||||
returnValue(signature)
|
||||
|
||||
return d.addCallback(on_connect)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# key = Key.from_raw(sys.argv[1], u'client02@example.com')
|
||||
# key = Key.from_ssh(sys.argv[1])
|
||||
|
||||
with open(u'/home/oberstet/.ssh/id_ed25519.pub', 'r') as f:
|
||||
pubkey = f.read().decode('ascii')
|
||||
|
||||
@inlineCallbacks
|
||||
def test(reactor):
|
||||
key = yield SSHAgentSigningKey.new(pubkey)
|
||||
print(key.public_key())
|
||||
|
||||
from twisted.internet.task import react
|
||||
react(test, [])
|
||||
|
@ -24,7 +24,7 @@
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import
|
||||
|
||||
import traceback
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user