PageRenderTime 27ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/slpmonkeypatch/socketmodule.py

http://stacklessexamples.googlecode.com/
Python | 27 lines | 15 code | 5 blank | 7 comment | 4 complexity | 3aa2c5c807254a90b1949dcacba053b7 MD5 | raw file
  1. import threading
  2. import stackless
  3. # We need the "socket" name for the function we export.
  4. import stdsocket
  5. # If we are to masquerade as the socket module, we need to provide the constants.
  6. for k, v in stdsocket.__dict__.iteritems():
  7. if k.upper() == k:
  8. globals()[k] = v
  9. error = stdsocket.error
  10. timeout = stdsocket.timeout
  11. # WARNING: this function blocks and is not thread safe.
  12. # The only solution is to spawn a thread to handle all
  13. # getaddrinfo requests. Implementing a stackless DNS
  14. # lookup service is only second best as getaddrinfo may
  15. # use other methods.
  16. getaddrinfo = stdsocket.getaddrinfo
  17. _config = stackless._config
  18. def socket(*args):
  19. if getattr(_config, "using_stackless"):
  20. return stackless.socket(*args)
  21. else:
  22. return stdsocket.socket(*args)