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
0e0b04d2
Commit
0e0b04d2
authored
Sep 15, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
socket: follow pep8
parent
7f1831ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
gevent/socket.py
gevent/socket.py
+13
-8
No files found.
gevent/socket.py
View file @
0e0b04d2
...
@@ -247,12 +247,14 @@ if sys.version_info[:2] <= (2, 4):
...
@@ -247,12 +247,14 @@ if sys.version_info[:2] <= (2, 4):
if
sys
.
version_info
[:
2
]
<
(
2
,
7
):
if
sys
.
version_info
[:
2
]
<
(
2
,
7
):
_get_memory
=
buffer
_get_memory
=
buffer
else
:
else
:
def
_get_memory
(
string
,
offset
):
def
_get_memory
(
string
,
offset
):
return
memoryview
(
string
)[
offset
:]
return
memoryview
(
string
)[
offset
:]
class
_closedsocket
(
object
):
class
_closedsocket
(
object
):
__slots__
=
[]
__slots__
=
[]
def
_dummy
(
*
args
):
def
_dummy
(
*
args
):
raise
error
(
EBADF
,
'Bad file descriptor'
)
raise
error
(
EBADF
,
'Bad file descriptor'
)
# All _delegate_methods must also be initialized here.
# All _delegate_methods must also be initialized here.
...
@@ -264,6 +266,7 @@ _delegate_methods = ("recv", "recvfrom", "recv_into", "recvfrom_into", "send", "
...
@@ -264,6 +266,7 @@ _delegate_methods = ("recv", "recvfrom", "recv_into", "recvfrom_into", "send", "
timeout_default
=
object
()
timeout_default
=
object
()
class
socket
(
object
):
class
socket
(
object
):
def
__init__
(
self
,
family
=
AF_INET
,
type
=
SOCK_STREAM
,
proto
=
0
,
_sock
=
None
):
def
__init__
(
self
,
family
=
AF_INET
,
type
=
SOCK_STREAM
,
proto
=
0
,
_sock
=
None
):
...
@@ -282,7 +285,7 @@ class socket(object):
...
@@ -282,7 +285,7 @@ class socket(object):
self
.
_sock
.
setblocking
(
0
)
self
.
_sock
.
setblocking
(
0
)
self
.
_read_event
=
core
.
event
(
core
.
EV_READ
,
self
.
fileno
(),
_wait_helper
)
self
.
_read_event
=
core
.
event
(
core
.
EV_READ
,
self
.
fileno
(),
_wait_helper
)
self
.
_write_event
=
core
.
event
(
core
.
EV_WRITE
,
self
.
fileno
(),
_wait_helper
)
self
.
_write_event
=
core
.
event
(
core
.
EV_WRITE
,
self
.
fileno
(),
_wait_helper
)
self
.
_rw_event
=
core
.
event
(
core
.
EV_READ
|
core
.
EV_WRITE
,
self
.
fileno
(),
_wait_helper
)
self
.
_rw_event
=
core
.
event
(
core
.
EV_READ
|
core
.
EV_WRITE
,
self
.
fileno
(),
_wait_helper
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<%s at %s %s>'
%
(
type
(
self
).
__name__
,
hex
(
id
(
self
)),
self
.
_formatinfo
())
return
'<%s at %s %s>'
%
(
type
(
self
).
__name__
,
hex
(
id
(
self
)),
self
.
_formatinfo
())
...
@@ -337,7 +340,7 @@ class socket(object):
...
@@ -337,7 +340,7 @@ class socket(object):
setattr
(
self
,
method
,
dummy
)
setattr
(
self
,
method
,
dummy
)
def
connect
(
self
,
address
):
def
connect
(
self
,
address
):
if
isinstance
(
address
,
tuple
)
and
len
(
address
)
==
2
:
if
isinstance
(
address
,
tuple
)
and
len
(
address
)
==
2
:
address
=
gethostbyname
(
address
[
0
]),
address
[
1
]
address
=
gethostbyname
(
address
[
0
]),
address
[
1
]
if
self
.
timeout
==
0.0
:
if
self
.
timeout
==
0.0
:
return
self
.
_sock
.
connect
(
address
)
return
self
.
_sock
.
connect
(
address
)
...
@@ -380,7 +383,7 @@ class socket(object):
...
@@ -380,7 +383,7 @@ class socket(object):
if
type
(
ex
)
is
error
:
if
type
(
ex
)
is
error
:
return
ex
[
0
]
return
ex
[
0
]
else
:
else
:
raise
# gaierror is not silented by connect_ex
raise
# gaierror is not silented by connect_ex
def
dup
(
self
):
def
dup
(
self
):
"""dup() -> socket object
"""dup() -> socket object
...
@@ -395,7 +398,7 @@ class socket(object):
...
@@ -395,7 +398,7 @@ class socket(object):
return
_fileobject
(
self
.
dup
(),
mode
,
bufsize
)
return
_fileobject
(
self
.
dup
(),
mode
,
bufsize
)
def
recv
(
self
,
*
args
):
def
recv
(
self
,
*
args
):
sock
=
self
.
_sock
# keeping the reference so that fd is not closed during waiting
sock
=
self
.
_sock
# keeping the reference so that fd is not closed during waiting
while
True
:
while
True
:
try
:
try
:
return
sock
.
recv
(
*
args
)
return
sock
.
recv
(
*
args
)
...
@@ -535,9 +538,9 @@ class socket(object):
...
@@ -535,9 +538,9 @@ class socket(object):
def
shutdown
(
self
,
how
):
def
shutdown
(
self
,
how
):
cancel_wait
(
self
.
_rw_event
)
cancel_wait
(
self
.
_rw_event
)
if
how
==
0
:
# SHUT_RD
if
how
==
0
:
# SHUT_RD
cancel_wait
(
self
.
_read_event
)
cancel_wait
(
self
.
_read_event
)
elif
how
==
1
:
# SHUT_RW
elif
how
==
1
:
# SHUT_RW
cancel_wait
(
self
.
_write_event
)
cancel_wait
(
self
.
_write_event
)
else
:
else
:
cancel_wait
(
self
.
_read_event
)
cancel_wait
(
self
.
_read_event
)
...
@@ -559,6 +562,7 @@ class socket(object):
...
@@ -559,6 +562,7 @@ class socket(object):
SocketType
=
socket
SocketType
=
socket
if
hasattr
(
_socket
,
'socketpair'
):
if
hasattr
(
_socket
,
'socketpair'
):
def
socketpair
(
*
args
):
def
socketpair
(
*
args
):
one
,
two
=
_socket
.
socketpair
(
*
args
)
one
,
two
=
_socket
.
socketpair
(
*
args
)
return
socket
(
_sock
=
one
),
socket
(
_sock
=
two
)
return
socket
(
_sock
=
one
),
socket
(
_sock
=
two
)
...
@@ -566,6 +570,7 @@ else:
...
@@ -566,6 +570,7 @@ else:
__all__
.
remove
(
'socketpair'
)
__all__
.
remove
(
'socketpair'
)
if
hasattr
(
_socket
,
'fromfd'
):
if
hasattr
(
_socket
,
'fromfd'
):
def
fromfd
(
*
args
):
def
fromfd
(
*
args
):
return
socket
(
_sock
=
_socket
.
fromfd
(
*
args
))
return
socket
(
_sock
=
_socket
.
fromfd
(
*
args
))
else
:
else
:
...
@@ -594,6 +599,7 @@ try:
...
@@ -594,6 +599,7 @@ try:
except
AttributeError
:
except
AttributeError
:
_GLOBAL_DEFAULT_TIMEOUT
=
object
()
_GLOBAL_DEFAULT_TIMEOUT
=
object
()
def
create_connection
(
address
,
timeout
=
_GLOBAL_DEFAULT_TIMEOUT
,
source_address
=
None
):
def
create_connection
(
address
,
timeout
=
_GLOBAL_DEFAULT_TIMEOUT
,
source_address
=
None
):
"""Connect to *address* and return the socket object.
"""Connect to *address* and return the socket object.
...
@@ -623,7 +629,7 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
...
@@ -623,7 +629,7 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
except
error
,
msg
:
except
error
,
msg
:
if
sock
is
not
None
:
if
sock
is
not
None
:
sock
.
close
()
sock
.
close
()
raise
error
,
msg
raise
msg
try
:
try
:
...
@@ -658,7 +664,6 @@ else:
...
@@ -658,7 +664,6 @@ else:
_ttl
,
addrs
=
resolve_ipv4
(
hostname
)
_ttl
,
addrs
=
resolve_ipv4
(
hostname
)
return
inet_ntoa
(
random
.
choice
(
addrs
))
return
inet_ntoa
(
random
.
choice
(
addrs
))
def
getaddrinfo
(
host
,
port
,
*
args
,
**
kwargs
):
def
getaddrinfo
(
host
,
port
,
*
args
,
**
kwargs
):
"""*Some* approximation of :func:`socket.getaddrinfo` implemented using :mod:`gevent.dns`.
"""*Some* approximation of :func:`socket.getaddrinfo` implemented using :mod:`gevent.dns`.
...
...
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