Commit 01f5f3a2 by Bach Dániel

fix flake8 errors

parent 6f02b486
...@@ -129,6 +129,6 @@ if __name__ == "__main__": ...@@ -129,6 +129,6 @@ if __name__ == "__main__":
logging.basicConfig(level=opts.loglevel) logging.basicConfig(level=opts.loglevel)
resource = File('.') resource = File('.')
resource.putChild('vnc', WebSocketsResource( resource.putChild('vnc', WebSocketsResource(
lookupProtocolForFactory(VNCWebSocketFactory()))) lookupProtocolForFactory(VNCWebSocketFactory())))
reactor.listenTCP(9999, Site(resource)) reactor.listenTCP(9999, Site(resource))
reactor.run() reactor.run()
...@@ -31,14 +31,12 @@ from twisted.web.resource import IResource ...@@ -31,14 +31,12 @@ from twisted.web.resource import IResource
from twisted.web.server import NOT_DONE_YET from twisted.web.server import NOT_DONE_YET
class _WSException(Exception): class _WSException(Exception):
""" """
Internal exception for control flow inside the WebSockets frame parser. Internal exception for control flow inside the WebSockets frame parser.
""" """
class CONTROLS(Values): class CONTROLS(Values):
""" """
Control frame specifiers. Control frame specifiers.
...@@ -54,7 +52,6 @@ class CONTROLS(Values): ...@@ -54,7 +52,6 @@ class CONTROLS(Values):
PONG = ValueConstant(10) PONG = ValueConstant(10)
class STATUSES(Values): class STATUSES(Values):
""" """
Closing status codes. Closing status codes.
...@@ -76,12 +73,10 @@ class STATUSES(Values): ...@@ -76,12 +73,10 @@ class STATUSES(Values):
TLS_HANDSHAKE_FAILED = ValueConstant(1056) TLS_HANDSHAKE_FAILED = ValueConstant(1056)
# The GUID for WebSockets, from RFC 6455. # The GUID for WebSockets, from RFC 6455.
_WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" _WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
def _makeAccept(key): def _makeAccept(key):
""" """
Create an B{accept} response for a given key. Create an B{accept} response for a given key.
...@@ -95,7 +90,6 @@ def _makeAccept(key): ...@@ -95,7 +90,6 @@ def _makeAccept(key):
return sha1("%s%s" % (key, _WS_GUID)).digest().encode("base64").strip() return sha1("%s%s" % (key, _WS_GUID)).digest().encode("base64").strip()
def _mask(buf, key): def _mask(buf, key):
""" """
Mask or unmask a buffer of bytes with a masking key. Mask or unmask a buffer of bytes with a masking key.
...@@ -116,7 +110,6 @@ def _mask(buf, key): ...@@ -116,7 +110,6 @@ def _mask(buf, key):
return "".join(buf) return "".join(buf)
def _makeFrame(buf, opcode, fin, mask=None): def _makeFrame(buf, opcode, fin, mask=None):
""" """
Make a frame. Make a frame.
...@@ -164,7 +157,6 @@ def _makeFrame(buf, opcode, fin, mask=None): ...@@ -164,7 +157,6 @@ def _makeFrame(buf, opcode, fin, mask=None):
return frame return frame
def _parseFrames(frameBuffer, needMask=True): def _parseFrames(frameBuffer, needMask=True):
""" """
Parse frames in a highly compliant manner. It modifies C{frameBuffer} Parse frames in a highly compliant manner. It modifies C{frameBuffer}
...@@ -268,7 +260,6 @@ def _parseFrames(frameBuffer, needMask=True): ...@@ -268,7 +260,6 @@ def _parseFrames(frameBuffer, needMask=True):
frameBuffer[:] = [] frameBuffer[:] = []
class IWebSocketsFrameReceiver(Interface): class IWebSocketsFrameReceiver(Interface):
""" """
An interface for receiving WebSockets frames. An interface for receiving WebSockets frames.
...@@ -285,7 +276,6 @@ class IWebSocketsFrameReceiver(Interface): ...@@ -285,7 +276,6 @@ class IWebSocketsFrameReceiver(Interface):
@type transport: L{WebSocketsTransport}. @type transport: L{WebSocketsTransport}.
""" """
def frameReceived(opcode, data, fin): def frameReceived(opcode, data, fin):
""" """
Callback when a frame is received. Callback when a frame is received.
...@@ -301,7 +291,6 @@ class IWebSocketsFrameReceiver(Interface): ...@@ -301,7 +291,6 @@ class IWebSocketsFrameReceiver(Interface):
""" """
class WebSocketsTransport(object): class WebSocketsTransport(object):
""" """
A frame transport for WebSockets. A frame transport for WebSockets.
...@@ -316,7 +305,6 @@ class WebSocketsTransport(object): ...@@ -316,7 +305,6 @@ class WebSocketsTransport(object):
def __init__(self, transport): def __init__(self, transport):
self._transport = transport self._transport = transport
def sendFrame(self, opcode, data, fin): def sendFrame(self, opcode, data, fin):
""" """
Build a frame packet and send it over the wire. Build a frame packet and send it over the wire.
...@@ -333,7 +321,6 @@ class WebSocketsTransport(object): ...@@ -333,7 +321,6 @@ class WebSocketsTransport(object):
packet = _makeFrame(base64.b64encode(data), opcode, fin) packet = _makeFrame(base64.b64encode(data), opcode, fin)
self._transport.write(packet) self._transport.write(packet)
def loseConnection(self, code=STATUSES.NORMAL, reason=""): def loseConnection(self, code=STATUSES.NORMAL, reason=""):
""" """
Close the connection. Close the connection.
...@@ -362,7 +349,6 @@ class WebSocketsTransport(object): ...@@ -362,7 +349,6 @@ class WebSocketsTransport(object):
self._transport.loseConnection() self._transport.loseConnection()
class WebSocketsProtocol(Protocol): class WebSocketsProtocol(Protocol):
""" """
A protocol parsing WebSockets frames and interacting with a A protocol parsing WebSockets frames and interacting with a
...@@ -379,11 +365,9 @@ class WebSocketsProtocol(Protocol): ...@@ -379,11 +365,9 @@ class WebSocketsProtocol(Protocol):
""" """
_buffer = None _buffer = None
def __init__(self, receiver): def __init__(self, receiver):
self._receiver = receiver self._receiver = receiver
def connectionMade(self): def connectionMade(self):
""" """
Log the new connection and initialize the buffer list. Log the new connection and initialize the buffer list.
...@@ -393,7 +377,6 @@ class WebSocketsProtocol(Protocol): ...@@ -393,7 +377,6 @@ class WebSocketsProtocol(Protocol):
self._buffer = [] self._buffer = []
self._receiver.makeConnection(WebSocketsTransport(self.transport)) self._receiver.makeConnection(WebSocketsTransport(self.transport))
def _parseFrames(self): def _parseFrames(self):
""" """
Find frames in incoming data and pass them to the underlying protocol. Find frames in incoming data and pass them to the underlying protocol.
...@@ -417,7 +400,6 @@ class WebSocketsProtocol(Protocol): ...@@ -417,7 +400,6 @@ class WebSocketsProtocol(Protocol):
self.transport.write(_makeFrame(data, CONTROLS.PONG, True)) self.transport.write(_makeFrame(data, CONTROLS.PONG, True))
self._receiver.frameReceived(opcode, base64.b64decode(data), fin) self._receiver.frameReceived(opcode, base64.b64decode(data), fin)
def dataReceived(self, data): def dataReceived(self, data):
""" """
Append the data to the buffer list and parse the whole. Append the data to the buffer list and parse the whole.
...@@ -434,7 +416,6 @@ class WebSocketsProtocol(Protocol): ...@@ -434,7 +416,6 @@ class WebSocketsProtocol(Protocol):
self.transport.loseConnection() self.transport.loseConnection()
@implementer(IWebSocketsFrameReceiver) @implementer(IWebSocketsFrameReceiver)
class _WebSocketsProtocolWrapperReceiver(): class _WebSocketsProtocolWrapperReceiver():
""" """
...@@ -454,7 +435,6 @@ class _WebSocketsProtocolWrapperReceiver(): ...@@ -454,7 +435,6 @@ class _WebSocketsProtocolWrapperReceiver():
def __init__(self, wrappedProtocol): def __init__(self, wrappedProtocol):
self._wrappedProtocol = wrappedProtocol self._wrappedProtocol = wrappedProtocol
def makeConnection(self, transport): def makeConnection(self, transport):
""" """
Keep a reference to the given C{transport} and instantiate the list of Keep a reference to the given C{transport} and instantiate the list of
...@@ -463,7 +443,6 @@ class _WebSocketsProtocolWrapperReceiver(): ...@@ -463,7 +443,6 @@ class _WebSocketsProtocolWrapperReceiver():
self._transport = transport self._transport = transport
self._messages = [] self._messages = []
def frameReceived(self, opcode, data, fin): def frameReceived(self, opcode, data, fin):
""" """
For each frame received, accumulate the data (ignoring the opcode), and For each frame received, accumulate the data (ignoring the opcode), and
...@@ -487,7 +466,6 @@ class _WebSocketsProtocolWrapperReceiver(): ...@@ -487,7 +466,6 @@ class _WebSocketsProtocolWrapperReceiver():
self._wrappedProtocol.dataReceived(content) self._wrappedProtocol.dataReceived(content)
class WebSocketsProtocolWrapper(WebSocketsProtocol): class WebSocketsProtocolWrapper(WebSocketsProtocol):
""" """
A L{WebSocketsProtocol} which wraps a regular C{IProtocol} provider, A L{WebSocketsProtocol} which wraps a regular C{IProtocol} provider,
...@@ -509,7 +487,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol): ...@@ -509,7 +487,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
WebSocketsProtocol.__init__( WebSocketsProtocol.__init__(
self, _WebSocketsProtocolWrapperReceiver(wrappedProtocol)) self, _WebSocketsProtocolWrapperReceiver(wrappedProtocol))
def makeConnection(self, transport): def makeConnection(self, transport):
""" """
Upon connection, provides the transport interface, and forwards ourself Upon connection, provides the transport interface, and forwards ourself
...@@ -522,7 +499,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol): ...@@ -522,7 +499,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
WebSocketsProtocol.makeConnection(self, transport) WebSocketsProtocol.makeConnection(self, transport)
self.wrappedProtocol.makeConnection(self) self.wrappedProtocol.makeConnection(self)
def write(self, data): def write(self, data):
""" """
Write to the websocket protocol, transforming C{data} in a frame. Write to the websocket protocol, transforming C{data} in a frame.
...@@ -532,7 +508,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol): ...@@ -532,7 +508,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
""" """
self._receiver._transport.sendFrame(self.defaultOpcode, data, True) self._receiver._transport.sendFrame(self.defaultOpcode, data, True)
def writeSequence(self, data): def writeSequence(self, data):
""" """
Send all chunks from C{data} using C{write}. Send all chunks from C{data} using C{write}.
...@@ -543,7 +518,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol): ...@@ -543,7 +518,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
for chunk in data: for chunk in data:
self.write(chunk) self.write(chunk)
def loseConnection(self): def loseConnection(self):
""" """
Try to lose the connection gracefully when closing by sending a close Try to lose the connection gracefully when closing by sending a close
...@@ -551,14 +525,12 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol): ...@@ -551,14 +525,12 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
""" """
self._receiver._transport.loseConnection() self._receiver._transport.loseConnection()
def __getattr__(self, name): def __getattr__(self, name):
""" """
Forward all non-local attributes and methods to C{self.transport}. Forward all non-local attributes and methods to C{self.transport}.
""" """
return getattr(self.transport, name) return getattr(self.transport, name)
def connectionLost(self, reason): def connectionLost(self, reason):
""" """
Forward C{connectionLost} to C{self.wrappedProtocol}. Forward C{connectionLost} to C{self.wrappedProtocol}.
...@@ -570,7 +542,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol): ...@@ -570,7 +542,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
self.wrappedProtocol.connectionLost(reason) self.wrappedProtocol.connectionLost(reason)
@implementer(IResource) @implementer(IResource)
class WebSocketsResource(object): class WebSocketsResource(object):
""" """
...@@ -600,7 +571,6 @@ class WebSocketsResource(object): ...@@ -600,7 +571,6 @@ class WebSocketsResource(object):
def __init__(self, lookupProtocol): def __init__(self, lookupProtocol):
self._lookupProtocol = lookupProtocol self._lookupProtocol = lookupProtocol
def getChildWithDefault(self, name, request): def getChildWithDefault(self, name, request):
""" """
Reject attempts to retrieve a child resource. All path segments beyond Reject attempts to retrieve a child resource. All path segments beyond
...@@ -616,7 +586,6 @@ class WebSocketsResource(object): ...@@ -616,7 +586,6 @@ class WebSocketsResource(object):
raise RuntimeError( raise RuntimeError(
"Cannot get IResource children from WebSocketsResource") "Cannot get IResource children from WebSocketsResource")
def putChild(self, path, child): def putChild(self, path, child):
""" """
Reject attempts to add a child resource to this resource. The Reject attempts to add a child resource to this resource. The
...@@ -632,7 +601,6 @@ class WebSocketsResource(object): ...@@ -632,7 +601,6 @@ class WebSocketsResource(object):
raise RuntimeError( raise RuntimeError(
"Cannot put IResource children under WebSocketsResource") "Cannot put IResource children under WebSocketsResource")
def render(self, request): def render(self, request):
""" """
Render a request. Render a request.
...@@ -727,7 +695,6 @@ class WebSocketsResource(object): ...@@ -727,7 +695,6 @@ class WebSocketsResource(object):
return NOT_DONE_YET return NOT_DONE_YET
def lookupProtocolForFactory(factory): def lookupProtocolForFactory(factory):
""" """
Return a suitable C{lookupProtocol} argument for L{WebSocketsResource} Return a suitable C{lookupProtocol} argument for L{WebSocketsResource}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment