Skip to content

Commit 6e4cba9

Browse files
adamtheturtleclaude
andcommitted
Move target_api_request to shared _vws_request module
Fixes Pyright reportPrivateUsage error: _target_api_request was defined in vws.py but used in vumark_service.py. Move it to a shared private module with a public name so both can import it cleanly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7eb0da6 commit 6e4cba9

File tree

3 files changed

+89
-80
lines changed

3 files changed

+89
-80
lines changed

src/vws/_vws_request.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""Internal helper for making authenticated requests to the Vuforia Target
2+
API.
3+
"""
4+
5+
from urllib.parse import urljoin
6+
7+
import requests
8+
from beartype import BeartypeConf, beartype
9+
from vws_auth_tools import authorization_header, rfc_1123_date
10+
11+
from vws.response import Response
12+
13+
14+
@beartype(conf=BeartypeConf(is_pep484_tower=True))
15+
def target_api_request(
16+
*,
17+
content_type: str,
18+
server_access_key: str,
19+
server_secret_key: str,
20+
method: str,
21+
data: bytes,
22+
request_path: str,
23+
base_vws_url: str,
24+
request_timeout_seconds: float | tuple[float, float],
25+
extra_headers: dict[str, str],
26+
) -> Response:
27+
"""Make a request to the Vuforia Target API.
28+
29+
This uses `requests` to make a request against https://vws.vuforia.com.
30+
31+
Args:
32+
content_type: The content type of the request.
33+
server_access_key: A VWS server access key.
34+
server_secret_key: A VWS server secret key.
35+
method: The HTTP method which will be used in the request.
36+
data: The request body which will be used in the request.
37+
request_path: The path to the endpoint which will be used in the
38+
request.
39+
base_vws_url: The base URL for the VWS API.
40+
request_timeout_seconds: The timeout for the request, as used by
41+
``requests.request``. This can be a float to set both the
42+
connect and read timeouts, or a (connect, read) tuple.
43+
extra_headers: Additional headers to include in the request.
44+
45+
Returns:
46+
The response to the request made by `requests`.
47+
"""
48+
date_string = rfc_1123_date()
49+
50+
signature_string = authorization_header(
51+
access_key=server_access_key,
52+
secret_key=server_secret_key,
53+
method=method,
54+
content=data,
55+
content_type=content_type,
56+
date=date_string,
57+
request_path=request_path,
58+
)
59+
60+
headers = {
61+
"Authorization": signature_string,
62+
"Date": date_string,
63+
"Content-Type": content_type,
64+
**extra_headers,
65+
}
66+
67+
url = urljoin(base=base_vws_url, url=request_path)
68+
69+
requests_response = requests.request(
70+
method=method,
71+
url=url,
72+
headers=headers,
73+
data=data,
74+
timeout=request_timeout_seconds,
75+
)
76+
77+
return Response(
78+
text=requests_response.text,
79+
url=requests_response.url,
80+
status_code=requests_response.status_code,
81+
headers=dict(requests_response.headers),
82+
request_body=requests_response.request.body,
83+
tell_position=requests_response.raw.tell(),
84+
content=bytes(requests_response.content),
85+
)

src/vws/vumark_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from beartype import BeartypeConf, beartype
77

8+
from vws._vws_request import target_api_request
89
from vws.exceptions.custom_exceptions import ServerError
910
from vws.exceptions.vws_exceptions import (
1011
AuthenticationFailureError,
@@ -20,7 +21,6 @@
2021
UnknownTargetError,
2122
)
2223
from vws.vumark_accept import VuMarkAccept
23-
from vws.vws import _target_api_request
2424

2525

2626
@beartype(conf=BeartypeConf(is_pep484_tower=True))
@@ -99,7 +99,7 @@ def generate_vumark_instance(
9999
encoding="utf-8",
100100
)
101101

102-
response = _target_api_request(
102+
response = target_api_request(
103103
content_type=content_type,
104104
server_access_key=self._server_access_key,
105105
server_secret_key=self._server_secret_key,

src/vws/vws.py

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
from datetime import date
88
from http import HTTPMethod, HTTPStatus
99
from typing import BinaryIO
10-
from urllib.parse import urljoin
1110

12-
import requests
1311
from beartype import BeartypeConf, beartype
14-
from vws_auth_tools import authorization_header, rfc_1123_date
1512

13+
from vws._vws_request import target_api_request
1614
from vws.exceptions.custom_exceptions import (
1715
ServerError,
1816
TargetProcessingTimeoutError,
@@ -59,80 +57,6 @@ def _get_image_data(image: _ImageType) -> bytes:
5957
return image_data
6058

6159

62-
@beartype(conf=BeartypeConf(is_pep484_tower=True))
63-
def _target_api_request(
64-
*,
65-
content_type: str,
66-
server_access_key: str,
67-
server_secret_key: str,
68-
method: str,
69-
data: bytes,
70-
request_path: str,
71-
base_vws_url: str,
72-
request_timeout_seconds: float | tuple[float, float],
73-
extra_headers: dict[str, str],
74-
) -> Response:
75-
"""Make a request to the Vuforia Target API.
76-
77-
This uses `requests` to make a request against https://vws.vuforia.com.
78-
79-
Args:
80-
content_type: The content type of the request.
81-
server_access_key: A VWS server access key.
82-
server_secret_key: A VWS server secret key.
83-
method: The HTTP method which will be used in the request.
84-
data: The request body which will be used in the request.
85-
request_path: The path to the endpoint which will be used in the
86-
request.
87-
base_vws_url: The base URL for the VWS API.
88-
request_timeout_seconds: The timeout for the request, as used by
89-
``requests.request``. This can be a float to set both the
90-
connect and read timeouts, or a (connect, read) tuple.
91-
extra_headers: Additional headers to include in the request.
92-
93-
Returns:
94-
The response to the request made by `requests`.
95-
"""
96-
date_string = rfc_1123_date()
97-
98-
signature_string = authorization_header(
99-
access_key=server_access_key,
100-
secret_key=server_secret_key,
101-
method=method,
102-
content=data,
103-
content_type=content_type,
104-
date=date_string,
105-
request_path=request_path,
106-
)
107-
108-
headers = {
109-
"Authorization": signature_string,
110-
"Date": date_string,
111-
"Content-Type": content_type,
112-
**extra_headers,
113-
}
114-
115-
url = urljoin(base=base_vws_url, url=request_path)
116-
117-
requests_response = requests.request(
118-
method=method,
119-
url=url,
120-
headers=headers,
121-
data=data,
122-
timeout=request_timeout_seconds,
123-
)
124-
125-
return Response(
126-
text=requests_response.text,
127-
url=requests_response.url,
128-
status_code=requests_response.status_code,
129-
headers=dict(requests_response.headers),
130-
request_body=requests_response.request.body,
131-
tell_position=requests_response.raw.tell(),
132-
content=bytes(requests_response.content),
133-
)
134-
135-
13660
@beartype(conf=BeartypeConf(is_pep484_tower=True))
13761
class VWS:
13862
"""An interface to Vuforia Web Services APIs."""
@@ -198,7 +122,7 @@ def make_request(
198122
This may happen if the server address is not a valid Vuforia
199123
server.
200124
"""
201-
response = _target_api_request(
125+
response = target_api_request(
202126
content_type=content_type,
203127
server_access_key=self._server_access_key,
204128
server_secret_key=self._server_secret_key,

0 commit comments

Comments
 (0)