Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
39c9d17c
Commit
39c9d17c
authored
Jun 09, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backdoor: re-implement BackdoorServer as StreamServer subclass
parent
3b90a8ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
24 deletions
+10
-24
gevent/backdoor.py
gevent/backdoor.py
+10
-24
No files found.
gevent/backdoor.py
View file @
39c9d17c
...
...
@@ -27,6 +27,7 @@ from code import InteractiveConsole
from
gevent
import
socket
from
gevent.greenlet
import
Greenlet
from
gevent.server
import
StreamServer
try
:
sys
.
ps1
...
...
@@ -40,11 +41,11 @@ except AttributeError:
class
SocketConsole
(
Greenlet
):
def
__init__
(
self
,
desc
,
locals
):
def
__init__
(
self
,
locals
,
conn
):
Greenlet
.
__init__
(
self
)
self
.
locals
=
locals
# mangle the socket
self
.
desc
=
desc
desc
=
self
.
desc
=
_fileobject
(
conn
)
readline
=
desc
.
readline
self
.
old
=
{}
self
.
fixups
=
{
...
...
@@ -90,25 +91,15 @@ class SocketConsole(Greenlet):
self
.
finalize
()
class
BackdoorServer
(
Greenlet
):
class
BackdoorServer
(
StreamServer
):
def
__init__
(
self
,
address
,
locals
=
None
):
Greenlet
.
__init__
(
self
)
if
isinstance
(
address
,
socket
.
socket
):
self
.
socket
=
address
else
:
self
.
socket
=
socket
.
tcp_listener
(
address
)
def
__init__
(
self
,
listener
,
locals
=
None
,
**
server_args
):
StreamServer
.
__init__
(
self
,
listener
,
spawn
=
None
,
**
server_args
)
self
.
locals
=
locals
# QQQ passing pool instance as 'spawn' is not possible; should it be fixed?
def
__str__
(
self
):
return
'<BackdoorServer on %s>'
%
(
self
.
socket
,
)
def
_run
(
self
):
while
True
:
(
conn
,
address
)
=
self
.
socket
.
accept
()
print
'accepted connection from %s'
%
(
address
,
)
fileobj
=
_fileobject
(
conn
)
SocketConsole
.
spawn
(
fileobj
,
self
.
locals
)
def
handle
(
self
,
conn
,
address
):
SocketConsole
.
spawn
(
self
.
locals
,
conn
)
class
_fileobject
(
socket
.
_fileobject
):
...
...
@@ -121,10 +112,5 @@ if __name__ == '__main__':
if
not
sys
.
argv
[
1
:]:
print
'USAGE: %s PORT'
%
sys
.
argv
[
0
]
else
:
server
=
BackdoorServer
.
spawn
((
'127.0.0.1'
,
int
(
sys
.
argv
[
1
])))
print
server
try
:
server
.
join
()
except
KeyboardInterrupt
:
pass
BackdoorServer
((
'127.0.0.1'
,
int
(
sys
.
argv
[
1
]))).
serve_forever
()
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