How can I check a Python unicode string to see that it *actually* is proper Unicode?

前端 未结 5 865
一个人的身影
一个人的身影 2021-02-06 08:56

So I have this page:

http://hub.iis.sinica.edu.tw/cytoHubba/

Apparently it\'s all kinds of messed up, as it gets decoded properly but when I try to save it in po

5条回答
  •  囚心锁ツ
    2021-02-06 09:05

    To solve my similar problems with django/postgress I now do something like this

    class SafeTextField(models.TextField)
        def get_prep_value(self, value):
            encoded = base64.encodestring(value).strip()
            return super(SafeTextField, self).get_prep_value(encoded)
        def to_python(self, value):
            decoded = base64.decodestring(value)
            return super(SafeTextField, self).to_python(decoded)
    

提交回复
热议问题