Only encode if necessary

This commit is contained in:
John Garland 2010-06-07 20:05:34 +10:00
parent 81a837faed
commit 87879ab3b8
1 changed files with 4 additions and 2 deletions

View File

@ -126,7 +126,8 @@ def get_line_length(line, encoding="UTF-8"):
if line.count("{!") != line.count("!}"): if line.count("{!") != line.count("!}"):
raise BadColorString("Number of {! is not equal to number of !}") raise BadColorString("Number of {! is not equal to number of !}")
line = line.encode(encoding, "replace") if isinstance(line, unicode):
line = line.encode(encoding, "replace")
# Remove all the color tags # Remove all the color tags
line = strip_colors(line) line = strip_colors(line)
@ -146,7 +147,8 @@ def parse_color_string(s, encoding="UTF-8"):
if s.count("{!") != s.count("!}"): if s.count("{!") != s.count("!}"):
raise BadColorString("Number of {! is not equal to number of !}") raise BadColorString("Number of {! is not equal to number of !}")
s = s.encode(encoding, "replace") if isinstance(s, unicode):
s = s.encode(encoding, "replace")
ret = [] ret = []
# Keep track of where the strings # Keep track of where the strings