beetbox / confuse

painless YAML config files for Python
https://pypi.org/project/confuse/
MIT License
417 stars 52 forks source link

confuse should be able to return bytestrings for Filename() #51

Open ghost opened 8 years ago

sampsyo commented 8 years ago

Can you elaborate a little bit? Where exactly is this needed, and why (vs. just wrapping the lookup with bytestring_path())?

ghost commented 8 years ago

If you do:

config['foo']['file'] =  some_bytestring   # like we do in beet in various places (likely in the tests)

and then attempt

file = config['foo']['file'].as_filename()

then it'll blow up right here https://github.com/beetbox/beets/blob/master/beets/util/confit.py#L1350

sampsyo commented 8 years ago

Got it. In those cases, it's probably best to change the tests—because, in the real world, those values with be Unicode strings when they come from config files. (And we'd like to test conditions that resemble the real world.)

ghost commented 8 years ago

ok, so that's back to the age old question of converting bytestring filenames to utf-8. come up with a name for the utility function yet? :)

sampsyo commented 8 years ago

Right; good point. Let's call it unicode_path, I suppose. On Python 3, it can use surrogateescape; on Python 2, I suppose it should just use strict errors.