jupyterlite-simple-cors-proxy 0.0.1__py3-none-any.whl → 0.1.3__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # File: jupyterlite_simple_cors_proxy/__init__.py
2
- from .proxy import cors_proxy, ProxyResponse
2
+ from .proxy import cors_proxy, robust_get_request
3
3
 
4
- __version__ = "0.1.0"
5
- __all__ = ["cors_proxy", "ProxyResponse"]
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
- @property
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,13 +12,25 @@ def cors_proxy(url, params=None):
29
12
  params (dict, optional): Query parameters to include
30
13
 
31
14
  Returns:
32
- ProxyResponse: A response object with .text, .json(), and .content methods
15
+ A requests response object.
33
16
  """
34
17
  if params:
35
18
  full_url = f"{url}?{urlencode(params)}"
36
19
  else:
37
20
  full_url = url
38
21
 
39
- proxy_url = f"https://corsproxy.io/?{quote(full_url)}"
40
- response = requests.get(proxy_url).content.decode().strip()
41
- return ProxyResponse(response)
22
+ proxy_url = f"https://corsproxy.io/{quote(full_url)}"
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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: jupyterlite-simple-cors-proxy
3
- Version: 0.0.1
3
+ Version: 0.1.3
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
@@ -12,6 +12,15 @@ Requires-Python: >=3.6
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: requests>=2.32.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
15
24
 
16
25
  # jupyterlite-simple-cors-proxy
17
26
  Simple CORS proxy for making http requests from JupyterLite
@@ -19,13 +28,13 @@ Simple CORS proxy for making http requests from JupyterLite
19
28
  ## Installation
20
29
 
21
30
  ```bash
22
- pip install simple-cors-proxy
31
+ pip install jupyterlite-simple-cors-proxy
23
32
  ```
24
33
 
25
34
  ## Usage
26
35
 
27
36
  ```python
28
- from simple_cors_proxy import cors_proxy
37
+ from simple_cors_proxy import cors_proxy_get, robust_get_request
29
38
 
30
39
  # Make a request
31
40
  url = "https://api.example.com/data"
@@ -38,9 +47,10 @@ data = response.json()
38
47
  raw = response.content
39
48
  ```
40
49
 
50
+ The `robust_get_request()` will first try a simple reuqst, then a proxied request: `robust_get_request(url, params)`
51
+
41
52
  ## Features
42
53
 
43
54
  - Simple CORS proxy wrapper
44
- - Requests-like response object
55
+ - Requests response object
45
56
  - 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=zazo6dKSZHVHtoaETegAJ9GgdZs3TFQWZiSPikr877U,890
3
+ jupyterlite_simple_cors_proxy-0.1.3.dist-info/LICENSE,sha256=Ogw7GUmeZIxmDNiKWsu_N07svNoGnPB7lWyiXHX_rMY,1074
4
+ jupyterlite_simple_cors_proxy-0.1.3.dist-info/METADATA,sha256=DxwUwU32bN9q_-RZre9h_CPAc7-aebYX_WsGaojPgJE,1405
5
+ jupyterlite_simple_cors_proxy-0.1.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
+ jupyterlite_simple_cors_proxy-0.1.3.dist-info/top_level.txt,sha256=Oh0oQrSmRnBq5u675coiKMbkb2ASg8AGF8ZiZTzUS5Q,30
7
+ jupyterlite_simple_cors_proxy-0.1.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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,,