jupyterlite-simple-cors-proxy 0.1.4__tar.gz → 0.1.6__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jupyterlite-simple-cors-proxy
3
- Version: 0.1.4
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.6
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
- # Make a request
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
@@ -10,11 +10,22 @@ pip install jupyterlite-simple-cors-proxy
10
10
  ## Usage
11
11
 
12
12
  ```python
13
- from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request
13
+ from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl
14
14
 
15
- # Make a request
15
+ # Set up
16
16
  url = "https://api.example.com/data"
17
+ # Optional params
17
18
  params = {"key": "value"}
19
+
20
+ # Get a cross-origin proxied url
21
+ cross_origin_url = xurl(url) # xurl(url, params)
22
+
23
+ # Get a file like object
24
+ # (Make the request, then create a file like object
25
+ # from the response)
26
+ file_ob = furl(url) # furl(url, params)
27
+
28
+ # Make a request
18
29
  response = cors_proxy_get(url, params)
19
30
 
20
31
  # Use like requests
@@ -0,0 +1,5 @@
1
+ # File: jupyterlite_simple_cors_proxy/__init__.py
2
+ from .proxy import cors_proxy_get, robust_get_request, xurl, furl
3
+
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
- if params:
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.4
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.6
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
- # Make a request
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
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="jupyterlite-simple-cors-proxy",
6
- version="0.1.4",
6
+ version="0.1.6",
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
9
  "requests",
@@ -19,5 +19,5 @@ setup(
19
19
  "License :: OSI Approved :: MIT License",
20
20
  "Operating System :: OS Independent",
21
21
  ],
22
- python_requires=">=3.6",
22
+ python_requires=">=3.8",
23
23
  )
@@ -1,5 +0,0 @@
1
- # File: jupyterlite_simple_cors_proxy/__init__.py
2
- from .proxy import cors_proxy, robust_get_request
3
-
4
- __version__ = "0.1.2"
5
- __all__ = ["cors_proxy_get", "robust_get_request"]