-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRequest.py
More file actions
145 lines (98 loc) · 3.54 KB
/
Request.py
File metadata and controls
145 lines (98 loc) · 3.54 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""An abstract request"""
from MiscUtils import AbstractError
from MiscUtils.Funcs import asclocaltime
class Request:
"""The abstract request class.
Request is a base class that offers the following:
* A time stamp (indicating when the request was made)
* An input stream
* Remote request information (address, name)
* Local host information (address, name, port)
* A security indicator
Request is an abstract class; developers typically use HTTPRequest.
"""
# region Init
def __init__(self):
"""Initialize the request.
Subclasses are responsible for invoking super
and initializing self._time.
"""
self._transaction = None
# endregion Init
# region Access
def time(self):
return self._time # pylint: disable=no-member
def timeStamp(self):
"""Return time() as human readable string for logging and debugging."""
return asclocaltime(self.time())
# endregion Access
# region Input
def input(self):
"""Return a file-style object that the contents can be read from."""
# This is bogus. Disregard for now.
# endregion Input
# region Remote info
def remoteAddress(self):
"""Get the remote address.
Returns a string containing the Internet Protocol (IP) address
of the client that sent the request.
"""
raise AbstractError(self.__class__)
def remoteName(self):
"""Get the remote name.
Returns the fully qualified name of the client that sent the request,
or the IP address of the client if the name cannot be determined.
"""
raise AbstractError(self.__class__)
# endregion Remote info
# region Local info
def localAddress(self):
"""Get local address.
Returns a string containing the Internet Protocol (IP) address
of the local host (e.g., the server) that received the request.
"""
raise AbstractError(self.__class__)
@staticmethod
def localName():
"""Get local name.
Returns the fully qualified name of the local host (e.g., the server)
that received the request.
"""
return 'localhost'
def localPort(self):
"""Get local port.
Returns the port of the local host (e.g., the server)
that received the request.
"""
raise AbstractError(self.__class__)
# endregion Local info
# region Security
def isSecure(self):
"""Check whether this is a secure channel.
Returns true if request was made using a secure channel,
such as HTTPS. This currently always returns false,
since secure channels are not yet supported.
"""
return False
# endregion Security
# region Transactions
def responseClass(self):
"""Get the corresponding response class."""
raise AbstractError(self.__class__)
def setTransaction(self, trans):
"""Set a transaction container."""
self._transaction = trans
def transaction(self):
"""Get the transaction container."""
return self._transaction
# endregion Transactions
# region Cleanup
def clearTransaction(self):
del self._transaction
# endregion Cleanup
# region Exception reports
_exceptionReportAttrNames = []
def writeExceptionReport(self, handler):
handler.writeTitle(self.__class__.__name__)
handler.writeAttrs(self, self._exceptionReportAttrNames)
# endregion Exception reports