Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Python3 support (for integration with fedora-hubs).
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Jun 10, 2015
1 parent 23f1c2d commit eef264b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions fmn/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import bs4
import docutils.examples
import markupsafe
import six

from collections import defaultdict

Expand Down Expand Up @@ -147,8 +148,8 @@ def load_rules(root='fmn.rules'):

doc = inspect.getdoc(obj)

# It's crazy, but inspect (stdlib!) doesn't return unicode objs.
if doc:
# It's crazy, but inspect (stdlib!) doesn't return unicode objs on py2.
if doc and hasattr(doc, 'decode'):
doc = doc.decode('utf-8')

if doc:
Expand All @@ -159,7 +160,7 @@ def load_rules(root='fmn.rules'):
title, doc_as_rst = doc.split('\n', 1)
doc = docutils.examples.html_parts(doc_as_rst)['body']
soup = bs4.BeautifulSoup(doc)
doc_no_links = ''.join(map(unicode, strip_anchor_tags(soup)))
doc_no_links = ''.join(map(six.text_type, strip_anchor_tags(soup)))
doc = markupsafe.Markup(doc)
doc_no_links = markupsafe.Markup(doc_no_links)
else:
Expand Down
12 changes: 7 additions & 5 deletions fmn/lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import logging
import uuid

import six

import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
Expand Down Expand Up @@ -262,9 +264,9 @@ def __repr__(self):

@property
def cache_key(self):
return hashlib.sha256(
self.code_path + str(self.negated) + self._arguments
).hexdigest()
return hashlib.sha256((
self.code_path + six.text_type(self.negated) + self._arguments
).encode('utf-8')).hexdigest()

@hybrid_property
def arguments(self):
Expand Down Expand Up @@ -379,7 +381,7 @@ def has_rule(self, session, code_path, **kw):
return False

def add_rule(self, session, paths, rule, **kw):
if isinstance(rule, basestring):
if isinstance(rule, six.string_types):
rule = Rule.create_from_code_path(session, paths, rule, **kw)
elif kw:
raise ValueError("Cannot handle rule with non-empty kw")
Expand Down Expand Up @@ -719,7 +721,7 @@ def get_filter(self, session, filter_id):

def hash_producer(*args, **kwargs):
""" Returns a random hash for a confirmation secret. """
return hashlib.md5(str(uuid.uuid4())).hexdigest()
return hashlib.md5(six.text_type(uuid.uuid4()).encode('utf-8')).hexdigest()


class Confirmation(BASE):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_description():
'docutils',
'markupsafe',
'decorator',
'six',
]

if sys.version_info[0] == 2 and sys.version_info[1] <= 6:
Expand Down

0 comments on commit eef264b

Please sign in to comment.