server/sources/datafeed.py
changeset 7399 972ed1843bd8
parent 7398 26695dd703d8
child 7444 9bb8f89fd31c
equal deleted inserted replaced
7398:26695dd703d8 7399:972ed1843bd8
    25 from base64 import b64decode
    25 from base64 import b64decode
    26 from cookielib import CookieJar
    26 from cookielib import CookieJar
    27 
    27 
    28 from lxml import etree
    28 from lxml import etree
    29 
    29 
    30 from cubicweb import RegistryNotFound, ObjectNotFound, ValidationError
    30 from cubicweb import RegistryNotFound, ObjectNotFound, ValidationError, UnknownEid
    31 from cubicweb.server.sources import AbstractSource
    31 from cubicweb.server.sources import AbstractSource
    32 from cubicweb.appobject import AppObject
    32 from cubicweb.appobject import AppObject
    33 
    33 
    34 class DataFeedSource(AbstractSource):
    34 class DataFeedSource(AbstractSource):
    35     copy_based_source = True
    35     copy_based_source = True
   216         """deleted CWSourceSchemaConfig, modify mapping accordingly"""
   216         """deleted CWSourceSchemaConfig, modify mapping accordingly"""
   217         msg = schemacfg._cw._("this parser doesn't use a mapping")
   217         msg = schemacfg._cw._("this parser doesn't use a mapping")
   218         raise ValidationError(schemacfg.eid, {None: msg})
   218         raise ValidationError(schemacfg.eid, {None: msg})
   219 
   219 
   220     def extid2entity(self, uri, etype, **sourceparams):
   220     def extid2entity(self, uri, etype, **sourceparams):
       
   221         """return an entity for the given uri. May return None if it should be
       
   222         skipped
       
   223         """
   221         sourceparams['parser'] = self
   224         sourceparams['parser'] = self
   222         eid = self.source.extid2eid(str(uri), etype, self._cw,
   225         eid = self.source.extid2eid(str(uri), etype, self._cw,
   223                                     sourceparams=sourceparams)
   226                                     sourceparams=sourceparams)
       
   227         if eid < 0:
       
   228             # entity has been moved away from its original source
       
   229             #
       
   230             # Don't give etype to entity_from_eid so we get UnknownEid if the
       
   231             # entity has been removed
       
   232             try:
       
   233                 entity = self._cw.entity_from_eid(-eid)
       
   234             except UnknownEid:
       
   235                 return None
       
   236             self.notify_updated(entity) # avoid later update from the source's data
       
   237             return entity
   224         if self.sourceuris is not None:
   238         if self.sourceuris is not None:
   225             self.sourceuris.pop(str(uri), None)
   239             self.sourceuris.pop(str(uri), None)
   226         return self._cw.entity_from_eid(eid, etype)
   240         return self._cw.entity_from_eid(eid, etype)
   227 
   241 
   228     def process(self, url, partialcommit=True):
   242     def process(self, url, partialcommit=True):