Skip to content

Commit c34bc5b

Browse files
authored
Clean up global cookiejar patches (#8)
* Join all cookiejar patches into 1 * Fix generate.sh to use new patch * Remove redundant patch files
1 parent f7a99a2 commit c34bc5b

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

generate.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
npm install @openapitools/openapi-generator-cli
3+
npm install @openapitools/openapi-generator-cli
44

55
rm vrchatapi docs -rf
66

@@ -13,14 +13,6 @@ rm vrchatapi docs -rf
1313
-i https://raw.githubusercontent.com/vrchatapi/specification/gh-pages/openapi.yaml \
1414
--http-user-agent="vrchatapi-py"
1515

16-
# Enable Global cookies
17-
sed -i '/cert_reqs = ssl.CERT_NONE/r patches/cookiejar_init.py' ./vrchatapi/rest.py
18-
sed -i '/headers = headers or {}/r patches/cookiejar_add.py' ./vrchatapi/rest.py
19-
20-
sed -i 's/if _preload_content/abcdefvrc\n\n if _preload_content/g' ./vrchatapi/rest.py
21-
sed -i '/abcdefvrc/r patches/cookiejar_extract.py' ./vrchatapi/rest.py
22-
sed -i 's/ abcdefvrc//g' ./vrchatapi/rest.py
23-
2416
# Fix description, keywords, etc...
2517
# Echo to trim whitespace
2618
VERSION=`echo $(cat setup.py | grep "The version of the OpenAPI document" | cut -d ":" -f 2)`
@@ -36,5 +28,8 @@ sed -i 's/abcdefvrc//g' ./setup.py
3628
# Remove messily pasted markdown at top of every file
3729
find vrchatapi -type f -exec sed -i '/VRChat API Banner/d' {} \;
3830

31+
# Enable Global cookies
32+
patch ./vrchatapi/rest.py < ./patches/cookiejar.patch
33+
3934
# Make 2fa required error readable
4035
patch ./vrchatapi/rest.py < ./patches/error_2fa_verify_readable.patch

patches/cookiejar.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/rest.py b/restpatch.py
2+
index b8da0751..3702266e 100644
3+
--- a/rest.py
4+
+++ b/restpatch.py
5+
@@ -61,6 +61,10 @@ class RESTClientObject(object):
6+
else:
7+
cert_reqs = ssl.CERT_NONE
8+
9+
+ # VRChatAPI: Init global cookie storage
10+
+ from http.cookiejar import CookieJar
11+
+ self.cookie_jar = CookieJar()
12+
+
13+
addition_pool_args = {}
14+
if configuration.assert_hostname is not None:
15+
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
16+
@@ -134,6 +138,13 @@ class RESTClientObject(object):
17+
post_params = post_params or {}
18+
headers = headers or {}
19+
20+
+ # VRChatAPI: Build a mock Request object to work with
21+
+ from urllib.request import Request
22+
+ mock_request_object = Request(url=url, method=method, headers=headers)
23+
+ self.cookie_jar.add_cookie_header(mock_request_object)
24+
+ if "Cookie" in mock_request_object.unredirected_hdrs:
25+
+ headers["Cookie"] = mock_request_object.unredirected_hdrs["Cookie"]
26+
+
27+
timeout = None
28+
if _request_timeout:
29+
if isinstance(_request_timeout, six.integer_types + (float, )): # noqa: E501,F821
30+
@@ -209,6 +220,10 @@ class RESTClientObject(object):
31+
msg = "{0}\n{1}".format(type(e).__name__, str(e))
32+
raise ApiException(status=0, reason=msg)
33+
34+
+
35+
+ # VRChatAPI: Extract and save cookies for global storage
36+
+ self.cookie_jar.extract_cookies(r, mock_request_object)
37+
+
38+
if _preload_content:
39+
r = RESTResponse(r)
40+

patches/cookiejar_add.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

patches/cookiejar_extract.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

patches/cookiejar_init.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)