#300 Fix Python3 support
Merged 7 years ago by jcline. Opened 7 years ago by abompard.
abompard/fedora-hubs fix-python3  into  develop

file modified
+4 -2
@@ -1,9 +1,11 @@ 

+ from __future__ import print_function

+ 

  import datetime

  import functools

  import json

  import logging

  import os

- import urlparse

+ from six.moves.urllib import parse as urlparse

  

  import flask

  import flask.json
@@ -349,7 +351,7 @@ 

              widget.hub.last_edited = datetime.datetime.utcnow()

              session.commit()

          except Exception as err:

-             print err

+             print(err)

              flask.flash(

                  'Could not save the configuration to the database '

                  'if the error persists, please warn an admin',

@@ -1,6 +1,6 @@ 

  import flask

  import unittest

- from urlparse import urlparse

+ from six.moves.urllib.parse import urlparse

  

  import hubs.tests

  import hubs.models

@@ -1,5 +1,5 @@ 

  import json

- from urlparse import urlparse

+ from six.moves.urllib.parse import urlparse

  

  import hubs.tests

  import hubs.models

@@ -1,5 +1,5 @@ 

  import unittest

- from urlparse import urlparse

+ from six.moves.urllib.parse import urlparse

  import ast # import for string to dict conversion without unicode

  

  from flask import json

file modified
+5 -9
@@ -1,7 +1,7 @@ 

  import kitchen.text.converters

  

  import hubs.models

- import httplib

+ import requests

  

  

  def required(session, value):
@@ -42,18 +42,14 @@ 

  

  

  def pagure_repo(session, value):

-     conn = httplib.HTTPSConnection("pagure.io")

-     conn.request("GET", "/%s" % value)

-     response = conn.getresponse()

-     if response.status == 200:

+     response = requests.get("https://pagure.io/%s" % value, timeout=5)

+     if response.status_code == 200:

          return value

      raise ValueError('Invalid pagure repo')

  

  

  def fedorahosted_project(session, value):

-     conn = httplib.HTTPSConnection("fedorahosted.org")

-     conn.request("GET", "/%s" % value)

-     response = conn.getresponse()

-     if response.status == 200:

+     response = requests.get("https://fedorahosted.org/%s" % value, timeout=5)

+     if response.status_code == 200:

          return value

      raise ValueError('Invalid fedorahosted project')

file modified
+3 -3
@@ -1,4 +1,4 @@ 

- import urlparse

+ from six.moves.urllib.parse import urlparse

  

  import bleach

  
@@ -10,8 +10,8 @@ 

      if name in ('alt', 'height', 'width', 'class'):

          return True

      if name == 'src':

-         p = urlparse.urlparse(value)

-         return (not p.netloc) or p.netloc == urlparse.urlparse(

+         p = urlparse(value)

+         return (not p.netloc) or p.netloc == urlparse(

              hubs.app.app.config['APP_URL']).netloc

      return False

  

file modified
+1 -1
@@ -1,4 +1,4 @@ 

- from xmlrpclib import ServerProxy

+ from six.moves.xmlrpc_client import ServerProxy

  

  import hubs.validators as validators

  from hubs.widgets.chrome import panel

file modified
+1
@@ -15,6 +15,7 @@ 

  munch

  psycopg2

  pytz

+ requests

  sqlalchemy

  markdown

  pkgwat.api

file modified
+1
@@ -34,6 +34,7 @@ 

          'Topic :: Software Development :: Libraries :: Python Modules',

          'Intended Audience :: Developers',

          'Programming Language :: Python',

+         'Programming Language :: Python :: 3',

      ],

      entry_points={

          'moksha.consumer': [

Small fixes to make the code run on Python 3.

Since this looks like a new requirement, would it be better to pick up requests as a dependency instead? Admittedly with the code below it only saves a few lines.

It would be good to add classifiers to the setup.py so it's clear to new developers what version of Python are supported. I do much prefer requests to httlib2, but it's not a blocker for me. Other than that, it looks good to me!

The reason I chose httplib2 is because it's already a requirement for flask_oidc, but requests is also a requirement for fedmsg, so it doesn't really matter to me. I'll update the code for requests and the classifiers in setup.py.

1 new commit added

  • Use requests instead of httplib2
7 years ago

You might want to slap a timeout=<timeout in seconds> to this since by default there is no timeout and this could hang for an indefinite amount of time.

One suggestion, but it looks good :thumbsup:.

1 new commit added

  • Add a timeout to the requests-based validators
7 years ago

Done, thanks for reviewing.

:thumbsup: merge whenever you're ready!

I'm apparently not allowed to merge, can you do it?
Thanks.

rebased

7 years ago

Pull-Request has been merged by jcline

7 years ago