Add src/nucleus/response
Тестирование ядра / Tester (push) Failing after 13m38s

This commit is contained in:
2026-06-18 17:51:30 +03:00
parent 88dcf95f3e
commit bd318ead96
4 changed files with 103 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
__author__ = 'RemiZOffAlex'
__email__ = 'remizoffalex@mail.ru'
+33
View File
@@ -0,0 +1,33 @@
__author__ = 'RemiZOffAlex'
__email__ = 'remizoffalex@mail.ru'
class Response:
def __init__(self, data, **kwargs):
self.data = data
self.status = ''
self.position = ''
self.code = 200
self.phrase = 'Success'
self.version = 'HTTP/1.1'
self.headers = {}
self.content_type = "text/plain"
for key in kwargs:
if key in self.__dict__:
setattr(self, key, kwargs[key])
def __call__(self):
status = ' '.join([self.version, str(self.code), self.phrase])
crlf = b'\r\n'*2
raw = crlf.join([
status.encode(),
self.__data.encode()
])
return raw
def __iter__(self):
pass
def __next__(self):
pass
+25
View File
@@ -0,0 +1,25 @@
__author__ = 'RemiZOffAlex'
__email__ = 'remizoffalex@mail.ru'
class Response:
def __init__(self, data, **kwargs):
self.data = data
self.code = 200
self.phrase = 'Success'
self.version = 'HTTP/1.1'
self.headers = {}
self.content_type = "text/plain"
for key in kwargs:
if key in self.__dict__:
setattr(self, key, kwargs[key])
def __call__(self):
status = ' '.join([self.version, str(self.code), self.phrase])
crlf = b'\r\n'*2
raw = crlf.join([
status.encode(),
self.data.encode()
])
return raw
+43
View File
@@ -0,0 +1,43 @@
__author__ = 'RemiZOffAlex'
__email__ = 'remizoffalex@mail.ru'
class ResponseStream:
def __init__(self, response):
self.response = response
self.status = 'creating'
self.position = ''
def __iter__(self):
self.status = 'running'
self.position = 'status'
return self
def __next__(self):
if self.status == 'eof':
raise StopIteration
response = self.response
crlf = b'\r\n'
if self.position == 'status':
status = ' '.join([
response.version,
str(response.code),
response.phrase
])
raw = status.encode()
raw += crlf
self.position = 'headers'
return raw
if self.position == 'headers':
self.position = 'body'
raw = b''
for key in response.headers:
value = response.headers[key]
raw += key.encode() + b' ' + value.encode() + crlf
raw += crlf
return raw
if self.position == 'body':
raw = response.data.encode()
self.status = 'eof'
return raw