|
Revision 165, 1.9 kB
(checked in by jajcus, 2 years ago)
|
- addresses updated
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
from types import StringType,UnicodeType |
|---|
| 22 |
|
|---|
| 23 |
class Request: |
|---|
| 24 |
def __init__(self,command,stanza,args=None): |
|---|
| 25 |
self.command=command |
|---|
| 26 |
self.stanza=stanza |
|---|
| 27 |
self.args=args |
|---|
| 28 |
def match(self,commands,args=None): |
|---|
| 29 |
if type(commands) in (StringType,UnicodeType): |
|---|
| 30 |
commands=[commands] |
|---|
| 31 |
for c in commands: |
|---|
| 32 |
if not self.command==c: |
|---|
| 33 |
continue |
|---|
| 34 |
if args and not self.args==args: |
|---|
| 35 |
continue |
|---|
| 36 |
return 1 |
|---|
| 37 |
return 0 |
|---|
| 38 |
|
|---|
| 39 |
class RequestQueue: |
|---|
| 40 |
def __init__(self,maxsize): |
|---|
| 41 |
self.maxsize=maxsize |
|---|
| 42 |
self.requests=[] |
|---|
| 43 |
def get(self,commands,args=None): |
|---|
| 44 |
for r in self.requests: |
|---|
| 45 |
if r.match(commands): |
|---|
| 46 |
try: |
|---|
| 47 |
self.requests.remove(r) |
|---|
| 48 |
except ValueError: |
|---|
| 49 |
pass |
|---|
| 50 |
return r |
|---|
| 51 |
return None |
|---|
| 52 |
def add(self,command,stanza,args=None): |
|---|
| 53 |
r=Request(command,stanza,args) |
|---|
| 54 |
self.requests.append(r) |
|---|
| 55 |
if len(self.requests)>10: |
|---|
| 56 |
self.requests=self.requests[-10:] |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|