Debian Codegraph @

eventlet/green/urllib/request.py

raw
1 import sys
2
3 from eventlet import patcher
4 from eventlet.green import ftplib, http, os, socket, time
5 from eventlet.green.http import client as http_client
6 from eventlet.green.urllib import error, parse, response
7
8 # TODO should we also have green email version?
9 # import email
10
11
12 to_patch = [
13 # This (http module) is needed here, otherwise test__greenness hangs
14 # forever on Python 3 because parts of non-green http (including
15 # http.client) leak into our patched urllib.request. There may be a nicer
16 # way to handle this (I didn't dig too deep) but this does the job. Jakub
17 ('http', http),
18
19 ('http.client', http_client),
20 ('os', os),
21 ('socket', socket),
22 ('time', time),
23 ('urllib.error', error),
24 ('urllib.parse', parse),
25 ('urllib.response', response),
26 ]
27
28 try:
29 from eventlet.green import ssl
30 except ImportError:
31 pass
32 else:
33 to_patch.append(('ssl', ssl))
34
35 patcher.inject('urllib.request', globals(), *to_patch)
36 del to_patch
37
38 to_patch_in_functions = [('ftplib', ftplib)]
39 del ftplib
40
41 FTPHandler.ftp_open = patcher.patch_function(FTPHandler.ftp_open, *to_patch_in_functions)
42
43 if sys.version_info < (3, 14):
44 URLopener.open_ftp = patcher.patch_function(URLopener.open_ftp, *to_patch_in_functions)
45 else:
46 # Removed in python3.14+, nothing to do
47 pass
48
49 ftperrors = patcher.patch_function(ftperrors, *to_patch_in_functions)
50
51 ftpwrapper.init = patcher.patch_function(ftpwrapper.init, *to_patch_in_functions)
52 ftpwrapper.retrfile = patcher.patch_function(ftpwrapper.retrfile, *to_patch_in_functions)
53
54 del error
55 del parse
56 del response
57 del to_patch_in_functions