File: request.py

package info (click to toggle)
python-eventlet 0.40.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,200 kB
  • sloc: python: 25,101; sh: 78; makefile: 31
file content (57 lines) | stat: -rw-r--r-- 1,611 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys

from eventlet import patcher
from eventlet.green import ftplib, http, os, socket, time
from eventlet.green.http import client as http_client
from eventlet.green.urllib import error, parse, response

# TODO should we also have green email version?
# import email


to_patch = [
    # This (http module) is needed here, otherwise test__greenness hangs
    # forever on Python 3 because parts of non-green http (including
    # http.client) leak into our patched urllib.request. There may be a nicer
    # way to handle this (I didn't dig too deep) but this does the job. Jakub
    ('http', http),

    ('http.client', http_client),
    ('os', os),
    ('socket', socket),
    ('time', time),
    ('urllib.error', error),
    ('urllib.parse', parse),
    ('urllib.response', response),
]

try:
    from eventlet.green import ssl
except ImportError:
    pass
else:
    to_patch.append(('ssl', ssl))

patcher.inject('urllib.request', globals(), *to_patch)
del to_patch

to_patch_in_functions = [('ftplib', ftplib)]
del ftplib

FTPHandler.ftp_open = patcher.patch_function(FTPHandler.ftp_open, *to_patch_in_functions)

if sys.version_info < (3, 14):
    URLopener.open_ftp = patcher.patch_function(URLopener.open_ftp, *to_patch_in_functions)
else:
    # Removed in python3.14+, nothing to do
    pass

ftperrors = patcher.patch_function(ftperrors, *to_patch_in_functions)

ftpwrapper.init = patcher.patch_function(ftpwrapper.init, *to_patch_in_functions)
ftpwrapper.retrfile = patcher.patch_function(ftpwrapper.retrfile, *to_patch_in_functions)

del error
del parse
del response
del to_patch_in_functions