Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pywss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pywss.testing import HttpTestRequest, HttpTestResponse
from pywss.routing import Route
from pywss.openapi import openapi_ui_template
from pywss.utils import split_method_route, merge_dict
from pywss.utils import split_method_route, merge_dict, Query

__version__ = '0.1.28'

Expand All @@ -49,8 +49,10 @@ def __init__(
self.method: str = http_method
self.url: str = http_url # /route?key=value
self.url_params: dict = parse_params(http_url)
self.query: Query = Query(parse_params(http_url))
self.route: str = route # /route
self.route_params: dict = route_params
self.params: Query = Query(route_params)
self.version: str = http_version
self.headers: dict = http_headers
self.cookies: dict = parse_cookies(http_headers)
Expand Down
11 changes: 11 additions & 0 deletions pywss/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8
import json

from typing import Any
from copy import deepcopy


Expand All @@ -27,3 +28,13 @@ def merge_dict(dict1: dict, dict2: dict):
if isinstance(obj[k], dict) and isinstance(v, dict):
obj[k] = merge_dict(obj[k], v)
return obj


class Query(dict):

def fetch(self, *args, typ: Any = str):
ret = [typ()] * len(args)
for index, arg in enumerate(args):
if arg in self:
ret[index] = typ(self[arg])
return ret