升级Google Application Engine程序以使用unicode

时间:2022-04-06 05:02:22

I have a simple Google App Engine app, that I wrote using ordinary strings. I realize I want to make it handle unicode. Are there any gotchas with this? I'm thinking of all the strings that I currently already have in the live database. (From real users who I don't want to upset.)

我有一个简单的Google App Engine应用程序,我使用普通字符串编写。我意识到我想让它处理unicode。这有什么问题吗?我正在考虑我目前在实时数据库中已经拥有的所有字符串。 (来自真实用户,我不想沮丧。)

3 个解决方案

#1


2  

Alexander Kojevnikov said: "The datastore internally keeps all strings in unicode."

Alexander Kojevnikov说:“数据存储区内部保留所有字符串为unicode。”

In other words, your application is already using unicode everywhere. Thank the google folks for a sensible API. No further work required.

换句话说,您的应用程序已经在任何地方使用unicode。感谢谷歌人提供合理的API。无需进一步的工作。

#2


1  

The datastore internally keeps all strings in unicode.

数据存储区内部将所有字符串保留为unicode。

#3


1  

When storing to a db.TextProperty() you need to use db.Text() like:

存储到db.TextProperty()时,您需要使用db.Text(),如:

instance.xml = db.Text(xml_string, encoding="utf_8")

instance.xml = db.Text(xml_string,encoding =“utf_8”)

And specify the correct encoding if the string doesn't have a BOM on it. Like if you get unexpected unicode data from an XML stream.

如果字符串上没有BOM,请指定正确的编码。就像从XML流中获得意外的unicode数据一样。

This happened to me when using Amazon.com's product API.

在使用Amazon.com的产品API时,这种情况发生在我身上。

Also Google's urlfetch had unicode problems dealing with that stream. So I ended up running minidom's parse() function instead of parseString() on the urllib.urlopen()'s return which acts like a stream like so to fix the problem:

此外,Google的urlfetch在处理该流时遇到了unicode问题。所以我最终在urllib.urlopen()的返回上运行minidom的parse()函数而不是parseString(),它就像一个像这样的流来解决问题:

response = urllib.urlopen(url)
xml = minidom.parse(response)

#1


2  

Alexander Kojevnikov said: "The datastore internally keeps all strings in unicode."

Alexander Kojevnikov说:“数据存储区内部保留所有字符串为unicode。”

In other words, your application is already using unicode everywhere. Thank the google folks for a sensible API. No further work required.

换句话说,您的应用程序已经在任何地方使用unicode。感谢谷歌人提供合理的API。无需进一步的工作。

#2


1  

The datastore internally keeps all strings in unicode.

数据存储区内部将所有字符串保留为unicode。

#3


1  

When storing to a db.TextProperty() you need to use db.Text() like:

存储到db.TextProperty()时,您需要使用db.Text(),如:

instance.xml = db.Text(xml_string, encoding="utf_8")

instance.xml = db.Text(xml_string,encoding =“utf_8”)

And specify the correct encoding if the string doesn't have a BOM on it. Like if you get unexpected unicode data from an XML stream.

如果字符串上没有BOM,请指定正确的编码。就像从XML流中获得意外的unicode数据一样。

This happened to me when using Amazon.com's product API.

在使用Amazon.com的产品API时,这种情况发生在我身上。

Also Google's urlfetch had unicode problems dealing with that stream. So I ended up running minidom's parse() function instead of parseString() on the urllib.urlopen()'s return which acts like a stream like so to fix the problem:

此外,Google的urlfetch在处理该流时遇到了unicode问题。所以我最终在urllib.urlopen()的返回上运行minidom的parse()函数而不是parseString(),它就像一个像这样的流来解决问题:

response = urllib.urlopen(url)
xml = minidom.parse(response)