blob: 288d953947560ff92fe239660fb97b0052e91f10 (
plain)
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
|
#!/usr/bin/python
# -- Content-Encoding: UTF-8 --
"""
The history module.
:authors: Josh Marshall, Thomas Calmant
:copyright: Copyright 2015, isandlaTech
:license: Apache License 2.0
:version: 0.2.5
..
Copyright 2015 isandlaTech
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# Module version
__version_info__ = (0, 2, 5)
__version__ = ".".join(str(x) for x in __version_info__)
# Documentation strings format
__docformat__ = "restructuredtext en"
# ------------------------------------------------------------------------------
class History(object):
"""
This holds all the response and request objects for a
session. A server using this should call "clear" after
each request cycle in order to keep it from clogging
memory.
"""
def __init__(self):
"""
Sets up members
"""
self.requests = []
self.responses = []
def add_response(self, response_obj):
"""
Adds a response to the history
:param response_obj: Response content
"""
self.responses.append(response_obj)
def add_request(self, request_obj):
"""
Adds a request to the history
:param request_obj: A request object
"""
self.requests.append(request_obj)
@property
def request(self):
"""
Returns the latest stored request or None
"""
try:
return self.requests[-1]
except IndexError:
return None
@property
def response(self):
"""
Returns the latest stored response or None
"""
try:
return self.responses[-1]
except IndexError:
return None
def clear(self):
"""
Clears the history lists
"""
del self.requests[:]
del self.responses[:]
|