<commit_before>import argparse
import sys
import asyncio
import signal
import functools
import httptools
import logging
from inspect import isawaitable
from ujson import loads as json_loads
from urllib.parse import parse_qs
from traceback import format_exc

import httptools
try:
    import uvloop as async_loop
except:
    async_loop = asyncio

from socket import *

from .log import log
from .config import LOGO
from .exceptions import ServerError
from .response import HTTPResponse

PRINT = 0

class Request:
    __slots__ = ('protocol', 'url', 'headers', 'version', 'method', 'query_string', 'body', 'parsed_json', 'parsed_args')

    def __init__(self, protocol, url, headers, version, method):
        self.protocol = protocol
        self.url = url
        self.headers = headers
        self.version = version
        self.method = method

        # Capture query string
        query_string_position = self.url.find(b"?")
        if query_string_position != -1:
            self.query_string = self.url[query_string_position+1:]
            self.url = self.url[:query_string_position]
        else:
            self.query_string = None

        # Init but do not inhale
        self.body = None
        self.parsed_json = None
        self.parsed_args = None

    @property
    def json(self):
        if not self.parsed_json:
            if not self.body:
                raise ValueError("No body to parse")
            self.parsed_json = json_loads(self.body)

        return self.parsed_json 

    @property
    def args(self):
        if not self.parsed_args and self.query_string:
            self.parsed_args = {k:v if len(v)>1 else v[0] for k,v in parse_qs(self.query_string).items()}<commit_msg>Args should be an empty dict if none exist<commit_after>import argparse
import sys
import asyncio
import signal
import functools
import httptools
import logging
from inspect import isawaitable
from ujson import loads as json_loads
from urllib.parse import parse_qs
from traceback import format_exc

import httptools
try:
    import uvloop as async_loop
except:
    async_loop = asyncio

from socket import *

from .log import log
from .config import LOGO
from .exceptions import ServerError
from .response import HTTPResponse

PRINT = 0

class Request:
    __slots__ = ('protocol', 'url', 'headers', 'version', 'method', 'query_string', 'body', 'parsed_json', 'parsed_args')

    def __init__(self, protocol, url, headers, version, method):
        self.protocol = protocol
        self.url = url
        self.headers = headers
        self.version = version
        self.method = method

        # Capture query string
        query_string_position = self.url.find(b"?")
        if query_string_position != -1:
            self.query_string = self.url[query_string_position+1:]
            self.url = self.url[:query_string_position]
        else:
            self.query_string = None

        # Init but do not inhale
        self.body = None
        self.parsed_json = None
        self.parsed_args = None

    @property
    def json(self):
        if not self.parsed_json:
            if not self.body:
                raise ValueError("No body to parse")
            self.parsed_json = json_loads(self.body)

        return self.parsed_json 

    @property
    def args(self):
        if self.parsed_args is None:
            if self.query_string:
                self.parsed_args = {k:v if len(v)>1 else v[0] for k,v in parse_qs(self.query_string).items()}
            else:
                self.parsed_args = {}
{'fraction_non_alphanumeric': 0.08043047295383744, 'fraction_numerical': 0.002832058906825262, 'mean_word_length': 2.571284125379171, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5955263', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1025, 'n_words': 318}