# HG changeset patch # User Marcin Kuzminski # Date 1346694443 -7200 # Node ID 3c0ae44557c4335caafd7de458f0605f8489db93 # Parent d3e5c259fe711ab81127f71b589b3a66e4f9b61e more py2.5 compatibility patches diff -r d3e5c259fe71 -r 3c0ae44557c4 rhodecode/lib/compat.py --- a/rhodecode/lib/compat.py Mon Sep 03 18:21:42 2012 +0200 +++ b/rhodecode/lib/compat.py Mon Sep 03 19:47:23 2012 +0200 @@ -407,6 +407,15 @@ #============================================================================== +# bytes +#============================================================================== +if __py_version__ >= (2, 6): + _bytes = bytes +else: + # in py2.6 bytes is a synonim for str + _bytes = str + +#============================================================================== # deque #============================================================================== @@ -416,11 +425,11 @@ #need to implement our own deque with maxlen class deque(object): - def __init__(self, iterable=(), maxlen=-1): + def __init__(self, iterable=(), maxlen= -1): if not hasattr(self, 'data'): self.left = self.right = 0 self.data = {} - self.maxlen = maxlen + self.maxlen = maxlen or -1 self.extend(iterable) def append(self, x): @@ -537,9 +546,9 @@ #============================================================================== if __py_version__ >= (2, 6): - from threading import Event + from threading import Event, Thread else: - from threading import _Verbose, Condition, Lock + from threading import _Verbose, Condition, Lock, Thread def Event(*args, **kwargs): return _Event(*args, **kwargs) diff -r d3e5c259fe71 -r 3c0ae44557c4 rhodecode/lib/subprocessio.py --- a/rhodecode/lib/subprocessio.py Mon Sep 03 18:21:42 2012 +0200 +++ b/rhodecode/lib/subprocessio.py Mon Sep 03 19:47:23 2012 +0200 @@ -24,11 +24,10 @@ ''' import os import subprocess -import threading -from rhodecode.lib.compat import deque, Event +from rhodecode.lib.compat import deque, Event, Thread, _bytes -class StreamFeeder(threading.Thread): +class StreamFeeder(Thread): """ Normal writing into pipe-like is blocking once the buffer is filled. This thread allows a thread to seep data from a file-like into a pipe @@ -39,9 +38,9 @@ super(StreamFeeder, self).__init__() self.daemon = True filelike = False - self.bytes = bytes() - if type(source) in (type(''), bytes, bytearray): # string-like - self.bytes = bytes(source) + self.bytes = _bytes() + if type(source) in (type(''), _bytes, bytearray): # string-like + self.bytes = _bytes(source) else: # can be either file pointer or file-like if type(source) in (int, long): # file pointer it is ## converting file descriptor (int) stdin into file-like @@ -77,7 +76,7 @@ return self.readiface -class InputStreamChunker(threading.Thread): +class InputStreamChunker(Thread): def __init__(self, source, target, buffer_size, chunk_size): super(InputStreamChunker, self).__init__() @@ -121,6 +120,7 @@ da = self.data_added go = self.go b = s.read(cs) + while b and go.is_set(): if len(t) > ccm: kr.clear() @@ -180,7 +180,7 @@ self.worker.data_added.wait(0.2) if len(self.data): self.worker.keep_reading.set() - return bytes(self.data.popleft()) + return _bytes(self.data.popleft()) elif self.worker.EOF.is_set(): raise StopIteration diff -r d3e5c259fe71 -r 3c0ae44557c4 rhodecode/tests/test_libs.py --- a/rhodecode/tests/test_libs.py Mon Sep 03 18:21:42 2012 +0200 +++ b/rhodecode/tests/test_libs.py Mon Sep 03 19:47:23 2012 +0200 @@ -22,7 +22,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +from __future__ import with_statement import unittest import datetime import hashlib