Ticket #8215: wrong_uid_type-8215-1.patch

File wrong_uid_type-8215-1.patch, 1.7 KB (added by SamyCookie, 3 years ago)
  • twisted/web/server.py

    From 9ca7d578536e47baa6bb0b0e75e5bceb47b5ff65 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Samuel=20Bov=C3=A9e?= <samuel.bovee@zto-technology.com>
    Date: Thu, 18 Feb 2016 20:20:42 +0100
    Subject: [PATCH] Bugfix: ensure to return uuid as 'bytes' type as specified
     inside documentation for both Python 2 and 3
    
    ---
     twisted/web/server.py        |  5 +++--
     twisted/web/test/test_web.py | 11 +++++++++++
     2 files changed, 14 insertions(+), 2 deletions(-)
    
    diff --git a/twisted/web/server.py b/twisted/web/server.py
    index 2ec4d58..ece7d05 100644
    a b def _mkuid(self): 
    664664        """
    665665        (internal) Generate an opaque, unique ID for a user's session.
    666666        """
     667        from binascii import hexlify
    667668        from hashlib import md5
    668669        import random
    669670        self.counter = self.counter + 1
    670         return md5(networkString(
     671        return hexlify(md5(networkString(
    671672                "%s_%s" % (str(random.random()), str(self.counter)))
    672                    ).hexdigest()
     673                   ).digest())
    673674
    674675
    675676    def makeSession(self):
  • twisted/web/test/test_web.py

    diff --git a/twisted/web/test/test_web.py b/twisted/web/test/test_web.py
    index 0048d55..9c2611b 100644
    a b def test_buildProtocol(self): 
    108108        self.assertIs(site.requestFactory, channel.requestFactory)
    109109
    110110
     111    def test_mkuid(self):
     112        """
     113        The C{Session} uid type should be consistent with documentation, e.g.
     114        ${bytes}
     115        """
     116        site = server.Site(resource.Resource())
     117
     118        uid = site._mkuid()
     119
     120        self.assertIsInstance(uid, bytes)
     121
    111122
    112123class SessionTests(unittest.TestCase):
    113124    """