vchrome 0.1.9__py3-none-any.whl → 0.1.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vchrome/__init__.py +61 -12
- {vchrome-0.1.9.dist-info → vchrome-0.1.10.dist-info}/METADATA +1 -1
- vchrome-0.1.10.dist-info/RECORD +6 -0
- vchrome-0.1.9.dist-info/RECORD +0 -6
- {vchrome-0.1.9.dist-info → vchrome-0.1.10.dist-info}/WHEEL +0 -0
- {vchrome-0.1.9.dist-info → vchrome-0.1.10.dist-info}/top_level.txt +0 -0
vchrome/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = '0.1.
|
|
1
|
+
__version__ = '0.1.10'
|
|
2
2
|
__author__ = 'v'
|
|
3
3
|
# ----------------------------------------------------------------------------------------------------
|
|
4
4
|
_allowed = {'Chrome'}
|
|
@@ -15,6 +15,7 @@ import copy
|
|
|
15
15
|
import types
|
|
16
16
|
import queue
|
|
17
17
|
import time
|
|
18
|
+
import ast
|
|
18
19
|
import inspect
|
|
19
20
|
import textwrap
|
|
20
21
|
import threading
|
|
@@ -252,6 +253,18 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
252
253
|
return data
|
|
253
254
|
if is_err:
|
|
254
255
|
raise Exception(is_err)
|
|
256
|
+
def has_print(func):
|
|
257
|
+
try:
|
|
258
|
+
if not func:
|
|
259
|
+
return False
|
|
260
|
+
code = textwrap.dedent(inspect.getsource(func))
|
|
261
|
+
tree = ast.parse(code)
|
|
262
|
+
for node in ast.walk(tree):
|
|
263
|
+
if isinstance(node, ast.Call):
|
|
264
|
+
if isinstance(node.func, ast.Name) and node.func.id == "print":
|
|
265
|
+
return True
|
|
266
|
+
except:
|
|
267
|
+
return False
|
|
255
268
|
def is_function(obj):
|
|
256
269
|
return type(obj) == types.FunctionType or type(obj) == types.MethodType
|
|
257
270
|
def create_connection_saf(*a, **kw):
|
|
@@ -402,6 +415,7 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
402
415
|
self.call_listen = {}
|
|
403
416
|
self.call_listen_keys = []
|
|
404
417
|
self.call_listen_vals = {}
|
|
418
|
+
self.call_listen_lock = {}
|
|
405
419
|
self.tools = SniffTools(self)
|
|
406
420
|
def _listen_cdp(self, sessionId):
|
|
407
421
|
self.f.cdp('Network.enable',{
|
|
@@ -431,6 +445,10 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
431
445
|
self.call_listen[pk] = [waiter, on_request, on_response]
|
|
432
446
|
self.call_listen_keys = self.call_listen.keys()
|
|
433
447
|
self.call_listen_vals[pk] = [pattern, is_regex]
|
|
448
|
+
# To make it easier to synchronize function printing (if there are print calls within the function).
|
|
449
|
+
self.call_listen_lock[pk] = 0
|
|
450
|
+
if has_print(on_request): self.call_listen_lock[pk] = self.call_listen_lock[pk] | 1
|
|
451
|
+
if has_print(on_response): self.call_listen_lock[pk] = self.call_listen_lock[pk] | 2
|
|
434
452
|
return waiter
|
|
435
453
|
def _handle_network(self):
|
|
436
454
|
self.f.set_method_callback('Network.requestWillBeSent', self.Network_requestWillBeSent)
|
|
@@ -453,8 +471,11 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
453
471
|
waiter, on_request, on_response = self.call_listen[k]
|
|
454
472
|
if on_request:
|
|
455
473
|
r = SniffNetwork.NetworkRequest(self.info_listen[requestId])
|
|
456
|
-
if
|
|
457
|
-
|
|
474
|
+
if self.call_listen_lock[k] & 1:
|
|
475
|
+
with rl:
|
|
476
|
+
if on_request(r): waiter.add(r)
|
|
477
|
+
else:
|
|
478
|
+
if on_request(r): waiter.add(r)
|
|
458
479
|
def Network_requestWillBeSentExtraInfo(self, rdata):
|
|
459
480
|
request_extra = rdata['params']
|
|
460
481
|
requestId = request_extra['requestId']
|
|
@@ -467,8 +488,11 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
467
488
|
waiter, on_request, on_response = self.call_listen[k]
|
|
468
489
|
if on_request:
|
|
469
490
|
r = SniffNetwork.NetworkRequest(self.info_listen[requestId])
|
|
470
|
-
if
|
|
471
|
-
|
|
491
|
+
if self.call_listen_lock[k] & 1:
|
|
492
|
+
with rl:
|
|
493
|
+
if on_request(r): waiter.add(r)
|
|
494
|
+
else:
|
|
495
|
+
if on_request(r): waiter.add(r)
|
|
472
496
|
else:
|
|
473
497
|
self.info_listen[requestId] = {}
|
|
474
498
|
self.info_listen[requestId]['request_extra'] = request_extra
|
|
@@ -504,8 +528,11 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
504
528
|
rbody = self.f.cdp('Network.getResponseBody', {"requestId": requestId}, sessionId=rdata.get('sessionId'), limit_time=3)
|
|
505
529
|
self.info_listen[requestId]['response_body'] = rbody
|
|
506
530
|
r = SniffNetwork.NetworkResponse(self.info_listen[requestId])
|
|
507
|
-
if
|
|
508
|
-
|
|
531
|
+
if self.call_listen_lock[k] & 2:
|
|
532
|
+
with rl:
|
|
533
|
+
if on_response(r): waiter.add(r)
|
|
534
|
+
else:
|
|
535
|
+
if on_response(r): waiter.add(r)
|
|
509
536
|
self.info_listen.pop(requestId, None)
|
|
510
537
|
self.qlist.get('V')
|
|
511
538
|
def Network_loadingFailed(self, rdata):
|
|
@@ -682,6 +709,7 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
682
709
|
self.call_change = {}
|
|
683
710
|
self.call_change_keys = []
|
|
684
711
|
self.call_change_vals = {}
|
|
712
|
+
self.call_change_lock = {}
|
|
685
713
|
self.tools = SniffTools(self)
|
|
686
714
|
def _change_cdp(self, sessionId):
|
|
687
715
|
self.f.cdp('Fetch.enable',{
|
|
@@ -712,6 +740,10 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
712
740
|
self.call_change[pk] = [waiter, on_request, on_response]
|
|
713
741
|
self.call_change_keys = self.call_change.keys()
|
|
714
742
|
self.call_change_vals[pk] = [pattern, is_regex]
|
|
743
|
+
# To make it easier to synchronize function printing (if there are print calls within the function).
|
|
744
|
+
self.call_change_lock[pk] = 0
|
|
745
|
+
if has_print(on_request): self.call_change_lock[pk] = self.call_change_lock[pk] | 1
|
|
746
|
+
if has_print(on_response): self.call_change_lock[pk] = self.call_change_lock[pk] | 2
|
|
715
747
|
return waiter
|
|
716
748
|
def _handle_fetch(self):
|
|
717
749
|
self.f.set_method_callback('Fetch.requestPaused', self.Fetch_requestPaused)
|
|
@@ -738,8 +770,11 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
738
770
|
})
|
|
739
771
|
if on_request:
|
|
740
772
|
try:
|
|
741
|
-
if
|
|
742
|
-
|
|
773
|
+
if self.call_change_lock[k] & 1:
|
|
774
|
+
with rl:
|
|
775
|
+
if on_request(x): waiter.add(x)
|
|
776
|
+
else:
|
|
777
|
+
if on_request(x): waiter.add(x)
|
|
743
778
|
except:
|
|
744
779
|
self.f.logger.log('[ERROR] in request on_request', traceback.format_exc())
|
|
745
780
|
continue
|
|
@@ -771,6 +806,15 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
771
806
|
self.f.logger.log('[ERROR] in request on_request continue', traceback.format_exc())
|
|
772
807
|
self.f.cdp('Fetch.continueRequest', {'requestId': requestId}, sessionId=rdata.get('sessionId'))
|
|
773
808
|
else:
|
|
809
|
+
# request: Redirect.
|
|
810
|
+
if 'responseHeaders' in rdata['params'] and type(rdata['params']['responseHeaders']) == list:
|
|
811
|
+
for kv in rdata['params']['responseHeaders']:
|
|
812
|
+
if kv['name'] == 'Location':
|
|
813
|
+
return self.f.cdp('Fetch.continueRequest', {'requestId': requestId, 'url':kv['value']}, sessionId=rdata.get('sessionId'))
|
|
814
|
+
# request: fail Request.
|
|
815
|
+
if 'responseErrorReason' in rdata['params']:
|
|
816
|
+
return self.f.cdp('Fetch.failRequest', {'requestId': requestId, 'errorReason':rdata['params']['responseErrorReason']}, sessionId=rdata.get('sessionId'))
|
|
817
|
+
# response
|
|
774
818
|
for k in self.call_change_keys:
|
|
775
819
|
if self._match_url(self.call_change_vals[k], url):
|
|
776
820
|
waiter, on_request, on_response = self.call_change[k]
|
|
@@ -785,8 +829,11 @@ def cdp_client(hostname, port, debug=False, runtimeEnable=False, cfg={}):
|
|
|
785
829
|
"request": SniffFetch.FetchRequest(rdata['params']['request'])
|
|
786
830
|
})
|
|
787
831
|
try:
|
|
788
|
-
if
|
|
789
|
-
|
|
832
|
+
if self.call_change_lock[k] & 2:
|
|
833
|
+
with rl:
|
|
834
|
+
if on_response(x): waiter.add(x)
|
|
835
|
+
else:
|
|
836
|
+
if on_response(x): waiter.add(x)
|
|
790
837
|
except:
|
|
791
838
|
self.f.logger.log('[ERROR] in response on_response', traceback.format_exc())
|
|
792
839
|
continue
|
|
@@ -2835,6 +2882,7 @@ class Chrome:
|
|
|
2835
2882
|
def _connect(self):
|
|
2836
2883
|
v_cfg = {}
|
|
2837
2884
|
v_cfg['headless'] = self.headless
|
|
2885
|
+
v_cfg['proxy'] = self.proxy
|
|
2838
2886
|
v_cfg_fpath = self.user_path / 'v_config.json'
|
|
2839
2887
|
if not is_port_open(self.port):
|
|
2840
2888
|
self._init()
|
|
@@ -2843,8 +2891,9 @@ class Chrome:
|
|
|
2843
2891
|
v_cfg = self.loadSaveF(v_cfg_fpath, v_cfg)
|
|
2844
2892
|
else:
|
|
2845
2893
|
self.writeSaveF(v_cfg_fpath, v_cfg)
|
|
2846
|
-
if v_cfg
|
|
2894
|
+
if v_cfg.get('headless', 'v') != self.headless or v_cfg.get('proxy', 'v') != self.proxy:
|
|
2847
2895
|
v_cfg['headless'] = self.headless
|
|
2896
|
+
v_cfg['proxy'] = self.proxy
|
|
2848
2897
|
self.root = cdp_client(self.hostname, port=self.port, debug=self.debug, runtimeEnable=self.runtimeEnable, cfg=v_cfg)
|
|
2849
2898
|
self.root.active.quit()
|
|
2850
2899
|
self._init()
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
v/__init__.py,sha256=6ZddLaDcwLudHWmFr2utAcYhperXw9AYoItNPm8EZSM,65
|
|
2
|
+
vchrome/__init__.py,sha256=aMD6Ua-33LnoLUcyX5mu7FKffntOAWa84b2GpQyExec,230224
|
|
3
|
+
vchrome-0.1.10.dist-info/METADATA,sha256=1cFcdEsGP3QhKOSGQbkP1RM_AjwxrIDXLgNeb89C2Ng,57
|
|
4
|
+
vchrome-0.1.10.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
|
|
5
|
+
vchrome-0.1.10.dist-info/top_level.txt,sha256=IYbkbnFb2FGoroYj_ZXIitmnJDgYBA29_HmK9BdEUkY,10
|
|
6
|
+
vchrome-0.1.10.dist-info/RECORD,,
|
vchrome-0.1.9.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
v/__init__.py,sha256=6ZddLaDcwLudHWmFr2utAcYhperXw9AYoItNPm8EZSM,65
|
|
2
|
-
vchrome/__init__.py,sha256=jSrnEZLp3_atYOrh3Sd-QF2n1ynTIwIuCGXnuXIR_DM,227216
|
|
3
|
-
vchrome-0.1.9.dist-info/METADATA,sha256=s8cXPtNAplO0IEcCir-q9X-souSVzmAR4ocahqNlCFw,56
|
|
4
|
-
vchrome-0.1.9.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
|
|
5
|
-
vchrome-0.1.9.dist-info/top_level.txt,sha256=IYbkbnFb2FGoroYj_ZXIitmnJDgYBA29_HmK9BdEUkY,10
|
|
6
|
-
vchrome-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|