unicode filename

Gilles Bassière avatarGilles Bassière created an issue

When the file_name member of ShpResponder is assigned an unicode string, the zip.write method fails.

I guess it has to do with http://bugs.python.org/issue1734346 and it may be considered as a limitation rather than a bug.

I haven't been able to find a generic solution to this problem. My workaround was merely to cast my unicode as str but this won't work in every cases.

Regards,

Gilles

Comments (5)

  1. Dane Springmeyer

    Does this work for you?

    ^Cspringmeyer:django-shapes spring$ hg diff shapes
    diff -r 7ffecf949308 shapes/views/export.py
    --- a/shapes/views/export.py    Thu Oct 01 09:24:28 2009 -0700
    +++ b/shapes/views/export.py    Tue Oct 20 17:41:37 2009 -0700
    @@ -19,7 +19,10 @@
             self.geo_field = geo_field
             self.proj_transform = proj_transform
             self.mimetype = mimetype
    -        self.file_name = file_name
    +        try:
    +            self.file_name = file_name.encode('ascii')
    +        except UnicodeEncodeError:
    +            self.file_name = file_name.encode('utf-8')
     
         def __call__(self, *args, **kwargs):
             """
    
  2. Gilles Bassière

    That works fine for me. Thanks for your quick reply.

    In the meantime, I found another option which is to use Django's smart_str function:

    from django.utils.encoding import smart_str
    self.file_name = smart_str(file_name)
    
  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.