-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
models.text Behaviour (encoding choice) #1683
Comments
With the caveat that I hope you understand this would not solve your issue because we aren't catching that SystemError, I actually think this wouldn't be a bad idea if
Furthermore, assuming charade gets it wrong, then it's entirely possible that we'll still see a really awful exception because that call in the except block would not catch any errors thrown by the second call. Yes we don't handle that now but that's because we should raise an exception in the event we can't decode using that either. What catching those two would look like is: try:
content = str(self.content, encoding, errors='replace')
except (LookupError, TypeError):
pass
else:
try:
content = str(self.content, self.apparent_encoding, errors='replace')
except (LookupError, TypeError):
content = str(self.content, errors='replace') I'm not quite fond of that. And I'm not sure if it could be extracted to a function/method that would work the way we want easily. |
Closing to focus discussion on #1737 |
I have a question about the models module behaviour, around the text method.
When no encoding is given, there is an encoding detection, which is a good thing :
When an encoding is given, first try use it for decoding :
What I don't understand is, when an exception occurs, why it is not tried to use the self.apparent_encoding method, to do the
in a more clever way.
It then would be something like that :
Wouldn't it be better to try to detect the encoding instead of using locale one ?
The text was updated successfully, but these errors were encountered: