Skip to content

Commit 96aca0f

Browse files
authored
More fixes, goal is code quality of 6
1 parent e9d06b6 commit 96aca0f

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

picorpcserver/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def run():
142142
continue
143143
method = jreq.method
144144
if method not in _GFUNCMAP:
145-
jex = JsonRpcException(-32601,method,jreq.id)
145+
jex = JsonRPCException(-32601,method,jreq.id)
146146
resp = JSONRPCResponse(jreq)
147-
resp.fromException(je)
147+
resp.fromException(jex)
148148
resp.send(hreq)
149149
continue
150150
try:
@@ -162,6 +162,6 @@ def run():
162162
print(f"Exception caught! {str(e)}")
163163
ex = JsonRPCSystemError(e)
164164
resp = JSONRPCResponse(jreq)
165-
resp.fromException(je)
165+
resp.fromException(ex)
166166
resp.send(hreq)
167167
continue

picorpcserver/httprequest.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
Implements basic HTTP request parsing. This does not support SSL or anything like that
3+
but can be used to serve a simple web server if needed. The underlying process to jsonrpc
4+
It can verifiably stand on its own if needed.
5+
"""
6+
import socket
7+
from .netmgr import NetMgr
18
class HTTPRequest:
29

310
raw_msg = ""
@@ -11,6 +18,11 @@ class HTTPRequest:
1118
protocol = ""
1219

1320
def __init__(self,nm,sock):
21+
"""
22+
Initializes the http server, it requires the following parameters
23+
nm: A connected NetMgr object
24+
sock: A socket that is successfully listening
25+
"""
1426
self.hsock = sock
1527
self.nmgr = nm
1628
self.verbose = nm.verbose
@@ -20,15 +32,27 @@ def __init__(self,nm,sock):
2032
self._parse()
2133

2234
def socket(self):
35+
"""
36+
Returns the listening socket used to create this object
37+
"""
2338
return self.hsock
2439

2540
def net_manager(self):
41+
"""
42+
Returns the connected NetMgr object used to construct the object
43+
"""
2644
return self.nmgr
2745

2846
def raw_message(self):
47+
"""
48+
Returns the raw message read from the socket to process
49+
"""
2950
return self.raw_msg
3051

3152
def _parse(self):
53+
"""
54+
Parses the message filling in the method, url, headers, and raw message sent.
55+
"""
3256
if self.verbose:
3357
print("HTTPRequest::parse")
3458
try:
@@ -57,15 +81,33 @@ def _parse(self):
5781
return True
5882

5983
def method(self):
84+
"""
85+
The method used for this request, usually POST or GET
86+
"""
6087
return self.method
88+
6189
def url(self):
90+
"""
91+
The URL being requested
92+
"""
6293
return self.uri
94+
6395
def protocol(self):
96+
"""
97+
The request protocol, usually HTTP/1.1
98+
"""
6499
return self.protocol
100+
65101
def payload(self):
102+
"""
103+
The raw data sent after the headers. Will be blank if its a get request
104+
"""
66105
return self.payload
67106

68107
def headerval(self,key):
108+
"""
109+
Returns a case insensitive match for a header and retrieve its value
110+
"""
69111
if self.verbose:
70112
print(f"HTTPRequest::headerval ({key})")
71113

0 commit comments

Comments
 (0)