Skip to content

Commit

Permalink
Make it Compatible with Python3
Browse files Browse the repository at this point in the history
Exception, print Syntax is not compatible with python3, this patch
fixes it. Following changes are done:

- except Exception, e  => except Exception as e
- raise Error, "MSG" => raise Error("MSG")
- print "MSG" => print("MSG")
  • Loading branch information
karelyatin committed May 12, 2017
1 parent f1645a5 commit 6d155db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions pydot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import copy
try:
import dot_parser
except Exception, e:
print "Couldn't import dot_parser, loading of dot files will not be possible."
except Exception as e:
print("Couldn't import dot_parser, loading of dot files will not be possible.")

GRAPH_ATTRIBUTES = set( ['Damping', 'K', 'URL', 'aspect', 'bb', 'bgcolor',
'center', 'charset', 'clusterrank', 'colorscheme', 'comment', 'compound',
Expand Down Expand Up @@ -90,7 +90,7 @@
#
class frozendict(dict):
def _blocked_attribute(obj):
raise AttributeError, "A frozendict cannot be modified."
raise AttributeError("A frozendict cannot be modified.")
_blocked_attribute = property(_blocked_attribute)

__delitem__ = __setitem__ = clear = _blocked_attribute
Expand Down Expand Up @@ -501,10 +501,10 @@ def RegQueryValueEx( hkey, valuename ):
path = os.path.join(path, "bin")
progs = __find_executables(path)
if progs is not None :
#print "Used Windows registry"
#print("Used Windows registry")
return progs

except Exception, excp:
except Exception as excp:
#raise excp
pass
else:
Expand All @@ -519,7 +519,7 @@ def RegQueryValueEx( hkey, valuename ):
for path in os.environ['PATH'].split(os.pathsep):
progs = __find_executables(path)
if progs is not None :
#print "Used path"
#print("Used path")
return progs

# Method 3 (Windows only)
Expand All @@ -546,7 +546,7 @@ def RegQueryValueEx( hkey, valuename ):

if progs is not None :

#print "Used default install location"
#print("Used default install location")
return progs


Expand All @@ -558,7 +558,7 @@ def RegQueryValueEx( hkey, valuename ):

progs = __find_executables(path)
if progs is not None :
#print "Used path"
#print("Used path")
return progs

# Failed to find GraphViz
Expand Down Expand Up @@ -923,7 +923,7 @@ def __eq__(self, edge):
"""

if not isinstance(edge, Edge):
raise Error, "Can't compare and edge to a non-edge object."
raise Error("Can't compare and edge to a non-edge object.")

if self.get_parent_graph().get_top_graph_type() == 'graph':

Expand Down Expand Up @@ -1073,7 +1073,7 @@ def __init__(self, graph_name='G', obj_dict=None, graph_type='digraph', strict=F
self.obj_dict['attributes'] = dict(attrs)

if graph_type not in ['graph', 'digraph']:
raise Error, 'Invalid type "%s". Accepted graph types are: graph, digraph, subgraph' % graph_type
raise Error('Invalid type "%s". Accepted graph types are: graph, digraph, subgraph' % graph_type)


self.obj_dict['name'] = quote_if_necessary(graph_name)
Expand Down Expand Up @@ -2020,7 +2020,7 @@ def create(self, prog=None, format='ps'):
'Program terminated with status: %d. stderr follows: %s' % (
status, stderr_output) )
elif stderr_output:
print stderr_output
print(stderr_output)

# For each of the image files...
#
Expand Down
16 changes: 8 additions & 8 deletions pydot/dot_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def push_top_graph_stmt(str, loc, toks):
add_elements(g, element)

else:
raise ValueError, "Unknown element statement: %r " % element
raise ValueError("Unknown element statement: %r " % element)


for g in top_graphs:
Expand Down Expand Up @@ -220,14 +220,14 @@ def add_elements(g, toks, defaults_graph=None, defaults_node=None, defaults_edge
defaults_edge.update(element.attrs)

else:
raise ValueError, "Unknown DefaultStatement: %s " % element.default_type
raise ValueError("Unknown DefaultStatement: %s " % element.default_type)

elif isinstance(element, P_AttrList):

g.obj_dict['attributes'].update(element.attrs)

else:
raise ValueError, "Unknown element statement: %r" % element
raise ValueError("Unknown element statement: %r" % element)


def push_graph_stmt(str, loc, toks):
Expand Down Expand Up @@ -269,7 +269,7 @@ def push_default_stmt(str, loc, toks):
if default_type in ['graph', 'node', 'edge']:
return DefaultStatement(default_type, attrs)
else:
raise ValueError, "Unknown default statement: %r " % toks
raise ValueError("Unknown default statement: %r " % toks)


def push_attr_list(str, loc, toks):
Expand Down Expand Up @@ -525,9 +525,9 @@ def parse_dot_data(data):
else:
return [g for g in tokens]

except ParseException, err:
except ParseException as err:

print err.line
print " "*(err.column-1) + "^"
print err
print(err.line)
print(" "*(err.column-1) + "^")
print(err)
return None

0 comments on commit 6d155db

Please sign in to comment.