MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/uuid.py:935–992  ·  view source on GitHub ↗

Run the uuid command line interface.

()

Source from the content-addressed store, hash-verified

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

Callers 1

uuid.pyFile · 0.70

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…