← Back to team overview

beeseek-devs team mailing list archive

[Branch ~beeseek-devs/beeseek/trunk] Rev 204: Merge IStreamDecoder and ISocketDecoder interfaces.

 

------------------------------------------------------------
revno: 204
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-01-28 20:11:32 +0100
message:
  Merge IStreamDecoder and ISocketDecoder interfaces.
  The interface IStreamDecoder has been removed. ISocketDecoder has been 
  renamed in IDecoder. Developers have now a unique interface for decoders 
  and a standard way to deal with them.
modified:
  beeseek/decoders/base.py
  beeseek/decoders/chunks.py
  beeseek/decoders/gzip.py
  beeseek/network/http.py
    ------------------------------------------------------------
    revno: 200.1.13
    committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
    branch nick: decoders
    timestamp: Wed 2009-01-28 20:08:55 +0100
    message:
      Fix import.
    modified:
      beeseek/network/http.py
    ------------------------------------------------------------
    revno: 200.1.12
    committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
    branch nick: decoders
    timestamp: Wed 2009-01-28 19:51:01 +0100
    message:
      Adapt GzipDecoder to the new interface.
    modified:
      beeseek/decoders/gzip.py
    ------------------------------------------------------------
    revno: 200.1.11
    committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
    branch nick: decoders
    timestamp: Tue 2009-01-27 18:50:41 +0100
    message:
      Remove IStreamDecoder in favour of ISocketDecoder (now IDecoder).
    modified:
      beeseek/decoders/base.py
      beeseek/decoders/chunks.py
      beeseek/decoders/gzip.py
    ------------------------------------------------------------
    revno: 200.1.10
    committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
    branch nick: decoders
    timestamp: Tue 2009-01-27 18:43:13 +0100
    message:
      Merge from trunk.
    modified:
      beeseek/network/http.py

=== modified file 'beeseek/decoders/base.py'
--- a/beeseek/decoders/base.py	2009-01-20 19:12:44 +0000
+++ b/beeseek/decoders/base.py	2009-01-27 17:50:41 +0000
@@ -17,26 +17,10 @@
 
 from beeseek.interfaces import Interface, implements
 
-__all__ = 'IDecoder', 'IStreamDecoder', 'ISocketDecoder', 'NullSocketDecoder'
+__all__ = 'IDecoder', 'NullDecoder'
 
 
 class IDecoder(Interface):
-    """Base interface for all decoders."""
-
-
-class IStreamDecoder(IDecoder):
-    """Decode the given data."""
-
-    def decode(self, data):
-        """Decode the given data.
-
-        :param data: The encoded string.
-        :type data: str
-        :return: A string with the decoded data.
-        """
-
-
-class ISocketDecoder(IDecoder):
     """Decode data from a socket.
 
     Get the string from a socket and decode them.
@@ -71,17 +55,9 @@
         pass
 
 
-class NullStreamDecoder(object):
-
-    implements(IStreamDecoder)
-
-    def decode(self, data):
-        return data
-
-
-class NullSocketDecoder(object):
-
-    implements(ISocketDecoder)
+class NullDecoder(object):
+
+    implements(IDecoder)
 
     def recv(self, fp, size=-1):
         return fp.raw_recv(size)

=== modified file 'beeseek/decoders/chunks.py'
--- a/beeseek/decoders/chunks.py	2009-01-19 19:38:06 +0000
+++ b/beeseek/decoders/chunks.py	2009-01-27 17:50:41 +0000
@@ -16,7 +16,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from beeseek.interfaces import implements
-from beeseek.decoders import ISocketDecoder
+from beeseek.decoders import IDecoder
 
 __all__ = 'ChunksDecoder', 'FixedLengthChunkDecoder'
 
@@ -24,7 +24,7 @@
 class ChunksDecoder(object):
 
     __slots__ = '_chunklen'
-    implements(ISocketDecoder)
+    implements(IDecoder)
 
     def __init__(self):
         self._chunklen = 0

=== modified file 'beeseek/decoders/gzip.py'
--- a/beeseek/decoders/gzip.py	2009-01-20 19:12:58 +0000
+++ b/beeseek/decoders/gzip.py	2009-01-28 18:51:01 +0000
@@ -17,28 +17,49 @@
 
 import zlib
 from beeseek.interfaces import implements
-from beeseek.decoders import IStreamDecoder
+from beeseek.decoders import IDecoder
 
 __all__ = ('GzipDecoder',)
 
 
 class GzipDecoder(object):
 
-    __slots__ = '_decompress', '_header'
-    implements(IStreamDecoder)
+    __slots__ = '_decompress', '_buffer', '_header'
+    implements(IDecoder)
 
     def __init__(self):
         self._decompress = None
+        self._buffer = ''
         self._header = 10
 
-    def decode(self, buf):
+    def _decode(self, data):
         if not self._decompress:
             header = self._header
-            read = header - len(buf)
+            read = header - len(data)
             if read >= 0:
                 self._header = read
                 return ''
             else:
-                buf = buf[header:]
+                data = data[header:]
             self._decompress = zlib.decompressobj().decompress
-        return self._decompress(buf)
+        return self._decompress(data)
+
+    def _read_buffer(self, size):
+        data = self._buffer
+        self._buffer = data[size:]
+        return data[:size]
+
+    def recv(self, fp, size=-1):
+        if size < 0:
+            data = self._buffer
+            if not data:
+                return self._decode(fp.raw_recv(size))
+            else:
+                self._buffer = ''
+                return data
+        else:
+            data = self._read_buffer(size)
+            if not data:
+                return self._decode(fp.raw_recv(size))
+            else:
+                return data

=== modified file 'beeseek/network/http.py'
--- a/beeseek/network/http.py	2009-01-25 12:26:18 +0000
+++ b/beeseek/network/http.py	2009-01-28 19:08:55 +0000
@@ -19,7 +19,7 @@
 from beeseek.utils import CaseInsensitiveDict
 from beeseek.network import (IClientApplication, IServerApplication,
                              IApplicationProtocol, BaseApplication)
-from beeseek.decoders import (NullSocketDecoder, ChunksDecoder,
+from beeseek.decoders import (NullDecoder, ChunksDecoder,
                               FixedLengthChunkDecoder)
 
 __all__ = 'HTTPApplication', 'HTTPClientApplication', 'HTTPServerApplication'
@@ -273,7 +273,7 @@
         if style == 0:
             self._decoder = FixedLengthChunkDecoder(-1)
         elif style == 1:
-            self._decoder = NullSocketDecoder()
+            self._decoder = NullDecoder()
         elif style == 2:
             size = int(headers['Content-Length'])
             self._decoder = FixedLengthChunkDecoder(size)



--
BeeSeek mainline
https://code.launchpad.net/~beeseek-devs/beeseek/trunk

You are receiving this branch notification because you are subscribed to it.