diff -Nru python-apt-0.7.4ubuntu7/aptsources/distro.py python-apt-0.7.4ubuntu7netbook0belmont1/aptsources/distro.py
--- python-apt-0.7.4ubuntu7/aptsources/distro.py	2007-08-28 08:34:53.000000000 -0400
+++ python-apt-0.7.4ubuntu7netbook0belmont1/aptsources/distro.py	2009-02-05 14:44:31.000000000 -0500
@@ -174,7 +174,8 @@
         z = len(locale)
     country_code = locale[a+1:z].lower()
 
-    if mirror_template:
+    if mirror_template and \
+       re.search(self.source_template.match_uri, mirror_template):
       self.nearest_server = mirror_template % country_code
 
     if self.countries.has_key(country_code):
@@ -211,8 +212,9 @@
        (len(self.used_servers) == 1 and \
         compare_mirrors(self.used_servers[0], self.main_server)):
         mirrors.append([_("Main server"), self.main_server, True]) 
-        mirrors.append([self._get_mirror_name(self.nearest_server), 
-                       self.nearest_server, False])
+        if self.nearest_server:
+            mirrors.append([self._get_mirror_name(self.nearest_server), 
+                           self.nearest_server, False])
     elif len(self.used_servers) == 1 and not \
          compare_mirrors(self.used_servers[0], self.main_server):
         mirrors.append([_("Main server"), self.main_server, False]) 
@@ -220,7 +222,8 @@
         server = self.used_servers[0]
 
         # Append the nearest server if it's not already used            
-        if not compare_mirrors(server, self.nearest_server):
+        if self.nearest_server and \
+           not compare_mirrors(server, self.nearest_server):
             mirrors.append([self._get_mirror_name(self.nearest_server), 
                            self.nearest_server, False])
         mirrors.append([self._get_mirror_name(server), server, True])
@@ -230,12 +233,15 @@
         # in the user interface we set "custom servers" to true and 
         # append a list of all used servers 
         mirrors.append([_("Main server"), self.main_server, False])
-        mirrors.append([self._get_mirror_name(self.nearest_server), 
-                                        self.nearest_server, False])
+        if self.nearest_server:
+            mirrors.append([self._get_mirror_name(self.nearest_server), 
+                                            self.nearest_server, False])
         mirrors.append([_("Custom servers"), None, True])
         for server in self.used_servers:
-            if compare_mirrors(server, self.nearest_server) or\
-               compare_mirrors(server, self.main_server):
+            if self.nearest_server and \
+               compare_mirrors(server, self.nearest_server):
+                continue
+            elif compare_mirrors(server, self.main_server):
                 continue
             elif not [self._get_mirror_name(server), server, False] in mirrors:
                 mirrors.append([self._get_mirror_name(server), server, False])
