def read_root_name(path: Path) -> str: try: recovering_parser = etree.XMLParser(recover=True, resolve_entities=False, no_network=True) tree = etree.parse(str(path), parser=recovering_parser) # nosec name = text.pascal_case(local_name(tree.getroot().tag)) if text.is_reserved(name): return text.pascal_case(f"{name}_Type") return name except Exception: return ""
def test_pascal_case(self): self.assertEqual("P00P", pascal_case("p00p")) self.assertEqual("Username", pascal_case("USERName")) self.assertEqual("UserName", pascal_case("UserNAME")) self.assertEqual("UserName", pascal_case("USER_name")) self.assertEqual("UserName", pascal_case("USER-NAME")) self.assertEqual("UserName", pascal_case("User_Name")) self.assertEqual("UserName", pascal_case("user_name")) self.assertEqual("SuserName", pascal_case("SUserNAME"))
def read_root_name(path: Path) -> str: try: recovering_parser = etree.XMLParser( recover=True, resolve_entities=False, no_network=True ) tree = etree.parse(str(path), parser=recovering_parser) # nosec _, local_name = split_qname(tree.getroot().tag) return text.pascal_case(utils.safe_snake(local_name, "Type")) except Exception: return ""
def test_pascal_case(self): self.assertEqual("UserName", pascal_case("userName")) self.assertEqual("UserName", pascal_case("User.Name")) self.assertEqual("UserName", pascal_case("UserName")) self.assertEqual("UserName", pascal_case("USER_NAME")) self.assertEqual("UserName", pascal_case("user_name"))
def class_name(cls, name: str) -> str: """Convert class names to pascal case.""" return text.pascal_case(safe_snake(name, "type"))
def class_name(name: str) -> str: """Apply python conventions for class names.""" return text.pascal_case(utils.safe_snake(name, "type"))