cubicweb/server/sources/__init__.py
branch3.25
changeset 12153 0ff0aff4413d
parent 12150 6260c88e0ff5
child 12155 4ba8fd2cd41a
equal deleted inserted replaced
12152:f34d18d0603f 12153:0ff0aff4413d
   182         """Check configuration of source entity, raise ValidationError if some
   182         """Check configuration of source entity, raise ValidationError if some
   183         errors are detected.
   183         errors are detected.
   184         """
   184         """
   185         return cls._check_config_dict(source_entity.eid, source_entity.dictconfig)
   185         return cls._check_config_dict(source_entity.eid, source_entity.dictconfig)
   186 
   186 
       
   187     def check_urls(self, source_entity):
       
   188         """Check URL of source entity: `urls` is a string that may contain one
       
   189         URL per line), and return a list of at least one validated URL.
       
   190         """
       
   191         urls = source_entity.url if source_entity.url else ''
       
   192         urls = [url.strip() for url in urls.splitlines() if url.strip()]
       
   193         if not urls:
       
   194             msg = _('specifying an URL is mandatory')
       
   195             raise ValidationError(source_entity.eid, {role_name('url', 'subject'): msg})
       
   196         return urls
       
   197 
   187     # source initialization / finalization #####################################
   198     # source initialization / finalization #####################################
   188 
   199 
   189     def set_schema(self, schema):
   200     def set_schema(self, schema):
   190         """set the instance'schema"""
   201         """set the instance'schema"""
   191         self.schema = schema
   202         self.schema = schema
   198         """method called by the repository once ready to handle request.
   209         """method called by the repository once ready to handle request.
   199         `activated` is a boolean flag telling if the source is activated or not.
   210         `activated` is a boolean flag telling if the source is activated or not.
   200         """
   211         """
   201         source_entity.complete()
   212         source_entity.complete()
   202         if source_entity.url:
   213         if source_entity.url:
   203             self.urls = [url.strip() for url in source_entity.url.splitlines()
   214             self.urls = self.check_urls(source_entity)
   204                          if url.strip()]
       
   205         else:
   215         else:
   206             self.urls = []
   216             self.urls = []
   207 
   217 
   208     PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
   218     PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
   209     def remove_sensitive_information(self, sourcedef):
   219     def remove_sensitive_information(self, sourcedef):