Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
vncproxy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
01f5f3a2
authored
Feb 28, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix flake8 errors
parent
6f02b486
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
33 deletions
+0
-33
proxy.py
+0
-0
websockets.py
+0
-33
No files found.
proxy.py
View file @
01f5f3a2
websockets.py
View file @
01f5f3a2
...
...
@@ -31,14 +31,12 @@ from twisted.web.resource import IResource
from
twisted.web.server
import
NOT_DONE_YET
class
_WSException
(
Exception
):
"""
Internal exception for control flow inside the WebSockets frame parser.
"""
class
CONTROLS
(
Values
):
"""
Control frame specifiers.
...
...
@@ -54,7 +52,6 @@ class CONTROLS(Values):
PONG
=
ValueConstant
(
10
)
class
STATUSES
(
Values
):
"""
Closing status codes.
...
...
@@ -76,12 +73,10 @@ class STATUSES(Values):
TLS_HANDSHAKE_FAILED
=
ValueConstant
(
1056
)
# The GUID for WebSockets, from RFC 6455.
_WS_GUID
=
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
def
_makeAccept
(
key
):
"""
Create an B{accept} response for a given key.
...
...
@@ -95,7 +90,6 @@ def _makeAccept(key):
return
sha1
(
"
%
s
%
s"
%
(
key
,
_WS_GUID
))
.
digest
()
.
encode
(
"base64"
)
.
strip
()
def
_mask
(
buf
,
key
):
"""
Mask or unmask a buffer of bytes with a masking key.
...
...
@@ -116,7 +110,6 @@ def _mask(buf, key):
return
""
.
join
(
buf
)
def
_makeFrame
(
buf
,
opcode
,
fin
,
mask
=
None
):
"""
Make a frame.
...
...
@@ -164,7 +157,6 @@ def _makeFrame(buf, opcode, fin, mask=None):
return
frame
def
_parseFrames
(
frameBuffer
,
needMask
=
True
):
"""
Parse frames in a highly compliant manner. It modifies C{frameBuffer}
...
...
@@ -268,7 +260,6 @@ def _parseFrames(frameBuffer, needMask=True):
frameBuffer
[:]
=
[]
class
IWebSocketsFrameReceiver
(
Interface
):
"""
An interface for receiving WebSockets frames.
...
...
@@ -285,7 +276,6 @@ class IWebSocketsFrameReceiver(Interface):
@type transport: L{WebSocketsTransport}.
"""
def
frameReceived
(
opcode
,
data
,
fin
):
"""
Callback when a frame is received.
...
...
@@ -301,7 +291,6 @@ class IWebSocketsFrameReceiver(Interface):
"""
class
WebSocketsTransport
(
object
):
"""
A frame transport for WebSockets.
...
...
@@ -316,7 +305,6 @@ class WebSocketsTransport(object):
def
__init__
(
self
,
transport
):
self
.
_transport
=
transport
def
sendFrame
(
self
,
opcode
,
data
,
fin
):
"""
Build a frame packet and send it over the wire.
...
...
@@ -333,7 +321,6 @@ class WebSocketsTransport(object):
packet
=
_makeFrame
(
base64
.
b64encode
(
data
),
opcode
,
fin
)
self
.
_transport
.
write
(
packet
)
def
loseConnection
(
self
,
code
=
STATUSES
.
NORMAL
,
reason
=
""
):
"""
Close the connection.
...
...
@@ -362,7 +349,6 @@ class WebSocketsTransport(object):
self
.
_transport
.
loseConnection
()
class
WebSocketsProtocol
(
Protocol
):
"""
A protocol parsing WebSockets frames and interacting with a
...
...
@@ -379,11 +365,9 @@ class WebSocketsProtocol(Protocol):
"""
_buffer
=
None
def
__init__
(
self
,
receiver
):
self
.
_receiver
=
receiver
def
connectionMade
(
self
):
"""
Log the new connection and initialize the buffer list.
...
...
@@ -393,7 +377,6 @@ class WebSocketsProtocol(Protocol):
self
.
_buffer
=
[]
self
.
_receiver
.
makeConnection
(
WebSocketsTransport
(
self
.
transport
))
def
_parseFrames
(
self
):
"""
Find frames in incoming data and pass them to the underlying protocol.
...
...
@@ -417,7 +400,6 @@ class WebSocketsProtocol(Protocol):
self
.
transport
.
write
(
_makeFrame
(
data
,
CONTROLS
.
PONG
,
True
))
self
.
_receiver
.
frameReceived
(
opcode
,
base64
.
b64decode
(
data
),
fin
)
def
dataReceived
(
self
,
data
):
"""
Append the data to the buffer list and parse the whole.
...
...
@@ -434,7 +416,6 @@ class WebSocketsProtocol(Protocol):
self
.
transport
.
loseConnection
()
@implementer
(
IWebSocketsFrameReceiver
)
class
_WebSocketsProtocolWrapperReceiver
():
"""
...
...
@@ -454,7 +435,6 @@ class _WebSocketsProtocolWrapperReceiver():
def
__init__
(
self
,
wrappedProtocol
):
self
.
_wrappedProtocol
=
wrappedProtocol
def
makeConnection
(
self
,
transport
):
"""
Keep a reference to the given C{transport} and instantiate the list of
...
...
@@ -463,7 +443,6 @@ class _WebSocketsProtocolWrapperReceiver():
self
.
_transport
=
transport
self
.
_messages
=
[]
def
frameReceived
(
self
,
opcode
,
data
,
fin
):
"""
For each frame received, accumulate the data (ignoring the opcode), and
...
...
@@ -487,7 +466,6 @@ class _WebSocketsProtocolWrapperReceiver():
self
.
_wrappedProtocol
.
dataReceived
(
content
)
class
WebSocketsProtocolWrapper
(
WebSocketsProtocol
):
"""
A L{WebSocketsProtocol} which wraps a regular C{IProtocol} provider,
...
...
@@ -509,7 +487,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
WebSocketsProtocol
.
__init__
(
self
,
_WebSocketsProtocolWrapperReceiver
(
wrappedProtocol
))
def
makeConnection
(
self
,
transport
):
"""
Upon connection, provides the transport interface, and forwards ourself
...
...
@@ -522,7 +499,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
WebSocketsProtocol
.
makeConnection
(
self
,
transport
)
self
.
wrappedProtocol
.
makeConnection
(
self
)
def
write
(
self
,
data
):
"""
Write to the websocket protocol, transforming C{data} in a frame.
...
...
@@ -532,7 +508,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
"""
self
.
_receiver
.
_transport
.
sendFrame
(
self
.
defaultOpcode
,
data
,
True
)
def
writeSequence
(
self
,
data
):
"""
Send all chunks from C{data} using C{write}.
...
...
@@ -543,7 +518,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
for
chunk
in
data
:
self
.
write
(
chunk
)
def
loseConnection
(
self
):
"""
Try to lose the connection gracefully when closing by sending a close
...
...
@@ -551,14 +525,12 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
"""
self
.
_receiver
.
_transport
.
loseConnection
()
def
__getattr__
(
self
,
name
):
"""
Forward all non-local attributes and methods to C{self.transport}.
"""
return
getattr
(
self
.
transport
,
name
)
def
connectionLost
(
self
,
reason
):
"""
Forward C{connectionLost} to C{self.wrappedProtocol}.
...
...
@@ -570,7 +542,6 @@ class WebSocketsProtocolWrapper(WebSocketsProtocol):
self
.
wrappedProtocol
.
connectionLost
(
reason
)
@implementer
(
IResource
)
class
WebSocketsResource
(
object
):
"""
...
...
@@ -600,7 +571,6 @@ class WebSocketsResource(object):
def
__init__
(
self
,
lookupProtocol
):
self
.
_lookupProtocol
=
lookupProtocol
def
getChildWithDefault
(
self
,
name
,
request
):
"""
Reject attempts to retrieve a child resource. All path segments beyond
...
...
@@ -616,7 +586,6 @@ class WebSocketsResource(object):
raise
RuntimeError
(
"Cannot get IResource children from WebSocketsResource"
)
def
putChild
(
self
,
path
,
child
):
"""
Reject attempts to add a child resource to this resource. The
...
...
@@ -632,7 +601,6 @@ class WebSocketsResource(object):
raise
RuntimeError
(
"Cannot put IResource children under WebSocketsResource"
)
def
render
(
self
,
request
):
"""
Render a request.
...
...
@@ -727,7 +695,6 @@ class WebSocketsResource(object):
return
NOT_DONE_YET
def
lookupProtocolForFactory
(
factory
):
"""
Return a suitable C{lookupProtocol} argument for L{WebSocketsResource}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment