-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathResponse.py
More file actions
78 lines (47 loc) · 1.7 KB
/
Copy pathResponse.py
File metadata and controls
78 lines (47 loc) · 1.7 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
"""An abstract response"""
from time import time
from MiscUtils import AbstractError
from Message import Message
class Response(Message):
"""The abstract response class.
Response is a type of Message that offers the following:
* A time stamp (indicating when the response was finished)
* An output stream
Response is an abstract class; developers typically use HTTPResponse.
FUTURE
* Consider implementing the buffer/flush logic here
including buffer size.
* Also, consider then having a method that doesn't allow
commitment until the end.
"""
## Init ##
def __init__(self, trans, strmOut):
Message.__init__(self)
self._strmOut = strmOut
self._transaction = trans
## End time ##
def endTime(self):
return self._endTime
def recordEndTime(self):
"""Record the end time of the response.
Stores the current time as the end time of the response. This should
be invoked at the end of deliver(). It may also be invoked by the
application for those responses that never deliver due to an error.
"""
self._endTime = time()
## Output ##
def write(self, string):
raise AbstractError(self.__class__)
def isCommitted(self):
raise AbstractError(self.__class__)
def deliver(self):
raise AbstractError(self.__class__)
def reset(self):
raise AbstractError(self.__class__)
def streamOut(self):
return self._strmOut
## Cleanup ##
def clearTransaction(self):
del self._transaction
## Exception reporting ##
_exceptionReportAttrNames = Message._exceptionReportAttrNames + ['endTime']