*** wikisync.py.bak	2009-09-20 19:05:16.000000000 +0300
--- wikisync.py	2009-09-20 21:34:12.000000000 +0300
***************
*** 174,179 ****
--- 174,182 ----
              self.connection = None
              return
  
+         httpauth = False
+         notallowed = _("Invalid username or password.")
+ 
          self.connection = self.createConnection()
  
          try:
***************
*** 182,192 ****
--- 185,231 ----
              raise UnsupportedWikiException(_("The wiki is currently not reachable."))
          except xmlrpclib.Fault, err:
              raise UnsupportedWikiException("xmlrpclib.Fault: %s" % str(err))
+         except xmlrpclib.ProtocolError, err:
+             if err.errmsg != "Authorization Required":
+                 raise
+ 
+             if user and password:
+                 try:
+                     import urlparse
+                     import urllib
+ 
+                     def urlQuote(string):
+                         if isinstance(string, unicode):
+                             string = string.encode("utf-8")
+                         return urllib.quote(string, "/:")
+ 
+                     scheme, netloc, path, a, b, c = \
+                         urlparse.urlparse(self.wiki_url)
+                     action = "action=xmlrpc2"
+ 
+                     user, password = map(urlQuote, [user, password])
+                     netloc = "%s:%s@%s" % (user, password, netloc)
+                     self.xmlrpc_url = urlparse.urlunparse((scheme, netloc, 
+                                                            path, "", 
+                                                            action, ""))
+ 
+                     self.connection = self.createConnection()
+                     iw_list = self.connection.interwikiName()
+ 
+                     httpauth = True
+                 except:
+                     raise NotAllowedException(notallowed)
+             elif user:
+                 return
+             else:
+                 raise NotAllowedException(notallowed)
  
          if user and password:
              token = self.connection.getAuthToken(user, password)
              if token:
                  self.token = token
+             elif httpauth:
+                 self.token = None
              else:
                  raise NotAllowedException(_("Invalid username or password."))
          else:
