[695] | 1 | # PyKota |
---|
| 2 | # |
---|
| 3 | # PyKota : Print Quotas for CUPS |
---|
| 4 | # |
---|
| 5 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 6 | # You're welcome to redistribute this software under the |
---|
| 7 | # terms of the GNU General Public Licence version 2.0 |
---|
| 8 | # or, at your option, any higher version. |
---|
| 9 | # |
---|
| 10 | # You can read the complete GNU GPL in the file COPYING |
---|
| 11 | # which should come along with this software, or visit |
---|
| 12 | # the Free Software Foundation's WEB site http://www.fsf.org |
---|
| 13 | # |
---|
| 14 | # $Id$ |
---|
| 15 | # |
---|
| 16 | # $Log$ |
---|
[698] | 17 | # Revision 1.3 2003/02/05 22:10:29 jalet |
---|
| 18 | # Typos |
---|
| 19 | # |
---|
[697] | 20 | # Revision 1.2 2003/02/05 22:02:22 jalet |
---|
| 21 | # __import__ statement didn't work as expected |
---|
| 22 | # |
---|
[695] | 23 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 24 | # Initial import into CVS |
---|
| 25 | # |
---|
| 26 | # |
---|
| 27 | # |
---|
| 28 | |
---|
| 29 | class PyKotaRequesterError(Exception): |
---|
| 30 | """An exception for Requester related stuff.""" |
---|
| 31 | def __init__(self, message = ""): |
---|
| 32 | self.message = message |
---|
| 33 | Exception.__init__(self, message) |
---|
| 34 | def __repr__(self): |
---|
| 35 | return self.message |
---|
| 36 | __str__ = __repr__ |
---|
| 37 | |
---|
| 38 | def openRequester(config, printername) : |
---|
| 39 | """Returns a connection handle to the appropriate requester.""" |
---|
| 40 | backend = config.getRequesterBackend(printername) |
---|
| 41 | try : |
---|
[698] | 42 | if not backend.isalpha() : |
---|
[697] | 43 | # don't trust user input |
---|
| 44 | raise ImportError |
---|
| 45 | exec "from pykota.requesters import %s as requesterbackend" % backend.lower() |
---|
[695] | 46 | except ImportError : |
---|
| 47 | raise PyKotaRequesterError, "Unsupported requester backend %s" % backend |
---|
| 48 | else : |
---|
[697] | 49 | return getattr(requesterbackend, "Requester")(config, printername) |
---|