Commit b89336a3f2a1d978a182f17a34d2f4317d2dd270

Authored by Christian Herdtweck
1 parent cb436a2f

msodde: Fix UnicodeError

Some debug-logging did not take into account that data added to
output could be non-ascii.
Showing 1 changed file with 9 additions and 9 deletions
oletools/msodde.py
... ... @@ -363,7 +363,7 @@ def process_doc_field(data):
363 363 """ check if field instructions start with DDE
364 364  
365 365 expects unicode input, returns unicode output (empty if not dde) """
366   - logger.debug('processing field {0}'.format(data))
  366 + logger.debug(u'processing field {0}'.format(data))
367 367  
368 368 if data.lstrip().lower().startswith(u'dde'):
369 369 return data
... ... @@ -626,7 +626,7 @@ def field_is_blacklisted(contents):
626 626 index = FIELD_BLACKLIST_CMDS.index(words[0].lower())
627 627 except ValueError: # first word is no blacklisted command
628 628 return False
629   - logger.debug('trying to match "{0}" to blacklist command {1}'
  629 + logger.debug(u'trying to match "{0}" to blacklist command {1}'
630 630 .format(contents, FIELD_BLACKLIST[index]))
631 631 _, nargs_required, nargs_optional, sw_with_arg, sw_solo, sw_format \
632 632 = FIELD_BLACKLIST[index]
... ... @@ -638,12 +638,12 @@ def field_is_blacklisted(contents):
638 638 break
639 639 nargs += 1
640 640 if nargs < nargs_required:
641   - logger.debug('too few args: found {0}, but need at least {1} in "{2}"'
  641 + logger.debug(u'too few args: found {0}, but need at least {1} in "{2}"'
642 642 .format(nargs, nargs_required, contents))
643 643 return False
644 644 if nargs > nargs_required + nargs_optional:
645   - logger.debug('too many args: found {0}, but need at most {1}+{2} in '
646   - '"{3}"'
  645 + logger.debug(u'too many args: found {0}, but need at most {1}+{2} in '
  646 + u'"{3}"'
647 647 .format(nargs, nargs_required, nargs_optional, contents))
648 648 return False
649 649  
... ... @@ -653,14 +653,14 @@ def field_is_blacklisted(contents):
653 653 for word in words[1+nargs:]:
654 654 if expect_arg: # this is an argument for the last switch
655 655 if arg_choices and (word not in arg_choices):
656   - logger.debug('Found invalid switch argument "{0}" in "{1}"'
  656 + logger.debug(u'Found invalid switch argument "{0}" in "{1}"'
657 657 .format(word, contents))
658 658 return False
659 659 expect_arg = False
660 660 arg_choices = [] # in general, do not enforce choices
661 661 continue # "no further questions, your honor"
662 662 elif not FIELD_SWITCH_REGEX.match(word):
663   - logger.debug('expected switch, found "{0}" in "{1}"'
  663 + logger.debug(u'expected switch, found "{0}" in "{1}"'
664 664 .format(word, contents))
665 665 return False
666 666 # we want a switch and we got a valid one
... ... @@ -682,7 +682,7 @@ def field_is_blacklisted(contents):
682 682 if 'numeric' in sw_format:
683 683 arg_choices = [] # too many choices to list them here
684 684 else:
685   - logger.debug('unexpected switch {0} in "{1}"'
  685 + logger.debug(u'unexpected switch {0} in "{1}"'
686 686 .format(switch, contents))
687 687 return False
688 688  
... ... @@ -900,7 +900,7 @@ def process_excel_xml(filepath):
900 900 break
901 901 if formula is None:
902 902 continue
903   - logger.debug('found cell with formula {0}'.format(formula))
  903 + logger.debug(u'found cell with formula {0}'.format(formula))
904 904 match = re.match(XML_DDE_FORMAT, formula)
905 905 if match:
906 906 dde_links.append(u' '.join(match.groups()[:2]))
... ...