mercurial/httpconnection.py
changeset 43075 57875cf423c9
parent 41759 aaad36b88298
child 43077 687b865b95ad
equal deleted inserted replaced
43074:9cc55b743713 43075:57875cf423c9
    41         # We pass double the max for total because we currently have
    41         # We pass double the max for total because we currently have
    42         # to send the bundle twice in the case of a server that
    42         # to send the bundle twice in the case of a server that
    43         # requires authentication. Since we can't know until we try
    43         # requires authentication. Since we can't know until we try
    44         # once whether authentication will be required, just lie to
    44         # once whether authentication will be required, just lie to
    45         # the user and maybe the push succeeds suddenly at 50%.
    45         # the user and maybe the push succeeds suddenly at 50%.
    46         self._progress = ui.makeprogress(_('sending'), unit=_('kb'),
    46         self._progress = ui.makeprogress(
    47                                          total=(self.length // 1024 * 2))
    47             _('sending'), unit=_('kb'), total=(self.length // 1024 * 2)
       
    48         )
    48 
    49 
    49     def read(self, *args, **kwargs):
    50     def read(self, *args, **kwargs):
    50         ret = self._data.read(*args, **kwargs)
    51         ret = self._data.read(*args, **kwargs)
    51         if not ret:
    52         if not ret:
    52             self._progress.complete()
    53             self._progress.complete()
    58     def __enter__(self):
    59     def __enter__(self):
    59         return self
    60         return self
    60 
    61 
    61     def __exit__(self, exc_type, exc_val, exc_tb):
    62     def __exit__(self, exc_type, exc_val, exc_tb):
    62         self.close()
    63         self.close()
       
    64 
    63 
    65 
    64 # moved here from url.py to avoid a cycle
    66 # moved here from url.py to avoid a cycle
    65 def readauthforuri(ui, uri, user):
    67 def readauthforuri(ui, uri, user):
    66     uri = pycompat.bytesurl(uri)
    68     uri = pycompat.bytesurl(uri)
    67     # Read configuration
    69     # Read configuration
   107         p = prefix.split('://', 1)
   109         p = prefix.split('://', 1)
   108         if len(p) > 1:
   110         if len(p) > 1:
   109             schemes, prefix = [p[0]], p[1]
   111             schemes, prefix = [p[0]], p[1]
   110         else:
   112         else:
   111             schemes = (auth.get('schemes') or 'https').split()
   113             schemes = (auth.get('schemes') or 'https').split()
   112         if ((prefix == '*' or hostpath.startswith(prefix)) and
   114         if (
   113             (len(prefix) > bestlen or (len(prefix) == bestlen and
   115             (prefix == '*' or hostpath.startswith(prefix))
   114                                        not bestuser and 'username' in auth))
   116             and (
   115             and scheme in schemes):
   117                 len(prefix) > bestlen
       
   118                 or (
       
   119                     len(prefix) == bestlen
       
   120                     and not bestuser
       
   121                     and 'username' in auth
       
   122                 )
       
   123             )
       
   124             and scheme in schemes
       
   125         ):
   116             bestlen = len(prefix)
   126             bestlen = len(prefix)
   117             bestauth = group, auth
   127             bestauth = group, auth
   118             bestuser = auth.get('username')
   128             bestuser = auth.get('username')
   119             if user and not bestuser:
   129             if user and not bestuser:
   120                 auth['username'] = user
   130                 auth['username'] = user