Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 952a1d9

Browse files
authored
GH-88597: Rename uuid's new CLI args to be in line with uuidgen. (#101248)
this way they match an existing uuidgen command line tool.
1 parent 1417712 commit 952a1d9

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

Doc/library/uuid.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ The :mod:`uuid` module can be executed as a script from the command line.
272272

273273
.. code-block:: sh
274274
275-
python -m uuid [-h] [-u {uuid1,uuid3,uuid4,uuid5}] [-ns NAMESPACE] [-n NAME]
275+
python -m uuid [-h] [-u {uuid1,uuid3,uuid4,uuid5}] [-n NAMESPACE] [-N NAME]
276276
277277
The following options are accepted:
278278

@@ -288,13 +288,14 @@ The following options are accepted:
288288
Specify the function name to use to generate the uuid. By default :func:`uuid4`
289289
is used.
290290

291-
.. cmdoption:: -ns <namespace>
291+
.. cmdoption:: -n <namespace>
292292
--namespace <namespace>
293293

294-
The namespace used as part of generating the uuid. Only required for
295-
:func:`uuid3` / :func:`uuid5` functions.
294+
The namespace is a ``UUID``, or ``@ns`` where ``ns`` is a well-known predefined UUID
295+
addressed by namespace name. Such as ``@dns``, ``@url``, ``@oid``, and ``@x500``.
296+
Only required for :func:`uuid3` / :func:`uuid5` functions.
296297

297-
.. cmdoption:: -n <name>
298+
.. cmdoption:: -N <name>
298299
--name <name>
299300

300301
The name used as part of generating the uuid. Only required for
@@ -351,12 +352,12 @@ Here are some examples of typical usage of the :mod:`uuid` command line interfac
351352

352353
.. code-block:: shell
353354
354-
# generate a random uuid - by default uuid4() is used
355-
$ python -m uuid
355+
# generate a random uuid - by default uuid4() is used
356+
$ python -m uuid
356357
357-
# generate a uuid using uuid1()
358-
$ python -m uuid -u uuid1
358+
# generate a uuid using uuid1()
359+
$ python -m uuid -u uuid1
359360
360-
# generate a uuid using uuid5
361-
$ python -m uuid -u uuid5 -ns NAMESPACE_URL -n example.com
361+
# generate a uuid using uuid5
362+
$ python -m uuid -u uuid5 -n @url -N example.com
362363

Lib/test/test_uuid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,15 @@ def test_uuid_weakref(self):
675675
weak = weakref.ref(strong)
676676
self.assertIs(strong, weak())
677677

678-
@mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-ns", "NAMESPACE_DNS"])
678+
@mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "@dns"])
679679
def test_cli_namespace_required_for_uuid3(self):
680680
with self.assertRaises(SystemExit) as cm:
681681
self.uuid.main()
682682

683683
# Check that exception code is the same as argparse.ArgumentParser.error
684684
self.assertEqual(cm.exception.code, 2)
685685

686-
@mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "python.org"])
686+
@mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-N", "python.org"])
687687
def test_cli_name_required_for_uuid3(self):
688688
with self.assertRaises(SystemExit) as cm:
689689
self.uuid.main()
@@ -705,7 +705,7 @@ def test_cli_uuid4_outputted_with_no_args(self):
705705
self.assertEqual(uuid_output.version, 4)
706706

707707
@mock.patch.object(sys, "argv",
708-
["", "-u", "uuid3", "-ns", "NAMESPACE_DNS", "-n", "python.org"])
708+
["", "-u", "uuid3", "-n", "@dns", "-N", "python.org"])
709709
def test_cli_uuid3_ouputted_with_valid_namespace_and_name(self):
710710
stdout = io.StringIO()
711711
with contextlib.redirect_stdout(stdout):
@@ -719,7 +719,7 @@ def test_cli_uuid3_ouputted_with_valid_namespace_and_name(self):
719719
self.assertEqual(uuid_output.version, 3)
720720

721721
@mock.patch.object(sys, "argv",
722-
["", "-u", "uuid5", "-ns", "NAMESPACE_DNS", "-n", "python.org"])
722+
["", "-u", "uuid5", "-n", "@dns", "-N", "python.org"])
723723
def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self):
724724
stdout = io.StringIO()
725725
with contextlib.redirect_stdout(stdout):

Lib/uuid.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -731,28 +731,32 @@ def uuid5(namespace, name):
731731

732732
def main():
733733
"""Run the uuid command line interface."""
734-
uuid_funcs = {"uuid1": uuid1,
735-
"uuid3": uuid3,
736-
"uuid4": uuid4,
737-
"uuid5": uuid5}
734+
uuid_funcs = {
735+
"uuid1": uuid1,
736+
"uuid3": uuid3,
737+
"uuid4": uuid4,
738+
"uuid5": uuid5
739+
}
738740
uuid_namespace_funcs = ("uuid3", "uuid5")
739741
namespaces = {
740-
"NAMESPACE_DNS": NAMESPACE_DNS,
741-
"NAMESPACE_URL": NAMESPACE_URL,
742-
"NAMESPACE_OID": NAMESPACE_OID,
743-
"NAMESPACE_X500": NAMESPACE_X500
742+
"@dns": NAMESPACE_DNS,
743+
"@url": NAMESPACE_URL,
744+
"@oid": NAMESPACE_OID,
745+
"@x500": NAMESPACE_X500
744746
}
745747

746748
import argparse
747749
parser = argparse.ArgumentParser(
748750
description="Generates a uuid using the selected uuid function.")
749751
parser.add_argument("-u", "--uuid", choices=uuid_funcs.keys(), default="uuid4",
750752
help="The function to use to generate the uuid. "
751-
"By default uuid4 function is used.")
752-
parser.add_argument("-ns", "--namespace",
753-
help="The namespace used as part of generating the uuid. "
753+
"By default uuid4 function is used.")
754+
parser.add_argument("-n", "--namespace",
755+
help="The namespace is a UUID, or '@ns' where 'ns' is a "
756+
"well-known predefined UUID addressed by namespace name. "
757+
"Such as @dns, @url, @oid, and @x500. "
754758
"Only required for uuid3/uuid5 functions.")
755-
parser.add_argument("-n", "--name",
759+
parser.add_argument("-N", "--name",
756760
help="The name used as part of generating the uuid. "
757761
"Only required for uuid3/uuid5 functions.")
758762

0 commit comments

Comments
 (0)