root/trunk/jjigw/requests.py

Revision 165, 1.9 kB (checked in by jajcus, 2 years ago)

- addresses updated

Line 
1 #!/usr/bin/python -u
2 #
3 #  Jajcus' Jabber to IRC Gateway
4 #  Copyright (C) 2004  Jacek Konieczny <jajcus@jajcus.net>
5 #
6 #  This program is free software; you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation; either version 2 of the License, or
9 #  (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License along
17 #  with this program; if not, write to the Free Software Foundation, Inc.,
18 #  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 # vi: sts=4 et sw=4
59
Note: See TracBrowser for help on using the browser.