Skip to content

Commit 42db57b

Browse files
committed
drop text-encoding 2isms
1 parent 0de3ae0 commit 42db57b

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

plotdevice/gfx/text.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,20 @@ def append(self, txt=None, **kwargs):
119119
if not is_xml:
120120
txt_bytes = txt.encode('utf-8')
121121
txt_opts = {'CharacterEncoding': NSUTF8StringEncoding}
122-
decoded, info, err = NSMutableAttributedString.alloc().initWithData_options_documentAttributes_error_(
122+
txt, info, err = NSMutableAttributedString.alloc().initWithData_options_documentAttributes_error_(
123123
NSData.dataWithBytes_length_(txt_bytes, len(txt_bytes)), txt_opts, None, None
124124
)
125125

126126
# if the data got unpacked into anything more interesting than plain text,
127127
# preserve its styling. otherwise fall through and style the txt val
128128
if re.search(r'(html|rtf)$', info.get('UTI')):
129-
attrib_txt = decoded
129+
attrib_txt = txt
130130

131131
if txt is not None and not attrib_txt:
132132
# convert non-textual `str` args to strings
133133
if not isinstance(txt, str) and not is_xml:
134134
txt = repr(txt)
135135

136-
# try to insulate people from the need to use a unicode constant for any text
137-
# with high-ascii characters (while waiting for the other shoe to drop)
138-
decoded = txt #if isinstance(txt, unicode) else txt.decode('utf-8')
139-
140136
# use the inherited baseline style but allow one-off overrides from kwargs
141137
merged_style = self._font._spec
142138
merged_style.update(fill=self._fillcolor)
@@ -146,7 +142,7 @@ def append(self, txt=None, **kwargs):
146142
# its tag names. otherwise apply the merged style to the entire string
147143
if is_xml:
148144
# find any tagged regions that need styling
149-
parser = XMLParser(decoded, offset=len(self.text))
145+
parser = XMLParser(txt, offset=len(self.text))
150146

151147
# update our internal lookup table of nodes
152148
for tag, elts in parser.nodes.items():
@@ -167,7 +163,7 @@ def append(self, txt=None, **kwargs):
167163
else:
168164
# don't parse as xml, just apply the current font(), align(), and fill()
169165
attrs = self._fontify(merged_style)
170-
attrib_txt = NSMutableAttributedString.alloc().initWithString_attributes_(decoded, attrs)
166+
attrib_txt = NSMutableAttributedString.alloc().initWithString_attributes_(txt, attrs)
171167

172168
# ensure the very-first character of a Text is indented flush left. also watch for
173169
# double-newlines at the edge of the existing string and the appended chars. grafs
@@ -408,8 +404,6 @@ def find(self, regex, matches=0):
408404
Returns:
409405
a list of TextFragment objects
410406
"""
411-
# if isinstance(regex, str):
412-
# regex = regex.decode('utf-8')
413407
if isinstance(regex, str):
414408
flags = (re.I|re.S) if regex.lower()==regex else (re.S)
415409
regex = re.compile(regex, flags)
@@ -440,8 +434,6 @@ def select(self, tag_name, matches=0):
440434
Returns:
441435
a list of TextFragment objects
442436
"""
443-
if isinstance(tag_name, str):
444-
tag_name = tag_name.decode('utf-8')
445437
return self._seek(self._nodes.get(tag_name, []), matches)
446438

447439
def _seek(self, stream, limit):

0 commit comments

Comments
 (0)