Skip to content

Commit

Permalink
python3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
biasmv committed Nov 1, 2015
1 parent 1cc1728 commit eaed774
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pvviewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import uuid

from viewer import Viewer
import color
import mol
from .viewer import Viewer
from . import color
from . import mol


base_url = ('http://www.rcsb.org/pdb/download/downloadFile.do'
Expand Down
2 changes: 1 addition & 1 deletion pvviewer/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contains the coloring operations
"""

from command import Command
from .command import Command


def _color_command(name, *args, **kwargs):
Expand Down
12 changes: 10 additions & 2 deletions pvviewer/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import json

# Python2/3 compatibility
try:
string_base_type = basestring
except NameError:
string_base_type = str

def encode(obj):

Expand All @@ -9,7 +14,7 @@ def encode(obj):
return obj and 'true' or 'false'
if isinstance(obj, type(None)):
return 'null'
if isinstance(obj, basestring):
if isinstance(obj, string_base_type):
# use json.dumps here to handle special characters etc.
return json.dumps(obj)
if isinstance(obj, list):
Expand All @@ -18,7 +23,10 @@ def encode(obj):
# FIXME: Nan, Inf handling
return str(obj)
if isinstance(obj, dict):
contents = ['%s:%s' % (encode(k), encode(v)) for k,v in obj.iteritems()]
# use items here for Python3 compat, even tough it's not as efficient
# as it can be. But then again, I'm not expecting huge dictionaries
# here.
contents = ['%s:%s' % (encode(k), encode(v)) for k,v in obj.items()]
return '{%s}' % ', '.join(contents)


Expand Down
2 changes: 1 addition & 1 deletion pvviewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import uuid
from command import Command
from .command import Command

_VIEWER_SCAFFOLD_BEGIN = """
<div id="%(id)s" style="width: %(width)dpx; height: %(height)dpx"><div>
Expand Down

0 comments on commit eaed774

Please sign in to comment.