@@ -45,27 +45,33 @@ async def test(self, proxy: Proxy):
45
45
logger .debug (f'testing { proxy .string ()} ' )
46
46
# if TEST_ANONYMOUS is True, make sure that
47
47
# the proxy has the effect of hiding the real IP
48
+ # logger.debug(f'TEST_ANONYMOUS {TEST_ANONYMOUS}')
48
49
if TEST_ANONYMOUS :
49
50
url = 'https://httpbin.org/ip'
50
51
async with session .get (url , timeout = TEST_TIMEOUT ) as response :
51
52
resp_json = await response .json ()
52
53
origin_ip = resp_json ['origin' ]
54
+ # logger.debug(f'origin ip is {origin_ip}')
53
55
async with session .get (url , proxy = f'http://{ proxy .string ()} ' , timeout = TEST_TIMEOUT ) as response :
54
56
resp_json = await response .json ()
55
57
anonymous_ip = resp_json ['origin' ]
58
+ logger .debug (f'anonymous ip is { anonymous_ip } ' )
56
59
assert origin_ip != anonymous_ip
57
60
assert proxy .host == anonymous_ip
58
61
async with session .get (TEST_URL , proxy = f'http://{ proxy .string ()} ' , timeout = TEST_TIMEOUT ,
59
62
allow_redirects = False ) as response :
60
63
if response .status in TEST_VALID_STATUS :
61
64
if TEST_DONT_SET_MAX_SCORE :
62
- logger .debug (f'proxy { proxy .string ()} is valid, remain current score' )
65
+ logger .debug (
66
+ f'proxy { proxy .string ()} is valid, remain current score' )
63
67
else :
64
68
self .redis .max (proxy )
65
- logger .debug (f'proxy { proxy .string ()} is valid, set max score' )
69
+ logger .debug (
70
+ f'proxy { proxy .string ()} is valid, set max score' )
66
71
else :
67
72
self .redis .decrease (proxy )
68
- logger .debug (f'proxy { proxy .string ()} is invalid, decrease score' )
73
+ logger .debug (
74
+ f'proxy { proxy .string ()} is invalid, decrease score' )
69
75
# if independent tester class found, create new set of storage and do the extra test
70
76
for tester in self .testers :
71
77
key = tester .key
@@ -82,18 +88,25 @@ async def test(self, proxy: Proxy):
82
88
is_valid = await tester .parse (resp_text , test_url , proxy .string ())
83
89
if is_valid :
84
90
if tester .test_dont_set_max_score :
85
- logger .info (f'key[{ key } ] proxy { proxy .string ()} is valid, remain current score' )
91
+ logger .info (
92
+ f'key[{ key } ] proxy { proxy .string ()} is valid, remain current score' )
86
93
else :
87
- self .redis .max (proxy , key , tester .proxy_score_max )
88
- logger .info (f'key[{ key } ] proxy { proxy .string ()} is valid, set max score' )
94
+ self .redis .max (
95
+ proxy , key , tester .proxy_score_max )
96
+ logger .info (
97
+ f'key[{ key } ] proxy { proxy .string ()} is valid, set max score' )
89
98
else :
90
- self .redis .decrease (proxy , tester .key , tester .proxy_score_min )
91
- logger .info (f'key[{ key } ] proxy { proxy .string ()} is invalid, decrease score' )
99
+ self .redis .decrease (
100
+ proxy , tester .key , tester .proxy_score_min )
101
+ logger .info (
102
+ f'key[{ key } ] proxy { proxy .string ()} is invalid, decrease score' )
92
103
93
104
except EXCEPTIONS :
94
105
self .redis .decrease (proxy )
95
- [self .redis .decrease (proxy , tester .key , tester .proxy_score_min ) for tester in self .testers ]
96
- logger .debug (f'proxy { proxy .string ()} is invalid, decrease score' )
106
+ [self .redis .decrease (proxy , tester .key , tester .proxy_score_min )
107
+ for tester in self .testers ]
108
+ logger .debug (
109
+ f'proxy { proxy .string ()} is invalid, decrease score' )
97
110
98
111
@logger .catch
99
112
def run (self ):
@@ -107,10 +120,12 @@ def run(self):
107
120
logger .debug (f'{ count } proxies to test' )
108
121
cursor = 0
109
122
while True :
110
- logger .debug (f'testing proxies use cursor { cursor } , count { TEST_BATCH } ' )
123
+ logger .debug (
124
+ f'testing proxies use cursor { cursor } , count { TEST_BATCH } ' )
111
125
cursor , proxies = self .redis .batch (cursor , count = TEST_BATCH )
112
126
if proxies :
113
- tasks = [self .loop .create_task (self .test (proxy )) for proxy in proxies ]
127
+ tasks = [self .loop .create_task (
128
+ self .test (proxy )) for proxy in proxies ]
114
129
self .loop .run_until_complete (asyncio .wait (tasks ))
115
130
if not cursor :
116
131
break
0 commit comments