Permalink
Browse files

Catch UnicodeEncodeError when opening a Unicode filename

Fixes issue 326. Thanks to Barry Warsaw for reporting this!

git-svn-id: http://feedparser.googlecode.com/svn/trunk@681 73d2b349-402e-0410-baf4-070fd12ab5b7
  • Loading branch information...
1 parent 6e2a1f9 commit a1f8f05c092e8c686548008057048839024b670b kurtmckee committed Feb 9, 2012
Showing with 6 additions and 1 deletion.
  1. +1 −0 NEWS
  2. +5 −1 feedparser/feedparser.py
View
1 NEWS
@@ -8,6 +8,7 @@ Changes coming in the next release:
* Issue 321 (malformed URIs can cause ValueError to be thrown)
* Issue 323 (installing chardet causes 11 unit test failures)
* Issue 325 (map `description_detail` to `summary_detail`)
+ * Issue 326 (Unicode filename causes UnicodeEncodeError if locale is ASCII)
5.1 - December 2, 2011
* Extensive, extensive unit test refactoring
View
@@ -2979,7 +2979,11 @@ def _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, h
# try to open with native open function (if url_file_stream_or_string is a filename)
try:
return open(url_file_stream_or_string, 'rb')
- except IOError:
+ except (IOError, UnicodeEncodeError):
+ # if url_file_stream_or_string is a unicode object that
+ # cannot be converted to the encoding returned by
+ # sys.getfilesystemencoding(), a UnicodeEncodeError
+ # will be thrown
pass
# treat url_file_stream_or_string as string

0 comments on commit a1f8f05

Please sign in to comment.