3110: Various tie-ins don't load because Random is not importable from the Crypto module

yane****@gmai***** (Google Code) (Is this you? Claim this profile.)
Dec. 23, 2013
What version are you running?

1.7.14

What's the URL of the page containing the problem?

admin/db/scmtools/repository/add/

What steps will reproduce the problem?
n/a

What is the expected output? What do you see instead?
n/a

What operating system are you using? What browser?

CentOS 6.4. Firefox 24

Please provide any additional information below.

When going to the server logs, I noted that the beanstalk and bitbucket tie-ins weren't working:

16:36:41 	ERROR 	

 - Unable to load repository hosting service bitbucket = reviewboard.hostingsvcs.bitbucket:Bitbucket: cannot import name Random

16:36:41 	ERROR 	

 - Unable to load repository hosting service beanstalk = reviewboard.hostingsvcs.beanstalk:Beanstalk: cannot import name Random

16:38:28 	ERROR 	

 - Unable to load repository hosting service bitbucket = reviewboard.hostingsvcs.bitbucket:Bitbucket: cannot import name Random

16:38:28 	ERROR 	

 - Unable to load repository hosting service beanstalk = reviewboard.hostingsvcs.beanstalk:Beanstalk: cannot import name Random

16:39:38 	ERROR 	

 - Unable to load repository hosting service bitbucket = reviewboard.hostingsvcs.bitbucket:Bitbucket: cannot import name Random

16:39:38 	ERROR 	

 - Unable to load repository hosting service beanstalk = reviewboard.hostingsvcs.beanstalk:Beanstalk: cannot import name Random

This is because Crypto doesn't have the Random object in its namespace:

# python -c 'from Crypto import Random'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name Random
# python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Crypto
>>> dir(Crypto)
['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__revision__', '__version__']
>>> Crypto.__file__
'/usr/lib64/python2.6/site-packages/Crypto/__init__.pyc'

Maybe Random should be imported from the random module instead?
#1 yane****@gmai***** (Google Code) (Is this you? Claim this profile.)
This patch fixes this issue, and allows me to add repos in CentOS 6.4.
  • +
    From d518a34130c50824749a60f2527cc342b3488d1f Mon Sep 17 00:00:00 2001
    From: Garrett <garrett.cooper@zonarsystems.com>
    Date: Tue, 15 Oct 2013 13:22:04 -0700
    Subject: [PATCH] Make crypto_utils backwards compatible with with
     python-crypto shipped on CentOS 6.4
    This resolves GoogleCode Issue 3110.
    Sponsored-by: Zonar Systems, Inc
    Signed-off-by: Garrett <garrett.cooper@zonarsystems.com>
    ---
     reviewboard/scmtools/crypto_utils.py |    5 ++++-
     1 files changed, 4 insertions(+), 1 deletions(-)
    diff --git a/reviewboard/scmtools/crypto_utils.py b/reviewboard/scmtools/crypto_utils.py
    index 03879fc..525bb8e 100644
    --- a/reviewboard/scmtools/crypto_utils.py
    +++ b/reviewboard/scmtools/crypto_utils.py
    @@ -1,5 +1,8 @@
     import base64
    -from Crypto import Random
    +try:
    +    from Crypto import Random
    +except ImportError:
    +    from Crypto.Util.randpool import RandomPool as Random
     from Crypto.Cipher import AES
     from django.conf import settings
     
    -- 
    1.7.9
david
#2 david
Please post patches to https://reviews.reviewboard.org/
david
#3 david
Fixed in 390147f
  • +Fixed