mercurial/worker.py
changeset 49224 cdb85d0512b8
parent 49217 13dfad0f9f7a
child 49230 5d28246b9acc
equal deleted inserted replaced
49223:13e523228623 49224:cdb85d0512b8
    66 
    66 
    67 def ismainthread():
    67 def ismainthread():
    68     return threading.current_thread() == threading.main_thread()
    68     return threading.current_thread() == threading.main_thread()
    69 
    69 
    70 
    70 
    71 class _blockingreader(object):
    71 class _blockingreader:
    72     def __init__(self, wrapped):
    72     def __init__(self, wrapped):
    73         self._wrapped = wrapped
    73         self._wrapped = wrapped
    74 
    74 
    75     # Do NOT implement readinto() by making it delegate to
    75     # Do NOT implement readinto() by making it delegate to
    76     # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
    76     # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
    88                 if not ret:
    88                 if not ret:
    89                     break
    89                     break
    90                 pos += ret
    90                 pos += ret
    91 
    91 
    92             return pos
    92             return pos
    93 
       
    94     def readline(self):
       
    95         return self._wrapped.readline()
       
    96 
       
    97     # issue multiple reads until size is fulfilled
       
    98     def read(self, size=-1):
       
    99         if size < 0:
       
   100             return self._wrapped.readall()
       
   101 
       
   102         buf = bytearray(size)
       
   103         view = memoryview(buf)
       
   104         pos = 0
       
   105 
       
   106         while pos < size:
       
   107             ret = self._wrapped.readinto(view[pos:])
       
   108             if not ret:
       
   109                 break
       
   110             pos += ret
       
   111 
       
   112         del view
       
   113         del buf[pos:]
       
   114         return bytes(buf)
       
   115 
       
   116 
       
   117 class _blockingreader:
       
   118     def __init__(self, wrapped):
       
   119         self._wrapped = wrapped
       
   120 
       
   121     # Do NOT implement readinto() by making it delegate to
       
   122     # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
       
   123     # with just read() and readline(), so we don't need to implement it.
       
   124 
    93 
   125     def readline(self):
    94     def readline(self):
   126         return self._wrapped.readline()
    95         return self._wrapped.readline()
   127 
    96 
   128     # issue multiple reads until size is fulfilled
    97     # issue multiple reads until size is fulfilled