Skip to content

Commit c221f26

Browse files
committed
clean up and version bump
1 parent cea3828 commit c221f26

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

mystbin/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
from .client import MystbinClient
2828
from .errors import *
2929

30-
__version__ = "0.3.4"
30+
__version__ = "0.3.5"
3131
VersionInfo = namedtuple(
3232
"VersionInfo", "major minor micro releaselevel serial")
33-
version_info = VersionInfo(major=0, minor=3, micro=4,
33+
version_info = VersionInfo(major=0, minor=3, micro=5,
3434
releaselevel='final', serial=0)

mystbin/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ def _generate_sync_session(self, session: Type["requests.Session"]) -> Type["req
7070
if self.api_key:
7171
session.headers.update(
7272
{"Authorization": self.api_key, "User-Agent": "Mystbin.py"})
73+
7374
return session
7475

7576
async def _generate_async_session(self, session: Optional[aiohttp.ClientSession] = None) -> aiohttp.ClientSession:
7677
""" We will update (or create) a :class:`aiohttp.ClientSession` instance with the auth we require. """
7778
if not session:
7879
session = aiohttp.ClientSession(raise_for_status=False)
80+
7981
if self.api_key:
8082
session._default_headers.update(
8183
{"Authorization": self.api_key, "User-Agent": "Mystbin.py"})
84+
8285
session._timeout = aiohttp.ClientTimeout(CLIENT_TIMEOUT)
8386
return session
8487

@@ -103,6 +106,7 @@ def _perform_sync_post(self, content: str, syntax: str = None) -> Paste:
103106
payload = {'meta': [{'index': 0, 'syntax': syntax}]}
104107
response: Type["requests.Response"] = self.session.post(API_BASE_URL, files={
105108
'data': content, 'meta': (None, json.dumps(payload), 'application/json')}, timeout=CLIENT_TIMEOUT)
109+
106110
if response.status_code not in [200, 201]:
107111
raise APIError(response.status_code, response.text)
108112

@@ -112,13 +116,15 @@ async def _perform_async_post(self, content: str, syntax: str = None) -> Paste:
112116
""" Async post request. """
113117
if not self.session and self._are_we_async:
114118
self.session = await self._generate_async_session()
119+
115120
multi_part_write = aiohttp.MultipartWriter()
116121
paste_content = multi_part_write.append(content)
117122
paste_content.set_content_disposition("form-data", name="data")
118123
paste_content = multi_part_write.append_json(
119124
{'meta': [{'index': 0, 'syntax': syntax}]}
120125
)
121126
paste_content.set_content_disposition("form-data", name="meta")
127+
122128
async with self.session.post(API_BASE_URL, data=multi_part_write) as response:
123129
status_code = response.status
124130
response_text = await response.text()
@@ -139,31 +145,39 @@ def get(self, paste_id: str) -> Union[PasteData, Awaitable]:
139145
The ID of the paste you are going to retrieve.
140146
"""
141147
paste_id_match = MB_URL_RE.match(paste_id)
148+
142149
if not paste_id_match:
143150
raise BadPasteID("This is an invalid Mystb.in paste ID.")
151+
144152
paste_id = paste_id_match.group('ID')
145153
syntax = paste_id_match.group('syntax')
154+
146155
if not self._are_we_async:
147156
return self._perform_sync_get(paste_id, syntax)
157+
148158
return self._perform_async_get(paste_id, syntax)
149159

150160
def _perform_sync_get(self, paste_id: str, syntax: str = None) -> PasteData:
151161
""" Sync get request. """
152162
response: Type["requests.Response"] = self.session.get(
153163
f"{API_BASE_URL}/{paste_id}", timeout=CLIENT_TIMEOUT)
164+
154165
if response.status_code not in (200, ):
155166
raise BadPasteID("This is an invalid Mystb.in paste ID.")
167+
156168
paste_data = response.json()
157169
return PasteData(paste_id, paste_data)
158170

159171
async def _perform_async_get(self, paste_id: str, syntax: str = None) -> PasteData:
160172
""" Async get request. """
161173
if not self.session:
162174
self.session: aiohttp.ClientSession = await self._generate_async_session()
175+
163176
async with self.session.get(f"{API_BASE_URL}/{paste_id}", timeout=aiohttp.ClientTimeout(CLIENT_TIMEOUT)) as response:
164177
if response.status not in (200, ):
165178
raise BadPasteID("This is an invalid Mystb.in paste ID.")
166179
paste_data = await response.json()
180+
167181
return PasteData(paste_id, paste_data)
168182

169183
async def close(self):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mystbin.py"
3-
version = "0.3.4"
3+
version = "0.3.5"
44
description = "A small simple wrapper around the mystb.in API."
55
authors = ["AbstractUmbra <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)