Skip to content

Commit 780c41d

Browse files
committed
docstrings dont do fstrings
1 parent e779f0e commit 780c41d

File tree

1 file changed

+59
-49
lines changed

1 file changed

+59
-49
lines changed

mystbin/backend/routers/pastes.py

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ async def find_discord_tokens(request: Request, pastes: payloads.PastePut):
116116

117117
return tokens or None
118118

119+
desc = f"""Post a paste.
120+
121+
This endpoint falls under the `postpastes` ratelimit bucket.
122+
The `postpastes` bucket has a default ratelimit of {__config['ratelimits']['postpastes']}, and a ratelimit of {__config['ratelimits']['authed_postpastes']} when signed in
123+
"""
124+
119125
@router.put(
120126
"/paste",
121127
tags=["pastes"],
@@ -126,18 +132,13 @@ async def find_discord_tokens(request: Request, pastes: payloads.PastePut):
126132
},
127133
status_code=201,
128134
name="Create paste",
135+
description=desc
129136
)
130137
@limit("postpastes")
131138
async def put_pastes(
132139
request: Request,
133140
payload: payloads.PastePut,
134141
) -> Union[Dict[str, Optional[Union[str, int, datetime.datetime]]], UJSONResponse]:
135-
f"""Post a paste.
136-
137-
This endpoint falls under the `postpastes` ratelimit bucket.
138-
The `postpastes` bucket has a default ratelimit of {__config['ratelimits']['postpastes']}, and a ratelimit of {__config['ratelimits']['authed_postpastes']} when signed in
139-
"""
140-
141142
author_: Optional[Record] = request.state.user
142143

143144
if err := enforce_multipaste_limit(request.app, payload):
@@ -167,6 +168,11 @@ async def put_pastes(
167168
paste = recursive_hook(paste.dict())
168169
return UJSONResponse(paste, status_code=201)
169170

171+
desc = f"""Get a paste by ID.
172+
173+
This endpoint falls under the `getpaste` ratelimit bucket.
174+
The `getpaste` bucket has a default ratelimit of {__config['ratelimits']['getpaste']}, and a ratelimit of {__config['ratelimits']['authed_getpaste']} when signed in
175+
"""
170176

171177
@router.get(
172178
"/paste/{paste_id}",
@@ -178,14 +184,10 @@ async def put_pastes(
178184
404: {"model": errors.NotFound},
179185
},
180186
name="Get paste",
187+
description=desc
181188
)
182189
@limit("getpaste")
183190
async def get_paste(request: Request, paste_id: str, password: Optional[str] = None) -> UJSONResponse:
184-
f"""Get a paste by ID.
185-
186-
This endpoint falls under the `getpaste` ratelimit bucket.
187-
The `getpaste` bucket has a default ratelimit of {__config['ratelimits']['getpaste']}, and a ratelimit of {__config['ratelimits']['authed_getpaste']} when signed in
188-
"""
189191
paste = await request.app.state.db.get_paste(paste_id, password)
190192
if paste is None:
191193
return UJSONResponse({"error": "Not Found"}, status_code=404)
@@ -196,6 +198,12 @@ async def get_paste(request: Request, paste_id: str, password: Optional[str] = N
196198
resp = responses.PasteGetResponse(**paste)
197199
return UJSONResponse(recursive_hook(resp.dict()))
198200

201+
desc = f"""Get all pastes for the user you are signed in as via the Authorization header.
202+
* Requires authentication.
203+
204+
This endpoint falls under the `getpaste` ratelimit bucket.
205+
The `getpaste` bucket has a default ratelimit of {__config['ratelimits']['getpaste']}, and a ratelimit of {__config['ratelimits']['authed_getpaste']} when signed in
206+
"""
199207

200208
@router.get(
201209
"/pastes/@me",
@@ -206,18 +214,13 @@ async def get_paste(request: Request, paste_id: str, password: Optional[str] = N
206214
401: {"model": errors.Unauthorized},
207215
},
208216
name="Get user pastes",
217+
description=desc
209218
)
210219
@limit("getpaste")
211220
async def get_all_pastes(
212221
request: Request,
213222
limit: Optional[int] = None,
214223
) -> Union[UJSONResponse, Dict[str, List[Dict[str, str]]]]:
215-
f"""Get all pastes for the user you are signed in as via the Authorization header.
216-
* Requires authentication.
217-
218-
This endpoint falls under the `getpaste` ratelimit bucket.
219-
The `getpaste` bucket has a default ratelimit of {__config['ratelimits']['getpaste']}, and a ratelimit of {__config['ratelimits']['authed_getpaste']} when signed in
220-
"""
221224
user = request.state.user
222225
if not user:
223226
return UJSONResponse({"error": "Unathorized", "notice": "You must be signed in to use this route"}, status_code=401)
@@ -227,6 +230,15 @@ async def get_all_pastes(
227230

228231
return UJSONResponse({"pastes": pastes})
229232

233+
desc = f"""Edit a paste.
234+
You must be the author of the paste (IE, the paste must be created under your account).
235+
236+
* Requires authentication
237+
238+
This endpoint falls under the `postpastes` ratelimit bucket.
239+
The `postpastes` bucket has a default ratelimit of {__config['ratelimits']['postpastes']}, and a ratelimit of {__config['ratelimits']['authed_postpastes']} when signed in
240+
"""
241+
230242
@router.patch(
231243
"/paste/{paste_id}",
232244
tags=["pastes"],
@@ -237,22 +249,15 @@ async def get_all_pastes(
237249
403: {"model": errors.Forbidden},
238250
404: {"model": errors.NotFound},
239251
},
240-
name="Edit paste"
252+
name="Edit paste",
253+
description=desc
241254
)
242255
@limit("postpastes")
243256
async def edit_paste(
244257
request: Request,
245258
paste_id: str,
246259
payload: payloads.PastePatch,
247260
) -> Union[UJSONResponse, Dict[str, Optional[Union[str, int, datetime.datetime]]]]:
248-
f"""Edit a paste.
249-
You must be the author of the paste (IE, the paste must be created under your account).
250-
251-
* Requires authentication
252-
253-
This endpoint falls under the `postpastes` ratelimit bucket.
254-
The `postpastes` bucket has a default ratelimit of {__config['ratelimits']['postpastes']}, and a ratelimit of {__config['ratelimits']['authed_postpastes']} when signed in
255-
"""
256261
author = request.state.user
257262
if not author:
258263
return UJSONResponse({"error": "Unathorized", "notice": "You must be signed in to use this route"}, status_code=401)
@@ -271,6 +276,14 @@ async def edit_paste(
271276

272277
return UJSONResponse(dict(paste[0]))
273278

279+
desc = f"""Deletes pastes on MystBin.
280+
You must be the author of the paste (IE, the paste must be created under your account).
281+
282+
* Requires authentication.
283+
284+
This endpoint falls under the `deletepaste` ratelimit bucket.
285+
The `deletepaste` bucket has a default ratelimit of {__config['ratelimits']['deletepaste']}, and a ratelimit of {__config['ratelimits']['authed_deletepaste']} when signed in
286+
"""
274287

275288
@router.delete(
276289
"/paste/{paste_id}",
@@ -281,17 +294,10 @@ async def edit_paste(
281294
},
282295
status_code=200,
283296
name="Delete paste",
297+
description=desc
284298
)
285299
@limit("deletepaste")
286300
async def delete_paste(request: Request, paste_id: str) -> Union[UJSONResponse, Dict[str, str]]:
287-
f"""Deletes pastes on MystBin.
288-
You must be the author of the paste (IE, the paste must be created under your account).
289-
290-
* Requires authentication.
291-
292-
This endpoint falls under the `deletepaste` ratelimit bucket.
293-
The `deletepaste` bucket has a default ratelimit of {__config['ratelimits']['deletepaste']}, and a ratelimit of {__config['ratelimits']['authed_deletepaste']} when signed in
294-
"""
295301
user = request.state.user
296302
if not user:
297303
return UJSONResponse({"error": "Unathorized", "notice": "You must be signed in to use this route"}, status_code=401)
@@ -306,6 +312,15 @@ async def delete_paste(request: Request, paste_id: str) -> Union[UJSONResponse,
306312
return UJSONResponse({"deleted": deleted["id"]}, status_code=200)
307313

308314

315+
desc = f"""Deletes pastes.
316+
You must be the author of the pastes (IE, the pastes must be created under your account).
317+
318+
* Requires authentication.
319+
320+
This endpoint falls under the `deletepaste` ratelimit bucket.
321+
The `deletepaste` bucket has a default ratelimit of {__config['ratelimits']['deletepaste']}, and a ratelimit of {__config['ratelimits']['authed_deletepaste']} when signed in
322+
"""
323+
309324
@router.delete(
310325
"/paste",
311326
tags=["pastes"],
@@ -325,20 +340,13 @@ async def delete_paste(request: Request, paste_id: str) -> Union[UJSONResponse,
325340
},
326341
status_code=200,
327342
name="Delete pastes",
343+
description=desc
328344
)
329345
@limit("deletepaste")
330346
async def delete_pastes(
331347
request: Request,
332348
payload: payloads.PasteDelete,
333349
) -> Union[UJSONResponse, Dict[str, List[str]]]:
334-
f"""Deletes pastes.
335-
You must be the author of the pastes (IE, the pastes must be created under your account).
336-
337-
* Requires authentication.
338-
339-
This endpoint falls under the `deletepaste` ratelimit bucket.
340-
The `deletepaste` bucket has a default ratelimit of {__config['ratelimits']['deletepaste']}, and a ratelimit of {__config['ratelimits']['authed_deletepaste']} when signed in
341-
"""
342350
# We will filter out the pastes that are authorized and unauthorized, and return a clear response
343351
response = {"succeeded": [], "failed": []}
344352

@@ -357,22 +365,24 @@ async def delete_pastes(
357365

358366
return UJSONResponse(response, status_code=200)
359367

368+
desc = f"""
369+
A compatibility endpoint to maintain hastbin compatibility. Depreciated in favour of /paste
370+
This endpoint does not allow for syntax highlighting, multi-file, password protection, expiry, etc. Use the /paste endpoint for these features
371+
372+
This endpoint falls under the `postpastes` ratelimit bucket.
373+
The `postpastes` bucket has a default ratelimit of {__config['ratelimits']['postpastes']}, and a ratelimit of {__config['ratelimits']['authed_postpastes']} when signed in
374+
"""
360375

361376
@router.post(
362377
"/documents",
363378
tags=["pastes"],
364379
deprecated=True,
365380
response_description='{"key": "string"}',
381+
name="Hastebin create paste",
382+
description=desc
366383
)
367384
@limit("postpastes")
368385
async def compat_create_paste(request: Request):
369-
f"""
370-
A compatibility endpoint to maintain hastbin compatibility. Depreciated in favour of /paste
371-
This endpoint does not allow for syntax highlighting, multi-file, password protection, expiry, etc. Use the /paste endpoint for these features
372-
373-
This endpoint falls under the `postpastes` ratelimit bucket.
374-
The `postpastes` bucket has a default ratelimit of {__config['ratelimits']['postpastes']}, and a ratelimit of {__config['ratelimits']['authed_postpastes']} when signed in
375-
"""
376386
content = await request.body()
377387
paste: Record = await request.app.state.db.put_paste(
378388
paste_id=generate_paste_id(),

0 commit comments

Comments
 (0)