aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mirrorselect/mirrorparser3.py')
-rw-r--r--mirrorselect/mirrorparser3.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/mirrorselect/mirrorparser3.py b/mirrorselect/mirrorparser3.py
index e34f9c2..976ff17 100644
--- a/mirrorselect/mirrorparser3.py
+++ b/mirrorselect/mirrorparser3.py
@@ -35,7 +35,15 @@ MIRRORS_3_XML = 'http://www.gentoo.org/main/en/mirrors3.xml'
MIRRORS_RSYNC_DATA = 'http://www.gentoo.org/main/en/mirrors-rsync-data.xml'
class MirrorParser3:
- def __init__(self):
+ def __init__(self, options=None):
+ self.filters = {}
+ for opt in ["country", "region"]:
+ value = getattr(options, opt)
+ if value is not None:
+ self.filters[opt] = value
+ for opt in ["ftp", "http"]:
+ if getattr(options, opt):
+ self.filters["proto"] = opt
self._reset()
def _reset(self):
@@ -51,7 +59,7 @@ class MirrorParser3:
name = e.text
if e.tag == 'uri':
uri = e.text
- self._dict[uri] = {
+ data = {
"name": name,
"country": mirrorgroup.get("countryname"),
"region": mirrorgroup.get("region"),
@@ -59,6 +67,15 @@ class MirrorParser3:
"ipv6": e.get("ipv6"),
"proto": e.get("protocol"),
}
+ if len(self.filters):
+ good = True
+ for f in self.filters:
+ if data[f] != self.filters[f]:
+ good = False
+ if good:
+ self._dict[uri] = data
+ else:
+ self._dict[uri] = data
def tuples(self):
return [(url, args) for url, args in list(self._dict.items())]