vchrome 0.0.7__py3-none-any.whl → 0.0.8__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 +37 -19
- {vchrome-0.0.7.dist-info → vchrome-0.0.8.dist-info}/METADATA +1 -1
- vchrome-0.0.8.dist-info/RECORD +5 -0
- vchrome-0.0.7.dist-info/RECORD +0 -5
- {vchrome-0.0.7.dist-info → vchrome-0.0.8.dist-info}/WHEEL +0 -0
- {vchrome-0.0.7.dist-info → vchrome-0.0.8.dist-info}/top_level.txt +0 -0
vchrome/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = '0.0.
|
|
1
|
+
__version__ = '0.0.8'
|
|
2
2
|
__author__ = 'v'
|
|
3
3
|
# ----------------------------------------------------------------------------------------------------
|
|
4
4
|
_allowed = {'Chrome'}
|
|
@@ -16,6 +16,7 @@ import types
|
|
|
16
16
|
import queue
|
|
17
17
|
import time
|
|
18
18
|
import inspect
|
|
19
|
+
import textwrap
|
|
19
20
|
import threading
|
|
20
21
|
from time import perf_counter
|
|
21
22
|
from math import factorial, sin, pi
|
|
@@ -25,7 +26,6 @@ import socket
|
|
|
25
26
|
import base64
|
|
26
27
|
import traceback
|
|
27
28
|
from json import JSONDecodeError
|
|
28
|
-
from functools import lru_cache
|
|
29
29
|
from threading import Thread, Event, RLock
|
|
30
30
|
from urllib import request
|
|
31
31
|
import builtins
|
|
@@ -148,9 +148,6 @@ def cdp_client(hostname, port, debug=False):
|
|
|
148
148
|
def close_all(self):
|
|
149
149
|
for i in range(self.num):
|
|
150
150
|
self._pool.put(self.KillThreadParams)
|
|
151
|
-
@lru_cache(maxsize=1024)
|
|
152
|
-
def get_cached_signature(func):
|
|
153
|
-
return inspect.signature(func)
|
|
154
151
|
def to_human_read(size_in_bytes, decimal_places= 2):
|
|
155
152
|
if size_in_bytes < 0:
|
|
156
153
|
raise ValueError("byte size cannot be negative!")
|
|
@@ -466,30 +463,36 @@ def cdp_client(hostname, port, debug=False):
|
|
|
466
463
|
class FetchFakeResponse:
|
|
467
464
|
def __init__(self, rinfo, encoding='utf8'):
|
|
468
465
|
self.rinfo = rinfo
|
|
469
|
-
self.encoding = encoding
|
|
466
|
+
self.encoding = rinfo.get('encoding') or encoding
|
|
470
467
|
self._url = rinfo.get('url')
|
|
471
|
-
self._responseCode = 200
|
|
472
|
-
self._responseHeaders = {"fake-header": "fake-header"}
|
|
473
|
-
|
|
468
|
+
self._responseCode = rinfo.get('status_code') or 200
|
|
469
|
+
self._responseHeaders = rinfo.get('headers') or {"fake-header": "fake-header"}
|
|
470
|
+
if rinfo.get('text'):
|
|
471
|
+
self._body = rinfo.get('text').encode(self.encoding)
|
|
472
|
+
elif rinfo.get('content'):
|
|
473
|
+
assert isinstance(rinfo.get('content'), bytes), '.content must be type: bytes'
|
|
474
|
+
self._body = rinfo.get('content')
|
|
475
|
+
else:
|
|
476
|
+
self._body = b''
|
|
474
477
|
self.request = rinfo.get('request')
|
|
475
478
|
@property
|
|
476
479
|
def url(self): return self._url
|
|
477
480
|
@property
|
|
478
481
|
def status_code(self): return self._responseCode
|
|
479
482
|
@status_code.setter
|
|
480
|
-
def status_code(self, value): assert isinstance(value, int), 'must be type: int'; self._responseCode = value
|
|
483
|
+
def status_code(self, value): assert isinstance(value, int), '.status_code must be type: int'; self._responseCode = value
|
|
481
484
|
@property
|
|
482
485
|
def headers(self): return self._responseHeaders
|
|
483
486
|
@headers.setter
|
|
484
|
-
def headers(self, value): assert isinstance(value, dict), 'must be type: dict'; self._responseHeaders = value
|
|
487
|
+
def headers(self, value): assert isinstance(value, dict), '.headers must be type: dict'; self._responseHeaders = value
|
|
485
488
|
@property
|
|
486
489
|
def content(self): return self._body
|
|
487
490
|
@content.setter
|
|
488
|
-
def content(self, value): assert isinstance(value, bytes), 'must be type: bytes'; self._body = value
|
|
491
|
+
def content(self, value): assert isinstance(value, bytes), '.content must be type: bytes'; self._body = value
|
|
489
492
|
@property
|
|
490
493
|
def text(self): return self._body.decode(self.encoding)
|
|
491
494
|
@text.setter
|
|
492
|
-
def text(self, value): assert isinstance(value, str), 'must be type: str'; self._body = value.encode(self.encoding)
|
|
495
|
+
def text(self, value): assert isinstance(value, str), '.text must be type: str'; self._body = value.encode(self.encoding)
|
|
493
496
|
def json(self):
|
|
494
497
|
c = self.text
|
|
495
498
|
return json.loads(c[c.find('{'):c.rfind('}')+1])
|
|
@@ -509,24 +512,36 @@ def cdp_client(hostname, port, debug=False):
|
|
|
509
512
|
self._postData = rinfo.get('postData')
|
|
510
513
|
self._postData_copy = self._postData
|
|
511
514
|
self._fake = None
|
|
515
|
+
self._alert = textwrap.dedent('''
|
|
516
|
+
The fake_response() function is already running!
|
|
517
|
+
req object cannot be modified. maybe you're using the feature in the wrong way.
|
|
518
|
+
below is an example of a modification:
|
|
519
|
+
|
|
520
|
+
def on_request(req):
|
|
521
|
+
fk_resp = req.fake_response();
|
|
522
|
+
fk_resp.content = b'xxxxxx'
|
|
523
|
+
# If you need to modify the return content,
|
|
524
|
+
# you need to use the return value object of the fake_response() function.
|
|
525
|
+
''').strip()
|
|
526
|
+
def _A(self): assert self._fake == None, self._alert
|
|
512
527
|
@property
|
|
513
528
|
def url(self): return self._url
|
|
514
529
|
@property
|
|
515
530
|
def method(self): return self._method
|
|
516
531
|
@method.setter
|
|
517
|
-
def method(self, value): assert isinstance(value, str), 'must be type: str'; self._method = value
|
|
532
|
+
def method(self, value): self._A(); assert isinstance(value, str), 'must be type: str'; self._method = value
|
|
518
533
|
@property
|
|
519
534
|
def headers(self): return self._headers
|
|
520
535
|
@headers.setter
|
|
521
|
-
def headers(self, value): assert isinstance(value, dict), 'must be type: dict'; self._headers = value
|
|
536
|
+
def headers(self, value): self._A(); assert isinstance(value, dict), 'must be type: dict'; self._headers = value
|
|
522
537
|
@property
|
|
523
538
|
def content(self): return self._postData
|
|
524
539
|
@content.setter
|
|
525
|
-
def content(self, value): assert isinstance(value, bytes), 'must be type: bytes'; self._postData = value
|
|
540
|
+
def content(self, value): self._A(); assert isinstance(value, bytes), 'must be type: bytes'; self._postData = value
|
|
526
541
|
@property
|
|
527
542
|
def text(self): return self._postData.decode(self.encoding)
|
|
528
543
|
@text.setter
|
|
529
|
-
def text(self, value): assert isinstance(value, str), 'must be type: str'; self._postData = value.encode(self.encoding)
|
|
544
|
+
def text(self, value): self._A(); assert isinstance(value, str), 'must be type: str'; self._postData = value.encode(self.encoding)
|
|
530
545
|
def json(self):
|
|
531
546
|
c = self.text
|
|
532
547
|
return json.loads(c[c.find('{'):c.rfind('}')+1])
|
|
@@ -541,8 +556,11 @@ def cdp_client(hostname, port, debug=False):
|
|
|
541
556
|
)
|
|
542
557
|
def get(self, k):
|
|
543
558
|
return getattr(self, '_'+k, None)
|
|
544
|
-
def fake_response(self):
|
|
545
|
-
|
|
559
|
+
def fake_response(self, data=None):
|
|
560
|
+
data = data or dict()
|
|
561
|
+
data['request'] = self
|
|
562
|
+
data['url'] = self._url
|
|
563
|
+
self._fake = SniffFetch.FetchFakeResponse(data)
|
|
546
564
|
return self._fake
|
|
547
565
|
class FetchResponse:
|
|
548
566
|
def __init__(self, rinfo, encoding='utf8'):
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
vchrome/__init__.py,sha256=54rvOagRIZrrCOF7LrudzF85S8pzgAEZIsVq-bbpQMM,210094
|
|
2
|
+
vchrome-0.0.8.dist-info/METADATA,sha256=tKmwbpzUM3M5bQZJ0biHSgcoChSI49lVRZ2Z9z0PLjk,54
|
|
3
|
+
vchrome-0.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
+
vchrome-0.0.8.dist-info/top_level.txt,sha256=oB919Fa09PCy48Ptj8iy-1QUcvhEeY97MOR42281Fk0,8
|
|
5
|
+
vchrome-0.0.8.dist-info/RECORD,,
|
vchrome-0.0.7.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
vchrome/__init__.py,sha256=rZTIhIcODRjNL8PUMvk6XO3mHzwMyqsjdfuKuJPsjwk,208966
|
|
2
|
-
vchrome-0.0.7.dist-info/METADATA,sha256=mdNZkOVidXUB1H8G3Rhgp_3SvSKTqXApqZ4Ei3QAXR0,54
|
|
3
|
-
vchrome-0.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
-
vchrome-0.0.7.dist-info/top_level.txt,sha256=oB919Fa09PCy48Ptj8iy-1QUcvhEeY97MOR42281Fk0,8
|
|
5
|
-
vchrome-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|