-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpParser.py
79 lines (66 loc) · 2.33 KB
/
httpParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''
File name: httpParser.py
Author: Noyel Seth
Email: [email protected]
MicroPython Version: 3.4
'''
class HttpParser:
"""
This is a class for parse HTTP response, coming from ESP8266 after complete the Post/Get operation
Using this class, you parse the HTTP Post/Get operation's response and get HTTP status code, Response.
"""
__httpErrorCode=None
__httpHeader=None
__httpResponseLength=None
__httpResponse=None
def __init__(self):
"""
The constaructor for HttpParser class
"""
self.__httpErrCode=None
self.__httpHeader=None
self.__httpResponseLength=None
self.__httpResponse=None
def parseHTTP(self, httpRes):
"""
This funtion use to parse the HTTP response and return back the HTTP status code
Return:
HTTP status code.
"""
#print(">>>>",httpRes)
if(httpRes != None):
retParseResponse=str(httpRes).partition("+IPD,")[2]
#print(">>>>>>>>>>>>>>>>>",retParseResponse)
retParseResponse=retParseResponse.split(r"\r\n\r\n");
#print(">>>>>>>>>>>>>>>>>",retParseResponse[0])
self.__httpResponse = retParseResponse[1]
#print(">>>>>>>>>>>>>>>>>???",retParseResponse[1])
self.__httpHeader=str(retParseResponse[0]).partition(":")[2]
#print("--",self.__httpHeader)
for code in str(self.__httpHeader.partition(r"\r\n")[0]).split():
if code.isdigit():
self.__httpErrCode=int(code)
if(self.__httpErrCode != 200):
self.__httpResponse=None
return self.__httpErrCode
else:
return 0
def getHTTPErrCode(self):
"""
This funtion use to get latest parsed HTTP response's status code
Return:
HTTP status code.
"""
return self.__httpErrCode
def getHTTPResponse(self):
"""
This funtion use to get latest parsed HTTP response's response massage.
Return:
HTTP response message.
"""
return self.__httpResponse
def __del__(self):
"""
The distaructor for HttpParser class
"""
pass