mercurial/wireprotoserver.py
changeset 36070 90ca4986616c
parent 36069 957e773614d0
child 36071 038bcb759b75
equal deleted inserted replaced
36069:957e773614d0 36070:90ca4986616c
    62         """return the value for arguments in <args>
    62         """return the value for arguments in <args>
    63 
    63 
    64         returns a list of values (same order as <args>)"""
    64         returns a list of values (same order as <args>)"""
    65 
    65 
    66     @abc.abstractmethod
    66     @abc.abstractmethod
    67     def getfile(self, fp):
    67     def forwardpayload(self, fp):
    68         """write the whole content of a file into a file like object
    68         """Read the raw payload and forward to a file.
    69 
    69 
    70         The file is in the form::
    70         The payload is read in full before the function returns.
    71 
       
    72             (<chunk-size>\n<chunk>)+0\n
       
    73 
       
    74         chunk size is the ascii version of the int.
       
    75         """
    71         """
    76 
    72 
    77     @abc.abstractmethod
    73     @abc.abstractmethod
    78     def mayberedirectstdio(self):
    74     def mayberedirectstdio(self):
    79         """Context manager to possibly redirect stdio.
    75         """Context manager to possibly redirect stdio.
   143 
   139 
   144         argvalue = decodevaluefromheaders(self._req, r'X-HgArg')
   140         argvalue = decodevaluefromheaders(self._req, r'X-HgArg')
   145         args.update(cgi.parse_qs(argvalue, keep_blank_values=True))
   141         args.update(cgi.parse_qs(argvalue, keep_blank_values=True))
   146         return args
   142         return args
   147 
   143 
   148     def getfile(self, fp):
   144     def forwardpayload(self, fp):
   149         length = int(self._req.env[r'CONTENT_LENGTH'])
   145         length = int(self._req.env[r'CONTENT_LENGTH'])
   150         # If httppostargs is used, we need to read Content-Length
   146         # If httppostargs is used, we need to read Content-Length
   151         # minus the amount that was consumed by args.
   147         # minus the amount that was consumed by args.
   152         length -= int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0))
   148         length -= int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0))
   153         for s in util.filechunkiter(self._req, limit=length):
   149         for s in util.filechunkiter(self._req, limit=length):
   390             else:
   386             else:
   391                 val = self._fin.read(int(l))
   387                 val = self._fin.read(int(l))
   392                 data[arg] = val
   388                 data[arg] = val
   393         return [data[k] for k in keys]
   389         return [data[k] for k in keys]
   394 
   390 
   395     def getfile(self, fpout):
   391     def forwardpayload(self, fpout):
       
   392         # The file is in the form:
       
   393         #
       
   394         # <chunk size>\n<chunk>
       
   395         # ...
       
   396         # 0\n
   396         _sshv1respondbytes(self._fout, b'')
   397         _sshv1respondbytes(self._fout, b'')
   397         count = int(self._fin.readline())
   398         count = int(self._fin.readline())
   398         while count:
   399         while count:
   399             fpout.write(self._fin.read(count))
   400             fpout.write(self._fin.read(count))
   400             count = int(self._fin.readline())
   401             count = int(self._fin.readline())