def validate_signiture(signiture: str): """unimplemented- checks that the name part of a signiture is a valid identifier and has the correct naming conventions lowercase, underscores seperating words. Args: signiture (str): [description] Returns: [type]: [description] """ if signiture.count("("): signiture = signiture.split("(") name = signiture[0].strip() params = signiture[1].strip(")").split(",") for x, y in enumerate(params): # deals w default args if y.count("="): parameter = y.split("=")[0] default = y.split("=")[1] if is_identifier(parameter): pass else: response = input( f"the default parameter {y} is invalid. remove (y/n) ?" ) if response in ("yes", "y"): del params[x] # need to check both sides of the expression. if is_identifier(default): pass else: response = input( f"the default {default} in default arg: '{y}' is invalid. remove this parameter (y/n) ?" ) if response in ("yes", "y"): del params[x] else: pass else: if is_identifier(y): pass else: response = input( f"the parameter {y} is invalid. remove (y/n) ?") if response in ("yes", "y"): del params[x] else: continue params = ",".join(params) return f"{name}({params})"
def validate_members(items, item_type="class"): """does basic validation for a standard inlines' members 1. ensure each item is identifier 2. ensure it has appropriate case items [list | str] : class name or attributes/methods to validate. item_type="class" [str] : which type of identifier to validate- class or field. returns: """ # this ibnky= if item_type == "class": return class_correct_convention(items) elif item_type in ("attribute", "method"): # This is a lil weird. item_type = "field" container = [] for item in items: item = item.strip() if is_identifier(item): container.append(case_check(item, item_type=item_type)) if len(container): return container return None
def __init__(self, ext): """Constructs an extension based off a plain string containing the correct extension syntax Args: ext (string): plain string which contains the extension syntax. this may define the parent, package or both, but will always associate these values with a class name, which inherits from these parents and is located in the list of directories named in the packages. """ cls_name = (ext.split("(")[0]).strip() self.class_name = None self.parents = object self.packages = 'root' if is_identifier(cls_name): self.class_name = ext.split("(")[0].strip() else: # no point generating extension if we cant generate a file # strip the parens if invalid class name has them invalid = ext.split('(')[0].strip() if ext.count("(") else ext print(f"Cannot produce a file with name {invalid}.\n\ Not a valid identifier") raise NoFileNameError("Invalid Identifier", invalid) if ext.count("("): if " (" in ext: # take the packages portion of ext and strip all parens self.packages = ext[ext.find(" ("):].strip(" (").strip(")") rest = ext[:ext.find(" (")] if "(" in rest: self.parents = rest.split("(")[1].strip(")") del rest else: if "(" in ext: self.parents = ext.split("(")[1].strip(")")
def validate_parent_name(title): """Need a special fn for this because classes are auto coerced to uppercase by default.""" if is_identifier(title): if corrected := case_check(title, item_type="class"): return corrected else: return title
def validate_class_name(cls, ): """ Sub function for coercing class names to proper state. cls : the class name identifier get_valid=False : the default coerces cls to validity. flipping this makes the fn ask user for replacement value until a correct one is provided. """ # whitespace makes identifiers invalid cls = cls.replace(" ", "_") if is_identifier(cls): if corrected := class_correct_convention(cls): return corrected else: return cls
def attributes_main(attr: list): """ overseer fn for ensuring validity of each attr. Args: attr ([type]): [description] """ # y is the actual value for x, y in enumerate(attr): if is_identifier(y): # heres where you would override the default # arg if you wanted to coerce the case if returned := case_check(y, item_type="field"): attr[x] = returned # dont think we need an else block because ^^ always return truthy else: response = input(f"the attribute {y} is not a valid identifier\n\ delete {y} from attribute set {attr} (y/n)?") if response in ("y", "yes"): del attr[x]
def validate_module_name(title): if is_identifier(title): if corrected := case_check(title, item_type="module"): return corrected else: return title
def test_is_identifier(self): """[summary] """ self.assertEqual(is_identifier("Example"), True) self.assertEqual(is_identifier("%$#@!"), False)