Barry Warsaw pushed to branch master at mailman / Mailman

Commits:
187dad97 by Barry Warsaw at 2016-01-13T12:20:40-05:00
Just a little more UUID conversion convenience.

- - - - -


3 changed files:

- src/mailman/core/api.py
- src/mailman/interfaces/api.py
- src/mailman/rest/members.py


Changes:

=====================================
src/mailman/core/api.py
=====================================
--- a/src/mailman/core/api.py
+++ b/src/mailman/core/api.py
@@ -51,9 +51,11 @@ class API30:
         return uuid.int
 
     @staticmethod
-    def to_uuid(uuid_repr):
+    def to_uuid(uuid):
         """See `IAPI`."""
-        return UUID(int=int(uuid_repr))
+        if isinstance(uuid, UUID):
+            return uuid
+        return UUID(int=int(uuid))
 
 
 @implementer(IAPI)
@@ -77,6 +79,8 @@ class API31:
         return uuid.hex
 
     @staticmethod
-    def to_uuid(uuid_repr):
+    def to_uuid(uuid):
         """See `IAPI`."""
-        return UUID(hex=uuid_repr)
+        if isinstance(uuid, UUID):
+            return uuid
+        return UUID(hex=uuid)


=====================================
src/mailman/interfaces/api.py
=====================================
--- a/src/mailman/interfaces/api.py
+++ b/src/mailman/interfaces/api.py
@@ -55,11 +55,11 @@ class IAPI(Interface):
     def to_uuid(uuid):
         """Return the UUID from the string representation.
 
-        :param uuid: The string representation of the UUID.
-        :type uuid: str
-        :return: The UUID converted from the string representation, as
-            appropriate for the API version.  In 3.0, uuid is interpreted as
-            the integer representation of a UUID, while in 3.1 it is the hex
-            representation of the UUID.
+        :param uuid: A UUID, or the string representation of the UUID.
+        :type uuid: UUID or str
+        :return: The UUID, converted if needed as appropriate for the
+            API version.  In 3.0, the string representation is
+            interpreted as an integer, while in 3.1 it is the hex
+            string.
         :rtype: UUID
         """


=====================================
src/mailman/rest/members.py
=====================================
--- a/src/mailman/rest/members.py
+++ b/src/mailman/rest/members.py
@@ -111,18 +111,12 @@ class AMember(_MemberBase):
         # The member_id is either the member's UUID or the string
         # representation of the member's UUID.
         self.api = api
-        self._member = None
         service = getUtility(ISubscriptionService)
-        if isinstance(member_id, UUID):
-            self._member = service.get_member(member_id)
-        else:
-            try:
-                member_id = api.to_uuid(member_id)
-            except ValueError:
-                # The string argument could not be converted to a UUID.
-                pass
-            else:
-                self._member = service.get_member(member_id)
+        try:
+            self._member = service.get_member(api.to_uuid(member_id))
+        except ValueError:
+            # The string argument could not be converted to a UUID.
+            self._member = None
 
     def on_get(self, request, response):
         """Return a single member end-point."""



View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/187dad97bf278b0ca9d080774072e8fb235154cc
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to