cn-py-serv/server/urlhandler.py
Иван Солнцев 9155cb17ed Receive data from client
Allow handle client requests with HTTP body for custom functions.

- Rewrited "path" function to class;
- Simple check clien request of method allowed;
- Use "Enumirations" for handler types, HTTP methods;
2024-09-15 15:11:51 +03:00

40 lines
911 B
Python

import logging
import os
from .common import HandlerType, HTTPMethod
log = logging.getLogger(__name__)
class Path:
def __init__(self, address, handler_type=HandlerType.STATIC_FILE, link="index.html", methods=HTTPMethod.GET):
self.address = address
self.handler_type = handler_type
self.link = link
self.methods = methods
def check_method(self, method):
return method in self.methods
@property
def handler_type(self):
return self._handler_type
@handler_type.setter
def handler_type(self, value):
if not isinstance(value, HandlerType):
raise ValueError
self._handler_type = value
@property
def methods(self):
return self._methods
@methods.setter
def methods(self, value):
if not isinstance(value, HTTPMethod):
raise ValueError
self._methods = value