jupyterlite-simple-cors-proxy 0.0.1__py3-none-any.whl → 0.1.2__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.
- jupyterlite_simple_cors_proxy/__init__.py +3 -3
- jupyterlite_simple_cors_proxy/proxy.py +16 -21
- {jupyterlite_simple_cors_proxy-0.0.1.dist-info → jupyterlite_simple_cors_proxy-0.1.2.dist-info}/METADATA +6 -5
- jupyterlite_simple_cors_proxy-0.1.2.dist-info/RECORD +7 -0
- jupyterlite_simple_cors_proxy-0.0.1.dist-info/RECORD +0 -7
- {jupyterlite_simple_cors_proxy-0.0.1.dist-info → jupyterlite_simple_cors_proxy-0.1.2.dist-info}/LICENSE +0 -0
- {jupyterlite_simple_cors_proxy-0.0.1.dist-info → jupyterlite_simple_cors_proxy-0.1.2.dist-info}/WHEEL +0 -0
- {jupyterlite_simple_cors_proxy-0.0.1.dist-info → jupyterlite_simple_cors_proxy-0.1.2.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
# File: jupyterlite_simple_cors_proxy/__init__.py
|
2
|
-
from .proxy import cors_proxy,
|
2
|
+
from .proxy import cors_proxy, robust_get_request
|
3
3
|
|
4
|
-
__version__ = "0.1.
|
5
|
-
__all__ = ["
|
4
|
+
__version__ = "0.1.2"
|
5
|
+
__all__ = ["cors_proxy_get", "robust_get_request"]
|
@@ -2,25 +2,8 @@
|
|
2
2
|
from urllib.parse import urlencode, quote
|
3
3
|
import requests
|
4
4
|
|
5
|
-
class ProxyResponse:
|
6
|
-
def __init__(self, content):
|
7
|
-
self._content = content
|
8
5
|
|
9
|
-
|
10
|
-
def text(self):
|
11
|
-
return self._content
|
12
|
-
|
13
|
-
def json(self):
|
14
|
-
import json
|
15
|
-
|
16
|
-
return json.loads(self._content)
|
17
|
-
|
18
|
-
@property
|
19
|
-
def content(self):
|
20
|
-
return self._content.encode()
|
21
|
-
|
22
|
-
|
23
|
-
def cors_proxy(url, params=None):
|
6
|
+
def cors_proxy_get(url, params=None):
|
24
7
|
"""
|
25
8
|
CORS proxy for GET resources with requests-like response.
|
26
9
|
|
@@ -29,7 +12,7 @@ def cors_proxy(url, params=None):
|
|
29
12
|
params (dict, optional): Query parameters to include
|
30
13
|
|
31
14
|
Returns:
|
32
|
-
|
15
|
+
A requests response object.
|
33
16
|
"""
|
34
17
|
if params:
|
35
18
|
full_url = f"{url}?{urlencode(params)}"
|
@@ -37,5 +20,17 @@ def cors_proxy(url, params=None):
|
|
37
20
|
full_url = url
|
38
21
|
|
39
22
|
proxy_url = f"https://corsproxy.io/?{quote(full_url)}"
|
40
|
-
|
41
|
-
|
23
|
+
|
24
|
+
# Do a simple requests get and
|
25
|
+
# just pass through the entire response object
|
26
|
+
return requests.get(proxy_url)
|
27
|
+
|
28
|
+
def robust_get_request(url, params=None):
|
29
|
+
"""
|
30
|
+
Try to make a simple request else fall back to a proxy.
|
31
|
+
"""
|
32
|
+
try:
|
33
|
+
r = requests.get(url, params=params)
|
34
|
+
except:
|
35
|
+
r = cors_proxy_get(url, params=params)
|
36
|
+
return r
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: jupyterlite-simple-cors-proxy
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.1.2
|
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
|
@@ -19,13 +19,13 @@ Simple CORS proxy for making http requests from JupyterLite
|
|
19
19
|
## Installation
|
20
20
|
|
21
21
|
```bash
|
22
|
-
pip install simple-cors-proxy
|
22
|
+
pip install jupyterlite-simple-cors-proxy
|
23
23
|
```
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```python
|
28
|
-
from simple_cors_proxy import
|
28
|
+
from simple_cors_proxy import cors_proxy_get, robust_get_request
|
29
29
|
|
30
30
|
# Make a request
|
31
31
|
url = "https://api.example.com/data"
|
@@ -38,9 +38,10 @@ data = response.json()
|
|
38
38
|
raw = response.content
|
39
39
|
```
|
40
40
|
|
41
|
+
The `robust_get_request()` will first try a simple reuqst, then a proxied request: `robust_get_request(url, params)`
|
42
|
+
|
41
43
|
## Features
|
42
44
|
|
43
45
|
- Simple CORS proxy wrapper
|
44
|
-
- Requests
|
46
|
+
- Requests response object
|
45
47
|
- Support for URL parameters
|
46
|
-
- JSON parsing
|
@@ -0,0 +1,7 @@
|
|
1
|
+
jupyterlite_simple_cors_proxy/__init__.py,sha256=F1Y3oZFLKGV_q2B90txW9Lvxw8F9EyAEdnuk0WSeNiA,174
|
2
|
+
jupyterlite_simple_cors_proxy/proxy.py,sha256=KbJza7WpOq7VUrZtv1jEYSq0PTSyP9KED99k8eGxpHc,891
|
3
|
+
jupyterlite_simple_cors_proxy-0.1.2.dist-info/LICENSE,sha256=Ogw7GUmeZIxmDNiKWsu_N07svNoGnPB7lWyiXHX_rMY,1074
|
4
|
+
jupyterlite_simple_cors_proxy-0.1.2.dist-info/METADATA,sha256=LetMK15lky-aNJaitPPbByd4FilGFdiaXZqAxXhlpdg,1208
|
5
|
+
jupyterlite_simple_cors_proxy-0.1.2.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
6
|
+
jupyterlite_simple_cors_proxy-0.1.2.dist-info/top_level.txt,sha256=Oh0oQrSmRnBq5u675coiKMbkb2ASg8AGF8ZiZTzUS5Q,30
|
7
|
+
jupyterlite_simple_cors_proxy-0.1.2.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
jupyterlite_simple_cors_proxy/__init__.py,sha256=wiS7zPJSmqeRn4N3oXw_I6-3fcob3zmHNYPajNzJBC8,160
|
2
|
-
jupyterlite_simple_cors_proxy/proxy.py,sha256=ccWngd54cCctn84VLRqS1n68CLcAau-m1UMGKzdTDHQ,977
|
3
|
-
jupyterlite_simple_cors_proxy-0.0.1.dist-info/LICENSE,sha256=Ogw7GUmeZIxmDNiKWsu_N07svNoGnPB7lWyiXHX_rMY,1074
|
4
|
-
jupyterlite_simple_cors_proxy-0.0.1.dist-info/METADATA,sha256=WHxay6lOzsMur4XI-dd7pLkIXW6QiNqQ5NmSiy2itK8,1074
|
5
|
-
jupyterlite_simple_cors_proxy-0.0.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
6
|
-
jupyterlite_simple_cors_proxy-0.0.1.dist-info/top_level.txt,sha256=Oh0oQrSmRnBq5u675coiKMbkb2ASg8AGF8ZiZTzUS5Q,30
|
7
|
-
jupyterlite_simple_cors_proxy-0.0.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|