/libraries/slpmonkeypatch/socketmodule.py
Python | 27 lines | 15 code | 5 blank | 7 comment | 4 complexity | 3aa2c5c807254a90b1949dcacba053b7 MD5 | raw file
- import threading
- import stackless
-
- # We need the "socket" name for the function we export.
- import stdsocket
-
- # If we are to masquerade as the socket module, we need to provide the constants.
- for k, v in stdsocket.__dict__.iteritems():
- if k.upper() == k:
- globals()[k] = v
- error = stdsocket.error
- timeout = stdsocket.timeout
-
- # WARNING: this function blocks and is not thread safe.
- # The only solution is to spawn a thread to handle all
- # getaddrinfo requests. Implementing a stackless DNS
- # lookup service is only second best as getaddrinfo may
- # use other methods.
- getaddrinfo = stdsocket.getaddrinfo
-
- _config = stackless._config
-
- def socket(*args):
- if getattr(_config, "using_stackless"):
- return stackless.socket(*args)
- else:
- return stdsocket.socket(*args)