MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / validate_guid

Function validate_guid

src/ifcopenshell-python/ifcopenshell/validate.py:614–633  ·  view source on GitHub ↗

Check if a given guid is valid. Don't check for `None` as `None` guid will trigger "non-optional" validation error either way. :return: `None` if guid is valid, otherwise a string with an error message.

(guid: str)

Source from the content-addressed store, hash-verified

612
613
614def validate_guid(guid: str) -> Union[str, None]:
615 """Check if a given guid is valid.
616
617 Don't check for `None` as `None` guid will trigger "non-optional" validation error either way.
618
619 :return: `None` if guid is valid, otherwise a string with an error message.
620 """
621 if len(guid) != 22:
622 return "Guid length should be 22 characters."
623 if guid[0] not in "0123":
624 return "Guid first character must be either a 0, 1, 2, or 3."
625 try:
626 ifcopenshell.guid.expand(guid)
627 except:
628 allowed_characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$"
629 if any(c for c in guid if c not in allowed_characters):
630 return "Guid contains invalid characters, allowed characters: '%s'." % allowed_characters
631 # NOTE: are there actually cases where guid won't expand, besides invalid characters?
632 return "Couldn't decompress guid, it's not base64 encoded."
633 return None
634
635
636def to_string_header_entity(header_entity):

Callers 1

validateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected