sfq 0.0.1__py3-none-any.whl → 0.0.3__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.
sfq/__init__.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import http.client
|
2
2
|
import logging
|
3
3
|
import time
|
4
|
+
import os
|
4
5
|
import json
|
5
6
|
from urllib.parse import urlparse, quote
|
6
7
|
|
@@ -17,6 +18,7 @@ class SFAuth:
|
|
17
18
|
access_token=None,
|
18
19
|
token_expiration_time=None,
|
19
20
|
token_lifetime=15 * 60,
|
21
|
+
proxy="auto",
|
20
22
|
):
|
21
23
|
"""
|
22
24
|
Initializes the SFAuth with necessary parameters.
|
@@ -29,6 +31,7 @@ class SFAuth:
|
|
29
31
|
:param access_token: The access token for the current session (default is None).
|
30
32
|
:param token_expiration_time: The expiration time of the access token (default is None).
|
31
33
|
:param token_lifetime: The lifetime of the access token (default is 15 minutes).
|
34
|
+
:param proxy: The proxy configuration (default is "auto").
|
32
35
|
"""
|
33
36
|
self.instance_url = instance_url
|
34
37
|
self.client_id = client_id
|
@@ -38,6 +41,19 @@ class SFAuth:
|
|
38
41
|
self.access_token = access_token
|
39
42
|
self.token_expiration_time = token_expiration_time
|
40
43
|
self.token_lifetime = token_lifetime
|
44
|
+
self._auto_configure_proxy(proxy)
|
45
|
+
|
46
|
+
def _auto_configure_proxy(self, proxy):
|
47
|
+
"""
|
48
|
+
Automatically configure the proxy based on the environment.
|
49
|
+
"""
|
50
|
+
if proxy == "auto":
|
51
|
+
if "https_proxy" in os.environ:
|
52
|
+
self.proxy = os.environ["https_proxy"]
|
53
|
+
else:
|
54
|
+
self.proxy = None
|
55
|
+
else:
|
56
|
+
self.proxy = proxy
|
41
57
|
|
42
58
|
def _prepare_payload(self):
|
43
59
|
"""Prepare the payload for the token request."""
|
@@ -47,13 +63,28 @@ class SFAuth:
|
|
47
63
|
"refresh_token": self.refresh_token,
|
48
64
|
}
|
49
65
|
|
66
|
+
def _create_connection(self, netloc):
|
67
|
+
"""
|
68
|
+
Create a connection using HTTP or HTTPS, depending on the proxy configuration.
|
69
|
+
"""
|
70
|
+
if self.proxy:
|
71
|
+
proxy_url = urlparse(self.proxy)
|
72
|
+
if proxy_url.scheme == "http://":
|
73
|
+
conn = http.client.HTTPConnection(proxy_url.hostname, proxy_url.port)
|
74
|
+
else:
|
75
|
+
conn = http.client.HTTPSConnection(proxy_url.hostname, proxy_url.port)
|
76
|
+
conn.set_tunnel(netloc)
|
77
|
+
else:
|
78
|
+
conn = http.client.HTTPSConnection(netloc)
|
79
|
+
return conn
|
80
|
+
|
50
81
|
def _send_post_request(self, payload):
|
51
82
|
"""Send a POST request to the Salesforce token endpoint using http.client."""
|
52
83
|
parsed_url = urlparse(self.instance_url)
|
53
|
-
conn =
|
84
|
+
conn = self._create_connection(parsed_url.netloc)
|
54
85
|
|
55
86
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
56
|
-
body = "&".join([f"{key}={value}" for key, value in payload.items()])
|
87
|
+
body = "&".join([f"{key}={quote(str(value))}" for key, value in payload.items()])
|
57
88
|
|
58
89
|
try:
|
59
90
|
conn.request("POST", self.token_endpoint, body, headers)
|
@@ -75,7 +106,7 @@ class SFAuth:
|
|
75
106
|
|
76
107
|
def _refresh_token_if_needed(self):
|
77
108
|
"""Automatically refresh the token if it has expired or is missing."""
|
78
|
-
_token_expiration = self._is_token_expired
|
109
|
+
_token_expiration = self._is_token_expired()
|
79
110
|
if self.access_token and not _token_expiration:
|
80
111
|
return
|
81
112
|
|
@@ -96,7 +127,10 @@ class SFAuth:
|
|
96
127
|
|
97
128
|
def _is_token_expired(self):
|
98
129
|
"""Check if the access token has expired."""
|
99
|
-
|
130
|
+
try:
|
131
|
+
return time.time() >= float(self.token_expiration_time)
|
132
|
+
except (TypeError, ValueError):
|
133
|
+
return False
|
100
134
|
|
101
135
|
def query(self, query, tooling=False):
|
102
136
|
"""Query Salesforce using SOQL or Tooling API, depending on the `tooling` parameter."""
|
@@ -118,7 +152,7 @@ class SFAuth:
|
|
118
152
|
params = f"?q={encoded_query}"
|
119
153
|
|
120
154
|
parsed_url = urlparse(self.instance_url)
|
121
|
-
conn =
|
155
|
+
conn = self._create_connection(parsed_url.netloc)
|
122
156
|
|
123
157
|
try:
|
124
158
|
conn.request("GET", query_endpoint + params, headers=headers)
|
@@ -1,15 +1,17 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: sfq
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.3
|
4
4
|
Summary: Python wrapper for the Salesforce's Query API.
|
5
5
|
Author-email: David Moruzzi <sfq.pypi@dmoruzi.com>
|
6
6
|
Keywords: salesforce,salesforce query
|
7
7
|
Classifier: Development Status :: 3 - Alpha
|
8
8
|
Classifier: Intended Audience :: Developers
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
9
11
|
Classifier: Programming Language :: Python :: 3.12
|
10
12
|
Classifier: Programming Language :: Python :: 3.13
|
11
13
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
12
|
-
Requires-Python: >=3.
|
14
|
+
Requires-Python: >=3.9
|
13
15
|
Description-Content-Type: text/markdown
|
14
16
|
|
15
17
|
# sfq (Salesforce Query)
|
@@ -0,0 +1,5 @@
|
|
1
|
+
sfq/__init__.py,sha256=vcAXd4v6uyjzAqOril31LG2WG2n3l6OHxPiYQA63uD4,6361
|
2
|
+
sfq/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
sfq-0.0.3.dist-info/METADATA,sha256=y5Ir5XtomFESBbaktjuWzsA2d0Q40qlMIBXx1igISU4,4685
|
4
|
+
sfq-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
+
sfq-0.0.3.dist-info/RECORD,,
|
sfq-0.0.1.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
sfq/__init__.py,sha256=pOOF_qbF_5lWmZCp7Zth_cllmqD9Svr3pOVu01-1h5w,5180
|
2
|
-
sfq/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
sfq-0.0.1.dist-info/METADATA,sha256=tDxHUnStTdh2UrOqI9ItvquS3BHSVANmdhuF2-Sshlo,4585
|
4
|
-
sfq-0.0.1.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
5
|
-
sfq-0.0.1.dist-info/RECORD,,
|