commit 5f55b1822b1dd34b50b4f4f1a8dc0e9f0f64a6e4 Author: Arturo Filastò art@fuffa.org Date: Tue Mar 19 13:52:31 2013 -0400
Use regexp instead of parsing XML.
Fix unittest of the ubuntu check --- ooni/director.py | 1 - ooni/geoip.py | 5 ++--- tests/test_geoip.py | 7 +------ 3 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/ooni/director.py b/ooni/director.py index d2f5a7c..7c8c75b 100644 --- a/ooni/director.py +++ b/ooni/director.py @@ -1,4 +1,3 @@ -import xml.etree.ElementTree as ET import random import sys import os diff --git a/ooni/geoip.py b/ooni/geoip.py index ae06608..efac5e9 100644 --- a/ooni/geoip.py +++ b/ooni/geoip.py @@ -1,4 +1,3 @@ -import xml.etree.ElementTree as ET import re import os import random @@ -83,8 +82,8 @@ class UbuntuGeoIP(HTTPGeoIPLookupper): url = "http://geoip.ubuntu.com/lookup"
def parseResponse(self, response_body): - response = ET.fromstring(response_body) - probe_ip = response.find('Ip').text + m = re.match(".*<Ip>(.*)</Ip>.*", response_body) + probe_ip = m.group(1) return probe_ip
class TorProjectGeoIP(HTTPGeoIPLookupper): diff --git a/tests/test_geoip.py b/tests/test_geoip.py index 0d7165f..88f3dcb 100644 --- a/tests/test_geoip.py +++ b/tests/test_geoip.py @@ -12,12 +12,7 @@ from ooni.geoip import UbuntuGeoIP, HTTPGeoIPLookupper, IPToLocation
class UbuntuGeoIPResource(resource.Resource): def render(self, request): - return """ - <Response> - <Ip>127.0.0.1</Ip> - <Spam>Ham</Spam> - </Response> - """ + return """<?xml version="1.0" encoding="UTF-8"?><Response><Ip>127.0.0.1</Ip><Status>OK</Status></Response>"""
class MaxMindGeoIPResource(resource.Resource): def render(self, request):