From 634aa2765f091e407d7b4a1e74d8f3492692f22f Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sat, 3 Apr 2010 02:07:13 +0100 Subject: [PATCH] Fixing unicode issues in eve_api and eve_proxy. Shouldn't blow its guts on the russian alliances --- eve_api/managers.py | 5 ++--- eve_proxy/models.py | 12 +++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/eve_api/managers.py b/eve_api/managers.py index 8633a76..733f4b7 100644 --- a/eve_api/managers.py +++ b/eve_api/managers.py @@ -79,10 +79,9 @@ class EVEPlayerCorporationManager(models.Manager): """ corp_doc = CachedDocument.objects.api_query('/corp/CorporationSheet.xml.aspx', params={'corporationID': id}) - corp_dat = corp_doc.body.decode("utf-8", "replace") # Convert incoming data to UTF-8. - dom = minidom.parseString(corp_dat) + dom = minidom.parseString(corp_doc.body.encode('utf-8')) error_node = dom.getElementsByTagName('error') @@ -93,4 +92,4 @@ class EVEPlayerCorporationManager(models.Manager): raise InvalidCorpID(id) return dom - \ No newline at end of file + diff --git a/eve_proxy/models.py b/eve_proxy/models.py index 2b58089..3d755f7 100755 --- a/eve_proxy/models.py +++ b/eve_proxy/models.py @@ -27,14 +27,12 @@ class CachedDocumentManager(models.Manager): # Retrieve the response from the server. response = conn.getresponse() # Save the response (an XML document) to the CachedDocument. - cached_doc.body = response.read() - + cached_doc.body = unicode(response.read(), 'utf-8') + try: # Parse the response via minidom - dom = minidom.parseString(cached_doc.body) + dom = minidom.parseString(cached_doc.body.encode('utf-8')) except xml.parsers.expat.ExpatError: - print "XML Parser Error:" - print cached_doc.body return # Set the CachedDocument's time_retrieved and cached_until times based @@ -97,7 +95,7 @@ class CachedDocumentManager(models.Manager): else: # Parse the document here since it was retrieved from the # database cache instead of queried for. - dom = minidom.parseString(cached_doc.body) + dom = minidom.parseString(cached_doc.body.encode('utf-8')) # Check for the presence errors. Only check the bare minimum, # generic stuff that applies to most or all queries. User-level code @@ -123,4 +121,4 @@ class CachedDocument(models.Model): cached_until = models.DateTimeField(blank=True, null=True) # The custom manager handles the querying. - objects = CachedDocumentManager() \ No newline at end of file + objects = CachedDocumentManager()