aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2009-07-20 17:01:21 +0200
committerSebastian Pipping <sebastian@pipping.org>2009-07-21 01:35:40 +0200
commit7538e4997b579daf07ffd6789f37815bc0d141d4 (patch)
tree3247d2e8810a18bf46a0c71263cb07834589089d /mirrorselect
parentAdd idl0r to list of authors (diff)
downloadmirrorselect-7538e4997b579daf07ffd6789f37815bc0d141d4.tar.gz
mirrorselect-7538e4997b579daf07ffd6789f37815bc0d141d4.tar.bz2
mirrorselect-7538e4997b579daf07ffd6789f37815bc0d141d4.zip
Migrated to tabs everywhere. Minor cleanup as complained by pylint.
Diffstat (limited to 'mirrorselect')
-rw-r--r--mirrorselect/mirrorparser.py108
-rw-r--r--mirrorselect/mirrorparser3.py60
2 files changed, 84 insertions, 84 deletions
diff --git a/mirrorselect/mirrorparser.py b/mirrorselect/mirrorparser.py
index 4b07f0f..1240690 100644
--- a/mirrorselect/mirrorparser.py
+++ b/mirrorselect/mirrorparser.py
@@ -23,68 +23,68 @@ from HTMLParser import HTMLParser
MIRRORS_XML = 'http://www.gentoo.org/main/en/mirrors.xml?passthru=1'
class MirrorParser(HTMLParser):
- """
- MirrorParser objects are fed an html input stream via the feed() method.
- After the instance is closed, the lines atribute contains an array with
- elements of the form: (url, description)
- """
+ """
+ MirrorParser objects are fed an html input stream via the feed() method.
+ After the instance is closed, the lines atribute contains an array with
+ elements of the form: (url, description)
+ """
- def __init__(self):
- HTMLParser.__init__(self)
+ def __init__(self):
+ HTMLParser.__init__(self)
- self.lines = []
- self.line = []
+ self.lines = []
+ self.line = []
- self.get_desc = False
- self.in_sect = False
- self.sect_good = False
- self.check_title = False
+ self.get_desc = False
+ self.in_sect = False
+ self.sect_good = False
+ self.check_title = False
- self.sects = ('North America', 'South America', 'Europe', 'Australia',
- 'Asia', 'Other Mirrors:', 'Partial Mirrors')
+ self.sects = ('North America', 'South America', 'Europe', 'Australia',
+ 'Asia', 'Other Mirrors:', 'Partial Mirrors')
- def handle_starttag(self, tag, attrs):
- if tag == 'section':
- self.in_sect = True
- if (tag == 'title') and self.in_sect:
- self.check_title = True
- if (tag == 'uri') and self.sect_good: #This is a good one
- self.line.append(dict(attrs)['link']) #url
- self.get_desc = True #the next data block is the description
+ def handle_starttag(self, tag, attrs):
+ if tag == 'section':
+ self.in_sect = True
+ if (tag == 'title') and self.in_sect:
+ self.check_title = True
+ if (tag == 'uri') and self.sect_good: #This is a good one
+ self.line.append(dict(attrs)['link']) #url
+ self.get_desc = True #the next data block is the description
- def handle_data(self, data):
- if self.check_title and (data in self.sects):
- self.sect_good = True
- if self.get_desc:
- if data.endswith('*'):
- data = data.replace('*', '')
- data = '* ' + data
- self.line.append(data)
- self.get_desc = False
+ def handle_data(self, data):
+ if self.check_title and (data in self.sects):
+ self.sect_good = True
+ if self.get_desc:
+ if data.endswith('*'):
+ data = data.replace('*', '')
+ data = '* ' + data
+ self.line.append(data)
+ self.get_desc = False
- def handle_endtag(self, tag):
- if tag == 'section':
- self.in_sect = False
- self.sect_good = False
- if (tag == 'uri') and (len(self.line) == 2):
- self.lines.append(tuple(self.line))
- self.line = []
+ def handle_endtag(self, tag):
+ if tag == 'section':
+ self.in_sect = False
+ self.sect_good = False
+ if (tag == 'uri') and (len(self.line) == 2):
+ self.lines.append(tuple(self.line))
+ self.line = []
- def tuples(self):
- return self.lines
+ def tuples(self):
+ return self.lines
- def uris(self):
- return [url for url, description in self.lines]
+ def uris(self):
+ return [url for url, description in self.lines]
if __name__ == '__main__':
- import urllib
- parser = MirrorParser()
- try:
- parser.feed(urllib.urlopen(MIRRORS_XML).read())
- except EnvironmentError:
- pass
- parser.close()
- print '===== tuples'
- print parser.tuples()
- print '===== uris'
- print parser.uris()
+ import urllib
+ parser = MirrorParser()
+ try:
+ parser.feed(urllib.urlopen(MIRRORS_XML).read())
+ except EnvironmentError:
+ pass
+ parser.close()
+ print '===== tuples'
+ print parser.tuples()
+ print '===== uris'
+ print parser.uris()
diff --git a/mirrorselect/mirrorparser3.py b/mirrorselect/mirrorparser3.py
index 1bde004..f307c6f 100644
--- a/mirrorselect/mirrorparser3.py
+++ b/mirrorselect/mirrorparser3.py
@@ -25,35 +25,35 @@ from xml.etree import ElementTree as ET
MIRRORS_3_XML = 'http://www.gentoo.org/main/en/mirrors3.xml'
class MirrorParser3:
- def __init__(self):
- self._reset()
-
- def _reset(self):
- self._dict = {}
-
- def parse(self, text):
- self._reset()
- for mirrorgroup in ET.XML(text):
- for mirror in mirrorgroup:
- name = ''
- for e in mirror:
- if e.tag == 'name':
- name = e.text
- if e.tag == 'uri':
- uri = e.text
- self._dict[uri] = [name, mirrorgroup.get("countryname")]
-
- def tuples(self):
- return [(url, name) for url, name in self._dict.items()]
-
- def uris(self):
- return [url for url, name in self._dict.items()]
+ def __init__(self):
+ self._reset()
+
+ def _reset(self):
+ self._dict = {}
+
+ def parse(self, text):
+ self._reset()
+ for mirrorgroup in ET.XML(text):
+ for mirror in mirrorgroup:
+ name = ''
+ for e in mirror:
+ if e.tag == 'name':
+ name = e.text
+ if e.tag == 'uri':
+ uri = e.text
+ self._dict[uri] = [name, mirrorgroup.get("countryname")]
+
+ def tuples(self):
+ return [(url, name) for url, name in self._dict.items()]
+
+ def uris(self):
+ return [url for url, name in self._dict.items()]
if __name__ == '__main__':
- import urllib
- parser = MirrorParser3()
- parser.parse(urllib.urlopen(MIRRORS_3_XML).read())
- print '===== tuples'
- print parser.tuples()
- print '===== uris'
- print parser.uris()
+ import urllib
+ parser = MirrorParser3()
+ parser.parse(urllib.urlopen(MIRRORS_3_XML).read())
+ print '===== tuples'
+ print parser.tuples()
+ print '===== uris'
+ print parser.uris()