MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

Lib/uuid.py:934–991  ·  view source on GitHub ↗

Run the uuid command line interface.

()

Source from the content-addressed store, hash-verified

932
933
934def main():
935 """Run the uuid command line interface."""
936 uuid_funcs = {
937 "uuid1": uuid1,
938 "uuid3": uuid3,
939 "uuid4": uuid4,
940 "uuid5": uuid5,
941 "uuid6": uuid6,
942 "uuid7": uuid7,
943 "uuid8": uuid8,
944 }
945 uuid_namespace_funcs = ("uuid3", "uuid5")
946 namespaces = {
947 "@dns": NAMESPACE_DNS,
948 "@url": NAMESPACE_URL,
949 "@oid": NAMESPACE_OID,
950 "@x500": NAMESPACE_X500
951 }
952
953 import argparse
954 parser = argparse.ArgumentParser(
955 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
956 description="Generate a UUID using the selected UUID function.",
957 color=True,
958 )
959 parser.add_argument("-u", "--uuid",
960 choices=uuid_funcs.keys(),
961 default="uuid4",
962 help="function to generate the UUID")
963 parser.add_argument("-n", "--namespace",
964 choices=["any UUID", *namespaces.keys()],
965 help="uuid3/uuid5 only: "
966 "a UUID, or a well-known predefined UUID addressed "
967 "by namespace name")
968 parser.add_argument("-N", "--name",
969 help="uuid3/uuid5 only: "
970 "name used as part of generating the UUID")
971 parser.add_argument("-C", "--count", metavar="NUM", type=int, default=1,
972 help="generate NUM fresh UUIDs")
973
974 args = parser.parse_args()
975 uuid_func = uuid_funcs[args.uuid]
976 namespace = args.namespace
977 name = args.name
978
979 if args.uuid in uuid_namespace_funcs:
980 if not namespace or not name:
981 parser.error(
982 "Incorrect number of arguments. "
983 f"{args.uuid} requires a namespace and a name. "
984 "Run 'python -m uuid -h' for more information."
985 )
986 namespace = namespaces[namespace] if namespace in namespaces else UUID(namespace)
987 for _ in range(args.count):
988 print(uuid_func(namespace, name))
989 else:
990 for _ in range(args.count):
991 print(uuid_func())

Callers 1

uuid.pyFile · 0.70

Calls 6

parse_argsMethod · 0.95
errorMethod · 0.95
UUIDClass · 0.85
printFunction · 0.50
add_argumentMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected