PK! q00rafi/__init__.pyfrom rafi.app import App __version__ = "0.2.0" PK!v rafi/app.pyimport logging import re from collections import defaultdict class App(object): def __init__(self, app_name): self.app_name = app_name self.log = logging.getLogger(self.app_name) self.routes = defaultdict(dict) self.request = None def route(self, path, methods=["GET"]): def decorator(f): self._add_route(path, methods, f) return f return decorator def _add_route(self, path, methods, view_func): methods = set(item.upper() for item in methods) regex = re.compile( re.escape(path).replace("<", "(?P<").replace(">", ">[^/]+)") ) for method in methods: if method in self.routes[regex]: raise ValueError( "Duplicate method '%s' detected for route '%s'.", method, path, ) self.routes[regex][method] = view_func def __call__(self, request): # fix for empty paths path = "/" if not request.path else request.path for regex in self.routes.keys(): match = re.fullmatch(regex, path) if match is None: continue if request.method not in self.routes[regex]: return "", 405 self.request = request res = self.routes[regex][request.method](**match.groupdict()) if isinstance(res, tuple): return res return res, 200 return "", 404 PK!w??rafi-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2018 Danilo Braband, https://dab.io Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H=jTTrafi-0.2.0.dist-info/WHEEL 1 0 нRN&":WhAqo;VSoBtM4[`Z} Mz7M*{/ܒ?֎XPK!HIӴrafi-0.2.0.dist-info/METADATAok0SyZA4Yʶ@D.6[Č}dh +N!Ewt^]%Ǿ pb?_ m+\W8TފP`k|2j>F]9lZ̬(w-R^6bL޿9W%jOMb+^hFhy3lj |W-WT}InW=6{U36ƶ,CQd0il-Nؙ%JDPC {0Lu普cʣ3mtsHJA_ː}[ X5^gptʦeS|쩳42c0B_ވ39FbiLJ}kao! ["qpw׆Ʀ10-(nt4 z~p*aO16ЙZ < ÒϚZ]^6}O/SW=շ{drF/4PK!Hf\#rafi-0.2.0.dist-info/RECORDmKn@нgpA@峙H+D<}&&]$+U1073Dݲ{]O~w$rr&o#i\ʢm7n!l%v*N1AJ(S3OS@W |ZWTYD{cO ̝ lȩN-QP>ާ1}i/!{9708$Y,K[YG#`}UW}umB{+12eWOj!ى Ś,~PK! q00rafi/__init__.pyPK!v ^rafi/app.pyPK!w??rafi-0.2.0.dist-info/LICENSEPK!H=jTT rafi-0.2.0.dist-info/WHEELPK!HIӴ rafi-0.2.0.dist-info/METADATAPK!Hf\# rafi-0.2.0.dist-info/RECORDPK