diff --git a/pygraphviz/agraph.py b/pygraphviz/agraph.py index d468aa40..ae43f6f5 100644 --- a/pygraphviz/agraph.py +++ b/pygraphviz/agraph.py @@ -180,7 +180,7 @@ def __init__(self, thing=None, # get the encoding from the "charset" graph attribute item = gv.agget(self.handle, b'charset') if item is not None: - self.encoding = item + self.encoding = item if type(item) is not bytes else item.decode('utf-8') else: self.encoding = _DEFAULT_ENCODING else: @@ -1742,8 +1742,8 @@ def __init__(self, handle, atype): ghandle = gv.agraphof(handle) root_handle = gv.agroot(ghandle) # get root graph try: - ah = gv.agattr(root_handle, 0, b'charset', None) - self.encoding = gv.agattrdefval(ah) + item = gv.agattrdefval(gv.agattr(root_handle, 0, b'charset', None)) + self.encoding = item if type(item) is not bytes else item.decode('utf-8') except KeyError: self.encoding = _DEFAULT_ENCODING @@ -1834,8 +1834,8 @@ def __init__(self, handle, atype): # get the encoding root_handle = gv.agroot(self.ghandle) # get root graph try: - ah = gv.agattr(root_handle, 0, b'charset', None) - self.encoding = gv.agattrdefval(ah) + item = gv.agattrdefval(gv.agattr(root_handle, 0, b'charset', None)) + self.encoding = item if type(item) is not bytes else item.decode('utf-8') except KeyError: self.encoding = _DEFAULT_ENCODING