def fromstring(text, root_tag=None): try: elem = lxml.etree.fromstring(text, parser) except lxml.etree.XMLSyntaxError as e: LOGGER.debug(e) raise XMLSyntaxError(e) cleanup_namespaces(elem) if root_tag is not None: # validate XML try: path = 'schema/%s.rng' % camel_to_snake(root_tag) with resource_stream(__name__, path) as rng: lxml.etree.RelaxNG(file=rng).assertValid(elem) except IOError as e: # Probably, the schema file doesn't exist. exc_type, exc_value, exc_traceback = sys.exc_info() LOGGER.error(e) raise exc_type, exc_value, exc_traceback except lxml.etree.DocumentInvalid as e: LOGGER.debug(e) raise DocumentInvalid(e) return elem
def resource_type(cls): """ Returns the target resource type of this controller. """ name = cls.__name__[:-len('Controller')] return camel_to_snake(name).upper()
def get_resource_type(cls): # resource name should be resoleved in log_deliver, and class name # should be based on subresource name instead of resource type name. name = cls.__name__[:-len('Controller')] return camel_to_snake(name).upper()
def test_camel_to_snake(self): for s1, s2 in strs: self.assertEquals(utils.camel_to_snake(s1), s2)