##// END OF EJS Templates
more py2.5 compatibility patches
marcink -
r2790:3c0ae445 beta
parent child Browse files
Show More
@@ -407,6 +407,15 b' except ImportError:'
407 407
408 408
409 409 #==============================================================================
410 # bytes
411 #==============================================================================
412 if __py_version__ >= (2, 6):
413 _bytes = bytes
414 else:
415 # in py2.6 bytes is a synonim for str
416 _bytes = str
417
418 #==============================================================================
410 419 # deque
411 420 #==============================================================================
412 421
@@ -416,11 +425,11 b' else:'
416 425 #need to implement our own deque with maxlen
417 426 class deque(object):
418 427
419 def __init__(self, iterable=(), maxlen=-1):
428 def __init__(self, iterable=(), maxlen= -1):
420 429 if not hasattr(self, 'data'):
421 430 self.left = self.right = 0
422 431 self.data = {}
423 self.maxlen = maxlen
432 self.maxlen = maxlen or -1
424 433 self.extend(iterable)
425 434
426 435 def append(self, x):
@@ -537,9 +546,9 b' else:'
537 546 #==============================================================================
538 547
539 548 if __py_version__ >= (2, 6):
540 from threading import Event
549 from threading import Event, Thread
541 550 else:
542 from threading import _Verbose, Condition, Lock
551 from threading import _Verbose, Condition, Lock, Thread
543 552
544 553 def Event(*args, **kwargs):
545 554 return _Event(*args, **kwargs)
@@ -24,11 +24,10 b' If not, see <http://www.gnu.org/licenses'
24 24 '''
25 25 import os
26 26 import subprocess
27 import threading
28 from rhodecode.lib.compat import deque, Event
27 from rhodecode.lib.compat import deque, Event, Thread, _bytes
29 28
30 29
31 class StreamFeeder(threading.Thread):
30 class StreamFeeder(Thread):
32 31 """
33 32 Normal writing into pipe-like is blocking once the buffer is filled.
34 33 This thread allows a thread to seep data from a file-like into a pipe
@@ -39,9 +38,9 b' class StreamFeeder(threading.Thread):'
39 38 super(StreamFeeder, self).__init__()
40 39 self.daemon = True
41 40 filelike = False
42 self.bytes = bytes()
43 if type(source) in (type(''), bytes, bytearray): # string-like
44 self.bytes = bytes(source)
41 self.bytes = _bytes()
42 if type(source) in (type(''), _bytes, bytearray): # string-like
43 self.bytes = _bytes(source)
45 44 else: # can be either file pointer or file-like
46 45 if type(source) in (int, long): # file pointer it is
47 46 ## converting file descriptor (int) stdin into file-like
@@ -77,7 +76,7 b' class StreamFeeder(threading.Thread):'
77 76 return self.readiface
78 77
79 78
80 class InputStreamChunker(threading.Thread):
79 class InputStreamChunker(Thread):
81 80 def __init__(self, source, target, buffer_size, chunk_size):
82 81
83 82 super(InputStreamChunker, self).__init__()
@@ -121,6 +120,7 b' class InputStreamChunker(threading.Threa'
121 120 da = self.data_added
122 121 go = self.go
123 122 b = s.read(cs)
123
124 124 while b and go.is_set():
125 125 if len(t) > ccm:
126 126 kr.clear()
@@ -180,7 +180,7 b' class BufferedGenerator():'
180 180 self.worker.data_added.wait(0.2)
181 181 if len(self.data):
182 182 self.worker.keep_reading.set()
183 return bytes(self.data.popleft())
183 return _bytes(self.data.popleft())
184 184 elif self.worker.EOF.is_set():
185 185 raise StopIteration
186 186
@@ -22,7 +22,7 b''
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
25 from __future__ import with_statement
26 26 import unittest
27 27 import datetime
28 28 import hashlib
General Comments 0
You need to be logged in to leave comments. Login now