1
依賴我學習Python和我面臨着一個兩難的正確方法:這是用蟒蛇
from abc import ABCMeta, abstractproperty, abstractmethod
import jsocket
from acme.core import StatusCode, Direction
import acme.db as db
class ModuleThread(jsocket.ServerFactoryThread):
__metaclass__ = ABCMeta
@abstractproperty
def module_name(self):
pass
@abstractproperty
def _db_model(self):
pass
def __init__(self):
super(ModuleThread, self).__init__()
self.code = StatusCode.PENDING
self.status = None
def _get_config_for_domain(self, domain, direction):
# here I want to be sure that my db model is an instance
# of a pewee model
print self._db_model
class CheckMxThread(ModuleThread):
@property
def module_name(self):
return 'check_mx'
@property
def _db_model(self):
return db.ModMx
和呼叫
CheckMxThread()._get_config_for_domain('nocheck.mx', Direction.INCOMING)
我要確保使用self._db_model
時我得到一個Pewee模型的實例,我應該如何處理這個:
- 直接通過使用頂部導入像我做過的
- 在ModuleThread類中注入
db
包,並在子類中使用後面的self.db.ModMx
?