Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #15 from neubot/issue-3
Browse files Browse the repository at this point in the history
six.py updated
  • Loading branch information
bassosimone committed Nov 27, 2015
2 parents 8fc0919 + 0d1190b commit 749e34e
Show file tree
Hide file tree
Showing 8 changed files with 958 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.swp
38 changes: 38 additions & 0 deletions neubot_runtime/compat23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Buffer / memoryview, urlparse
# Written by Simone Basso
#

import sys

PY3 = sys.version_info[0] == 3

if PY3:
def buff(string, offset, size=None):
if not size:
size = len(string)
return memoryview(string)[offset:offset + size]

import urllib.parse as urlparse
from collections import OrderedDict

def bytes_to_string(octets, encoding):
return str(octets, encoding)

def bytes_to_string_safe(octets, encoding):
return str(octets, encoding, errors='ignore')

else:
def buff(string, offset, size=None):
if not size:
size = len(string)
return buffer(string, offset, size)

import urlparse
from .third_party.ordered_dict import OrderedDict

def bytes_to_string(octets, encoding):
return octets

def bytes_to_string_safe(octets, encoding):
return octets
2 changes: 1 addition & 1 deletion neubot_runtime/http_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

''' HTTP misc functions '''

from .third_party.six import urlparse
from .third_party.six.moves.urllib import parse as urlparse

from .http_states import BOUNDED
from .http_states import UNBOUNDED
Expand Down
4 changes: 2 additions & 2 deletions neubot_runtime/http_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .http_states import TRAILER
from .http_states import ERROR

from .third_party import six
from . import compat23

# Maximum allowed line length
MAXLINE = 1 << 15
Expand Down Expand Up @@ -118,7 +118,7 @@ def recv_complete(self, data):
logging.debug("looking for %d more bytes", self._left)
count = min(self._left, length)
logging.debug("capping bytes to %d", count)
piece = six.buff(data, offset, count)
piece = compat23.buff(data, offset, count)
logging.debug("found %d-bytes piece", len(piece))
self._left -= count
offset += count
Expand Down
4 changes: 2 additions & 2 deletions neubot_runtime/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import socket

from .pollable import Pollable
from .third_party import six
from . import compat23
from . import utils_net

# Maximum amount of bytes we read from a socket
Expand Down Expand Up @@ -186,7 +186,7 @@ def handle_write(self):
self.poller.close(self)
return
if count < len(self.send_octets):
self.send_octets = six.buff(self.send_octets, count)
self.send_octets = compat23.buff(self.send_octets, count)
return
raise RuntimeError("Sent more than expected")
if count == len(self.send_octets) == 0:
Expand Down
Loading

0 comments on commit 749e34e

Please sign in to comment.