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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
.TH "cmd2::History" 3 "Fri Sep 9 2011" "Cmd2" \" -*- nroff -*-
.ad l
.nh
.SH NAME
cmd2::History \-
.SH SYNOPSIS
.br
.PP
.SS "Public Member Functions"
.in +1c
.ti -1c
.RI "def \fBappend\fP"
.br
.ti -1c
.RI "def \fBextend\fP"
.br
.ti -1c
.RI "def \fBget\fP"
.br
.ti -1c
.RI "def \fBsearch\fP"
.br
.ti -1c
.RI "def \fBspan\fP"
.br
.ti -1c
.RI "def \fBto_index\fP"
.br
.ti -1c
.RI "def \fBzero_based_index\fP"
.br
.in -1c
.SS "Static Public Attributes"
.in +1c
.ti -1c
.RI "tuple \fBrangePattern\fP = re\&.compile(r'^\\s*(?P<start>[\\d]+)?\\s*\\-\\s*(?P<end>[\\d]+)?\\s*$')"
.br
.ti -1c
.RI "tuple \fBspanpattern\fP = re\&.compile(r'^\\s*(?P<start>\\-?\\d+)?\\s*(?P<separator>:|(\\\&.{2,}))?\\s*(?P<end>\\-?\\d+)?\\s*$')"
.br
.in -1c
.SH "Detailed Description"
.PP
.PP
.nf
A list of HistoryItems that knows how to respond to user requests.
>>> h = History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
>>> h.span('-2..')
['third', 'fourth']
>>> h.span('2..3')
['second', 'third']
>>> h.span('3')
['third']
>>> h.span(':')
['first', 'second', 'third', 'fourth']
>>> h.span('2..')
['second', 'third', 'fourth']
>>> h.span('-1')
['fourth']
>>> h.span('-2..-3')
['third', 'second']
>>> h.search('o')
['second', 'fourth']
>>> h.search('/IR/')
['first', 'third']
.fi
.PP
.PP
Definition at line 1304 of file cmd2\&.py'\&.
.SH "Member Function Documentation"
.PP
.SS "def cmd2::History::append (self, new)"
.PP
Definition at line 1368 of file cmd2\&.py'\&.
.PP
Referenced by extend()\&.
.PP
.nf
1368
1369 def append(self, new):
1370 new = HistoryItem(new)
1371 list\&.append(self, new)
new\&.idx = len(self)
.fi
.SS "def cmd2::History::extend (self, new)"
.PP
Definition at line 1372 of file cmd2\&.py'\&.
.PP
References cmd2::StubbornDict::append, and append()\&.
.PP
.nf
1372
1373 def extend(self, new):
1374 for n in new:
1375 self\&.append(n)
.fi
.SS "def cmd2::History::get (self, getme = \fCNone\fP, fromEnd = \fCFalse\fP)"
.PP
Definition at line 1376 of file cmd2\&.py'\&.
.PP
.nf
1376
1377 def get(self, getme=None, fromEnd=False):
1378 if not getme:
1379 return self
1380 try:
1381 getme = int(getme)
1382 if getme < 0:
1383 return self[:(-1 * getme)]
1384 else:
1385 return [self[getme-1]]
1386 except IndexError:
1387 return []
1388 except ValueError:
1389 rangeResult = self\&.rangePattern\&.search(getme)
1390 if rangeResult:
1391 start = rangeResult\&.group('start') or None
1392 end = rangeResult\&.group('start') or None
1393 if start:
1394 start = int(start) - 1
1395 if end:
1396 end = int(end)
1397 return self[start:end]
1398
1399 getme = getme\&.strip()
1400
1401 if getme\&.startswith(r'/') and getme\&.endswith(r'/'):
1402 finder = re\&.compile(getme[1:-1], re\&.DOTALL | re\&.MULTILINE | re\&.IGNORECASE)
1403 def isin(hi):
1404 return finder\&.search(hi)
1405 else:
1406 def isin(hi):
1407 return (getme\&.lower() in hi\&.lowercase)
1408 return [itm for itm in self if isin(itm)]
.fi
.SS "def cmd2::History::search (self, target)"
.PP
Definition at line 1337 of file cmd2\&.py'\&.
.PP
.nf
1337
1338 def search(self, target):
1339 target = target\&.strip()
1340 if target[0] == target[-1] == '/' and len(target) > 1:
1341 target = target[1:-1]
1342 else:
1343 target = re\&.escape(target)
1344 pattern = re\&.compile(target, re\&.IGNORECASE)
return [s for s in self if pattern\&.search(s)]
.fi
.SS "def cmd2::History::span (self, raw)"
.PP
Definition at line 1346 of file cmd2\&.py'\&.
.PP
References to_index()\&.
.PP
.nf
1346
1347 def span(self, raw):
1348 if raw\&.lower() in ('*', '-', 'all'):
1349 raw = ':'
1350 results = self\&.spanpattern\&.search(raw)
1351 if not results:
1352 raise IndexError
1353 if not results\&.group('separator'):
1354 return [self[self\&.to_index(results\&.group('start'))]]
1355 start = self\&.to_index(results\&.group('start'))
1356 end = self\&.to_index(results\&.group('end'))
1357 reverse = False
1358 if end is not None:
1359 if end < start:
1360 (start, end) = (end, start)
1361 reverse = True
1362 end += 1
1363 result = self[start:end]
1364 if reverse:
1365 result\&.reverse()
1366 return result
.fi
.SS "def cmd2::History::to_index (self, raw)"
.PP
Definition at line 1331 of file cmd2\&.py'\&.
.PP
References zero_based_index()\&.
.PP
Referenced by span()\&.
.PP
.nf
1331
1332 def to_index(self, raw):
1333 if raw:
1334 result = self\&.zero_based_index(int(raw))
1335 else:
1336 result = None
return result
.fi
.SS "def cmd2::History::zero_based_index (self, onebased)"
.PP
Definition at line 1326 of file cmd2\&.py'\&.
.PP
Referenced by to_index()\&.
.PP
.nf
1326
1327 def zero_based_index(self, onebased):
1328 result = onebased
1329 if result > 0:
1330 result -= 1
return result
.fi
.SH "Member Data Documentation"
.PP
.SS "tuple \fBcmd2::History::rangePattern\fP = re\&.compile(r'^\\s*(?P<start>[\\d]+)?\\s*\\-\\s*(?P<end>[\\d]+)?\\s*$')\fC [static]\fP"
.PP
Definition at line 1367 of file cmd2\&.py'\&.
.SS "tuple \fBcmd2::History::spanpattern\fP = re\&.compile(r'^\\s*(?P<start>\\-?\\d+)?\\s*(?P<separator>:|(\\\&.{2,}))?\\s*(?P<end>\\-?\\d+)?\\s*$')\fC [static]\fP"
.PP
Definition at line 1345 of file cmd2\&.py'\&.
.SH "Author"
.PP
Generated automatically by Doxygen for Cmd2 from the source code'\&.
|