nicer __str__ and __repr__ methods on rql constraints
"""hooks triggered on email entities creation:* look for state change instruction (XXX security)* set email content as a comment on an entity when comments are supported and linking information are found:organization: Logilab:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr"""__docformat__="restructuredtext en"importrefromcubicwebimportUnknownEid,typed_eidfromcubicweb.viewimportComponent# XXX use user session if gpg signature validatedclassTextAnalyzer(Component):"""analyze and extract information from plain text by calling registered text parsers """id='textanalyzer'defparse(self,caller,text):forparserclsinself.req.vreg['components'].get('textparser',()):parsercls(self.req).parse(caller,text)classTextParser(Component):"""base class for text parser, responsible to extract some information from plain text. When something is done, it usually call the .fire_event(something, {event args}) method on the caller. """id='textparser'__abstract__=Truedefparse(self,caller,text):raiseNotImplementedErrorclassChangeStateTextParser(TextParser):"""search some text for change state instruction in the form :<transition name>: #?<eid> """instr_rgx=re.compile(':(\w+):\s*#?(\d+)',re.U)defparse(self,caller,text):fortrname,eidinself.instr_rgx.findall(text):try:entity=self.req.entity_from_eid(typed_eid(eid))exceptUnknownEid:self.error("can't get entity with eid %s",eid)continueifnothasattr(entity,'in_state'):self.error('bad change state instruction for eid %s',eid)continuetr=entity.current_workflowandentity.current_workflow.transition_by_name(trname)iftrandtr.may_be_fired(entity.eid):try:trinfo=entity.fire_transition(tr)caller.fire_event('state-changed',{'trinfo':trinfo,'entity':entity})except:self.exception('while changing state of %s',entity)else:self.error("can't pass transition %s on entity %s",trname,entity)