Skip to content

Commit

Permalink
Use defensive programming
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanjo Conti committed Aug 31, 2015
1 parent ca78c3b commit bfe8186
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nikola/plugins/command/import_wordpress.py
Expand Up @@ -337,8 +337,11 @@ def show_info_about_mising_module(modulename):
# Add tag redirects
for tag in self.all_tags:
try:
tag_str = tag.decode('utf8')
except (AttributeError, UnicodeEncodeError):
if isinstance(tag, utils.bytes_str):
tag_str = tag.decode('utf8', 'replace')
else:
tag_str = tag
except AttributeError:
tag_str = tag
tag = utils.slugify(tag_str)
src_url = '{}tag/{}'.format(self.context['SITE_URL'], tag)
Expand Down Expand Up @@ -760,8 +763,12 @@ def import_postpage_item(self, item, wordpress_namespace, out_folder=None, attac
path = unquote(parsed.path.strip('/'))

try:
path = path.decode('utf8')
except (AttributeError, UnicodeEncodeError):
if isinstance(path, utils.bytes_str):
path = path.decode('utf8', 'replace')
else:
path = path
except AttributeError:
pdb.set_trace()
pass

# Cut out the base directory.
Expand Down

0 comments on commit bfe8186

Please sign in to comment.