jupyterlite-simple-cors-proxy 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- jupyterlite_simple_cors_proxy/__init__.py +3 -3
- jupyterlite_simple_cors_proxy/proxy.py +21 -7
- {jupyterlite_simple_cors_proxy-0.1.4.dist-info → jupyterlite_simple_cors_proxy-0.1.6.dist-info}/METADATA +15 -4
- jupyterlite_simple_cors_proxy-0.1.6.dist-info/RECORD +7 -0
- jupyterlite_simple_cors_proxy-0.1.4.dist-info/RECORD +0 -7
- {jupyterlite_simple_cors_proxy-0.1.4.dist-info → jupyterlite_simple_cors_proxy-0.1.6.dist-info}/LICENSE +0 -0
- {jupyterlite_simple_cors_proxy-0.1.4.dist-info → jupyterlite_simple_cors_proxy-0.1.6.dist-info}/WHEEL +0 -0
- {jupyterlite_simple_cors_proxy-0.1.4.dist-info → jupyterlite_simple_cors_proxy-0.1.6.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
# File: jupyterlite_simple_cors_proxy/__init__.py
|
2
|
-
from .proxy import
|
2
|
+
from .proxy import cors_proxy_get, robust_get_request, xurl, furl
|
3
3
|
|
4
|
-
__version__ = "0.1.
|
5
|
-
__all__ = ["cors_proxy_get", "robust_get_request"]
|
4
|
+
__version__ = "0.1.6"
|
5
|
+
__all__ = ["cors_proxy_get", "robust_get_request", "xurl", "furl"]
|
@@ -1,6 +1,25 @@
|
|
1
1
|
# File: simple_cors_proxy/proxy.py
|
2
2
|
from urllib.parse import urlencode, quote
|
3
3
|
import requests
|
4
|
+
import io
|
5
|
+
|
6
|
+
import platform
|
7
|
+
PLATFORM = platform.system().lower()
|
8
|
+
|
9
|
+
def xurl(url, params=None, force=False):
|
10
|
+
if PLATFORM=="emscripten" or force:
|
11
|
+
if params:
|
12
|
+
url = f"{url}?{urlencode(params)}"
|
13
|
+
url = f"https://corsproxy.io/{quote(url)}"
|
14
|
+
|
15
|
+
return url
|
16
|
+
|
17
|
+
def furl(url, params=None):
|
18
|
+
"""Return file like object."""
|
19
|
+
r = cors_proxy_get(url, params)
|
20
|
+
|
21
|
+
# Return a file-like object from the JSON string
|
22
|
+
return io.BytesIO(r.content)
|
4
23
|
|
5
24
|
|
6
25
|
def cors_proxy_get(url, params=None):
|
@@ -14,12 +33,7 @@ def cors_proxy_get(url, params=None):
|
|
14
33
|
Returns:
|
15
34
|
A requests response object.
|
16
35
|
"""
|
17
|
-
|
18
|
-
full_url = f"{url}?{urlencode(params)}"
|
19
|
-
else:
|
20
|
-
full_url = url
|
21
|
-
|
22
|
-
proxy_url = f"https://corsproxy.io/{quote(full_url)}"
|
36
|
+
proxy_url = xurl(url, params)
|
23
37
|
|
24
38
|
# Do a simple requests get and
|
25
39
|
# just pass through the entire response object
|
@@ -33,4 +47,4 @@ def robust_get_request(url, params=None):
|
|
33
47
|
r = requests.get(url, params=params)
|
34
48
|
except:
|
35
49
|
r = cors_proxy_get(url, params=params)
|
36
|
-
return r
|
50
|
+
return r
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: jupyterlite-simple-cors-proxy
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.6
|
4
4
|
Summary: A simple CORS proxy utility with requests-like response
|
5
5
|
Home-page: https://github.com/innovationOUtside/jupyterlite-simple-cors-proxy
|
6
6
|
Author: Tony Hirst
|
@@ -8,7 +8,7 @@ Author-email: tony.hirst@gmail.com
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
10
10
|
Classifier: Operating System :: OS Independent
|
11
|
-
Requires-Python: >=3.
|
11
|
+
Requires-Python: >=3.8
|
12
12
|
Description-Content-Type: text/markdown
|
13
13
|
License-File: LICENSE
|
14
14
|
Requires-Dist: requests
|
@@ -34,11 +34,22 @@ pip install jupyterlite-simple-cors-proxy
|
|
34
34
|
## Usage
|
35
35
|
|
36
36
|
```python
|
37
|
-
from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request
|
37
|
+
from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl
|
38
38
|
|
39
|
-
#
|
39
|
+
# Set up
|
40
40
|
url = "https://api.example.com/data"
|
41
|
+
# Optional params
|
41
42
|
params = {"key": "value"}
|
43
|
+
|
44
|
+
# Get a cross-origin proxied url
|
45
|
+
cross_origin_url = xurl(url) # xurl(url, params)
|
46
|
+
|
47
|
+
# Get a file like object
|
48
|
+
# (Make the request, then create a file like object
|
49
|
+
# from the response)
|
50
|
+
file_ob = furl(url) # furl(url, params)
|
51
|
+
|
52
|
+
# Make a request
|
42
53
|
response = cors_proxy_get(url, params)
|
43
54
|
|
44
55
|
# Use like requests
|
@@ -0,0 +1,7 @@
|
|
1
|
+
jupyterlite_simple_cors_proxy/__init__.py,sha256=LLiWTvpFRjtUNxEgpzSWkI4CAXIBtR1XlXgBc-gkkcw,206
|
2
|
+
jupyterlite_simple_cors_proxy/proxy.py,sha256=d7SF-HszSUA3DemI04UHS8c5bJ2XXshPGD_ngUEe3-s,1236
|
3
|
+
jupyterlite_simple_cors_proxy-0.1.6.dist-info/LICENSE,sha256=Ogw7GUmeZIxmDNiKWsu_N07svNoGnPB7lWyiXHX_rMY,1074
|
4
|
+
jupyterlite_simple_cors_proxy-0.1.6.dist-info/METADATA,sha256=aIrUBWiyExB8LxIvsZX5S-TJcXvPw5tM8HIXRiWqEkg,1682
|
5
|
+
jupyterlite_simple_cors_proxy-0.1.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
+
jupyterlite_simple_cors_proxy-0.1.6.dist-info/top_level.txt,sha256=Oh0oQrSmRnBq5u675coiKMbkb2ASg8AGF8ZiZTzUS5Q,30
|
7
|
+
jupyterlite_simple_cors_proxy-0.1.6.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
jupyterlite_simple_cors_proxy/__init__.py,sha256=F1Y3oZFLKGV_q2B90txW9Lvxw8F9EyAEdnuk0WSeNiA,174
|
2
|
-
jupyterlite_simple_cors_proxy/proxy.py,sha256=zazo6dKSZHVHtoaETegAJ9GgdZs3TFQWZiSPikr877U,890
|
3
|
-
jupyterlite_simple_cors_proxy-0.1.4.dist-info/LICENSE,sha256=Ogw7GUmeZIxmDNiKWsu_N07svNoGnPB7lWyiXHX_rMY,1074
|
4
|
-
jupyterlite_simple_cors_proxy-0.1.4.dist-info/METADATA,sha256=fjT0E0wEFMgXxpazLqEGagbpbjm0PJd-1MjtrAVObXU,1420
|
5
|
-
jupyterlite_simple_cors_proxy-0.1.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
-
jupyterlite_simple_cors_proxy-0.1.4.dist-info/top_level.txt,sha256=Oh0oQrSmRnBq5u675coiKMbkb2ASg8AGF8ZiZTzUS5Q,30
|
7
|
-
jupyterlite_simple_cors_proxy-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|