Michael Radziej wrote:
> No, I'd propose simply to use the file system's encoding for files
> within the file system, that's all,

This will fail in some cases. The problem is that file system itself 
doesn't check (nor enforce) any encoding in file names. And files may 
come to server from different places encoded into whatever encoding 
their source is in. I just recently was hit by this with my music 
exchange service where we accept files from zip archives that can be 
made on Windows or on Unixes with different locales and also can be 
uploaded through FTP that works in "C" locale. Anyway you end up with 
just raw *bytes* in filenames and you can't rely on their encoding.

I solved the problem by using Postgres' BYTEA field type that stores 
strings as bytes and doesn't check their encoding unlike VARCHAR. Thus 
you can safely save it and select it back.

If someone needs it here's quick-and-dirty ByteAField that deals with 
proper escaping on input:

     class ByteAField(models.CharField):
       def get_db_prep_save(self, value):
         return value and ''.join(['\\%03o' % ord(c) for c in value])

       def get_internal_type(self):
         return 'CharField'

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to