man: Use example.com in catchallinfo example output.
# -*- coding: UTF-8 -*-# Copyright (c) 2011, Pascal Volk# See COPYING for distribution information.""" VirtualMailManager.quotalimit ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Virtual Mail Manager's QuotaLimit class to manage quota limits for domains and accounts."""fromVirtualMailManager.pycompatimportall_=lambdamsg:msgclassQuotaLimit(object):"""Class to handle quota limit specific data."""__slots__=('_dbh','_qid','_bytes','_messages')_kwargs=('qid','bytes','messages')def__init__(self,dbh,**kwargs):"""Create a new QuotaLimit instance. Either the `qid` keyword or the `bytes` and `messages` keywords must be specified. Arguments: `dbh` : pyPgSQL.PgSQL.Connection || psycopg2._psycopg.connection A database connection for the database access. Keyword arguments: `qid` : int The id of a quota limit `bytes` : long The quota limit in bytes. `messages` : int The quota limit in number of messages """self._dbh=dbhself._qid=0self._bytes=0self._messages=0forkeyinkwargs.iterkeys():ifkeynotinself.__class__._kwargs:raiseValueError('unrecognized keyword: %r'%key)qid=kwargs.get('qid')ifqidisnotNone:assertisinstance(qid,(int,long))self._load_by_qid(qid)else:bytes_,msgs=kwargs.get('bytes'),kwargs.get('messages')assertall(isinstance(i,(int,long))foriin(bytes_,msgs))ifbytes_<0:self._bytes=-bytes_else:self._bytes=bytes_ifmsgs<0:self._messages=-msgselse:self._messages=msgsself._load_by_limit()@propertydefbytes(self):"""Quota limit in bytes."""returnself._bytes@propertydefmessages(self):"""Quota limit in number of messages."""returnself._messages@propertydefqid(self):"""The quota limit's unique ID."""returnself._qiddef__eq__(self,other):ifisinstance(other,self.__class__):returnself._qid==other._qidreturnNotImplementeddef__ne__(self,other):ifisinstance(other,self.__class__):returnself._qid!=other._qidreturnNotImplementeddef_load_by_limit(self):"""Load the quota limit by limit values from the database."""dbc=self._dbh.cursor()dbc.execute('SELECT qid FROM quotalimit WHERE bytes = %s AND ''messages = %s',(self._bytes,self._messages))res=dbc.fetchone()dbc.close()ifres:self._qid=res[0]else:self._save()def_load_by_qid(self,qid):"""Load the quota limit by its unique ID from the database."""dbc=self._dbh.cursor()dbc.execute('SELECT bytes, messages FROM quotalimit WHERE qid = %s',(qid,))res=dbc.fetchone()dbc.close()ifnotres:raiseValueError('Unknown quota limit id specified: %r'%qid)self._qid=qidself._bytes,self._messages=resdef_save(self):"""Store a new quota limit in the database."""dbc=self._dbh.cursor()dbc.execute("SELECT nextval('quotalimit_id')")self._qid=dbc.fetchone()[0]dbc.execute('INSERT INTO quotalimit (qid, bytes, messages) VALUES ''(%s, %s, %s)',(self._qid,self._bytes,self._messages))self._dbh.commit()dbc.close()del_