3131from pygments .formatters import HtmlFormatter
3232from pygments .util import ClassNotFound
3333from typing import List , Optional
34+ from . import __version__ , __author__ , __contact__ , __url__
35+
36+ description : str = "paste.py 🐍 - A pastebin written in python."
3437
3538limiter = Limiter (key_func = get_remote_address )
36- app : FastAPI = FastAPI (title = "paste.py 🐍" )
39+ app : FastAPI = FastAPI (
40+ title = "paste.py 🐍" ,
41+ version = __version__ ,
42+ contact = dict (
43+ name = __author__ ,
44+ url = __url__ ,
45+ email = __contact__ ,
46+ ),
47+ license_info = dict (name = "MIT" , url = "https://opensource.org/license/mit/" ),
48+ openapi_url = None ,
49+ docs_url = None ,
50+ redoc_url = None ,
51+ )
3752app .state .limiter = limiter
3853app .add_exception_handler (RateLimitExceeded , _rate_limit_exceeded_handler )
3954
6075
6176@app .post ("/file" )
6277@limiter .limit ("100/minute" )
63- async def post_as_a_file (
64- request : Request , file : UploadFile = File (...)
65- ) -> PlainTextResponse :
78+ async def post_as_a_file (request : Request , file : UploadFile = File (...)) -> PlainTextResponse :
6679 try :
6780 uuid : str = generate_uuid ()
6881 if uuid in large_uuid_storage :
@@ -91,9 +104,7 @@ async def post_as_a_file(
91104
92105
93106@app .get ("/paste/{uuid}" )
94- async def get_paste_data (
95- uuid : str , user_agent : Optional [str ] = Header (None )
96- ) -> Response :
107+ async def get_paste_data (uuid : str , user_agent : Optional [str ] = Header (None )) -> Response :
97108 path : str = f"data/{ uuid } "
98109 try :
99110 with open (path , "rb" ) as f :
@@ -116,9 +127,7 @@ async def get_paste_data(
116127 lexer = get_lexer_by_name (file_extension , stripall = True )
117128 except ClassNotFound :
118129 lexer = get_lexer_by_name ("text" , stripall = True ) # Default lexer
119- formatter = HtmlFormatter (
120- style = "colorful" , full = True , linenos = "inline" , cssclass = "code"
121- )
130+ formatter = HtmlFormatter (style = "colorful" , full = True , linenos = "inline" , cssclass = "code" )
122131 highlighted_code : str = highlight (content , lexer , formatter )
123132 custom_style = """
124133 .code pre span.linenos {
@@ -190,13 +199,9 @@ async def delete_paste(uuid: str) -> PlainTextResponse:
190199 os .remove (path )
191200 return PlainTextResponse (f"File successfully deleted { uuid } " )
192201 except FileNotFoundError :
193- raise HTTPException (
194- detail = "File Not Found" , status_code = status .HTTP_404_NOT_FOUND
195- )
202+ raise HTTPException (detail = "File Not Found" , status_code = status .HTTP_404_NOT_FOUND )
196203 except Exception as e :
197- raise HTTPException (
198- detail = f"The exception is { e } " , status_code = status .HTTP_409_CONFLICT
199- )
204+ raise HTTPException (detail = f"The exception is { e } " , status_code = status .HTTP_409_CONFLICT )
200205
201206
202207@app .get ("/web" , response_class = HTMLResponse )
@@ -206,9 +211,7 @@ async def web(request: Request) -> Response:
206211
207212@app .post ("/web" , response_class = PlainTextResponse )
208213@limiter .limit ("100/minute" )
209- async def web_post (
210- request : Request , content : str = Form (...), extension : Optional [str ] = Form (None )
211- ) -> RedirectResponse :
214+ async def web_post (request : Request , content : str = Form (...), extension : Optional [str ] = Form (None )) -> RedirectResponse :
212215 try :
213216 file_content : bytes = content .encode ()
214217 uuid : str = generate_uuid ()
@@ -228,9 +231,7 @@ async def web_post(
228231 status_code = status .HTTP_403_FORBIDDEN ,
229232 )
230233
231- return RedirectResponse (
232- f"{ BASE_URL } /paste/{ uuid_ } " , status_code = status .HTTP_303_SEE_OTHER
233- )
234+ return RedirectResponse (f"{ BASE_URL } /paste/{ uuid_ } " , status_code = status .HTTP_303_SEE_OTHER )
234235
235236
236237@app .get ("/health" , status_code = status .HTTP_200_OK )
0 commit comments