Ginés Martínez Sánchez avatar Ginés Martínez Sánchez committed 964869e Draft

fixing python3

Comments (0)

Files changed (8)

ginsfsm/c_sock.py

 
 from ginsfsm.gobj import GObj
 from ginsfsm.gconfig import GConfig
-from ginsfsm.utils import hexdump
-from ginsfsm.compat import tobytes
+from ginsfsm.utils import (
+    hexdump,
+)
 from ginsfsm.buffers import (
     ReadOnlyFileBasedBuffer,
     OverflowableBuffer,

ginsfsm/examples/essential_gobjs/stress_client_echo.py

 #===============================================================
 #                   Client
 #===============================================================
-query = "GET / HTTP/1.1\r\n" + \
-    "Host: \r\n" + \
-    "\r\n"
+query = b"GET / HTTP/1.1\r\n" + \
+    b"Host: \r\n" + \
+    b"\r\n"
 
 
 def ac_client_timeout(self, event):

ginsfsm/examples/http/simple_http_server.py

 
 
 def ac_channel_opened(self, event):
-    print "======> channel opened"
+    print("======> channel opened")
 
 
 def ac_channel_closed(self, event):
-    print "======> channel closed"
+    print("======> channel closed")
 
 
 def ac_request(self, event):
-    print "======> channel request"
+    print("======> channel request")
     channel = event.source[-1]
     request = event.request
     response = HttpSimpleOkResponse(

ginsfsm/examples/wsgi/multiple_wsgi_server.py

 #===============================================================
 def application1(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])
-    yield 'Hello World ONE!\n'
+    yield b'Hello World ONE!\n'
 
 
 def application2(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])
-    yield 'Hello World TWO!\n'
+    yield b'Hello World TWO!\n'
 
 
 def application3(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])
-    yield 'Hello World THREE!\n'
+    yield b'Hello World THREE!\n'
 
 
 def paste_app_factory1(global_config, **local_conf):

ginsfsm/examples/wsgi/simple_wsgi_server.py

 #===============================================================
 def application(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])
-    yield 'Hello World\n'
+    yield b'Hello World\n'
 
 
 def paste_app_factory(global_config, **local_conf):

ginsfsm/protocols/sockjs/server/c_websocket.py

 
     def do_request(self, host, port, resource, **options):
         headers = []
-        headers.append("GET %s HTTP/1.1" % resource)
-        headers.append("User-Agent: ginsfsm-%s" % __version__)
-        headers.append("Upgrade: websocket")
-        headers.append("Connection: Upgrade")
+        #headers.append("GET %s HTTP/1.1" % resource)
+        #headers.append("User-Agent: ginsfsm-%s" % __version__)
+        #headers.append("Upgrade: websocket")
+        #headers.append("Connection: Upgrade")
+        #if port == 80:
+        #    hostport = host
+        #else:
+        #    hostport = "%s:%d" % (host, port)
+        #headers.append("Host: %s" % hostport)
+        #
+        #if "origin" in options:
+        #    headers.append("Origin: %s" % options["origin"])
+        #else:
+        #    headers.append("Origin: %s" % hostport)
+        #
+        #key = _create_sec_websocket_key()
+        #headers.append("Sec-WebSocket-Key: %s" % key)
+        #headers.append("Sec-WebSocket-Version: %s" % VERSION)
+        #if "header" in options:
+        #    headers.extend(options["header"])
+        #
+        #headers.append("")
+        #headers.append("")
+        #
+        #header_str = "\r\n".join(headers)
+
+        headers.append(b"GET " + resource + b" HTTP/1.1")
+        headers.append(b"User-Agent: ginsfsm-" + __version__)
+        headers.append(b"Upgrade: websocket")
+        headers.append(b"Connection: Upgrade")
         if port == 80:
             hostport = host
         else:
-            hostport = "%s:%d" % (host, port)
-        headers.append("Host: %s" % hostport)
+            hostport = host + ":" + str(port)
+        headers.append(b"Host: " + hostport)
 
         if "origin" in options:
-            headers.append("Origin: %s" % options["origin"])
+            headers.append(b"Origin: " + options["origin"])
         else:
-            headers.append("Origin: %s" % hostport)
+            headers.append(b"Origin: " + hostport)
 
         key = _create_sec_websocket_key()
-        headers.append("Sec-WebSocket-Key: %s" % key)
-        headers.append("Sec-WebSocket-Version: %s" % VERSION)
+        headers.append(b"Sec-WebSocket-Key: " + key)
+        headers.append(b"Sec-WebSocket-Version: " + VERSION)
         if "header" in options:
             headers.extend(options["header"])
 
-        headers.append("")
-        headers.append("")
+        headers.append(b"")
+        headers.append(b"")
 
-        header_str = "\r\n".join(headers)
+        header_str = b"\r\n".join(headers)
+
         self.send_event(self.gsock, 'EV_SEND_DATA', data=header_str)
 
     def do_response(self):

ginsfsm/protocols/wsgi/common/urlmap.py

 Map URL prefixes to WSGI applications.  See ``URLMap``
 """
 
-from ginsfsm.compat import DictMixin
 from ginsfsm.compat import escape
 import re
 
 __all__ = ['URLMap']
 
+class DictMixin:
+    # Mixin defining all dictionary methods for classes that already have
+    # a minimum dictionary interface including getitem, setitem, delitem,
+    # and keys. Without knowledge of the subclass constructor, the mixin
+    # does not define __init__() or copy().  In addition to the four base
+    # methods, progressively more efficiency comes with defining
+    # __contains__(), __iter__(), and iteritems().
+
+    # second level definitions support higher levels
+    def __iter__(self):
+        for k in self.keys():
+            yield k
+    def has_key(self, key):
+        try:
+            self[key]
+        except KeyError:
+            return False
+        return True
+    def __contains__(self, key):
+        return self.has_key(key)
+
+    # third level takes advantage of second level definitions
+    def iteritems(self):
+        for k in self:
+            yield (k, self[k])
+    def iterkeys(self):
+        return self.__iter__()
+
+    # fourth level uses definitions from lower levels
+    def itervalues(self):
+        for _, v in self.iteritems():
+            yield v
+    def values(self):
+        return [v for _, v in self.iteritems()]
+    def items(self):
+        return list(self.iteritems())
+    def clear(self):
+        for key in self.keys():
+            del self[key]
+    def setdefault(self, key, default=None):
+        try:
+            return self[key]
+        except KeyError:
+            self[key] = default
+        return default
+    def pop(self, key, *args):
+        if len(args) > 1:
+            raise TypeError("pop expected at most 2 arguments, got "\
+                              + repr(1 + len(args)))
+        try:
+            value = self[key]
+        except KeyError:
+            if args:
+                return args[0]
+            raise
+        del self[key]
+        return value
+    def popitem(self):
+        try:
+            k, v = self.iteritems().next()
+        except StopIteration:
+            raise KeyError('container is empty')
+        del self[k]
+        return (k, v)
+    def update(self, other=None, **kwargs):
+        # Make progressively weaker assumptions about "other"
+        if other is None:
+            pass
+        elif hasattr(other, 'iteritems'):  # iteritems saves memory and lookups
+            for k, v in other.iteritems():
+                self[k] = v
+        elif hasattr(other, 'keys'):
+            for k in other.keys():
+                self[k] = other[k]
+        else:
+            for k, v in other:
+                self[k] = v
+        if kwargs:
+            self.update(kwargs)
+    def get(self, key, default=None):
+        try:
+            return self[key]
+        except KeyError:
+            return default
+    def __repr__(self):
+        return repr(dict(self.iteritems()))
+    def __cmp__(self, other):
+        if other is None:
+            return 1
+        if isinstance(other, DictMixin):
+            other = dict(other.iteritems())
+        return cmp(dict(self.iteritems()), other)
+    def __len__(self):
+        return len(self.keys())
+
 
 def urlmap_factory(loader, global_conf, **local_conf):
     """
 def random_key():
     """Return random session key"""
     i = md5()
-    i.update('%s%s' % (random(), time()))
+    #i.update('%s%s' % (random(), time()))
+    s = '%s%s' % (random(), time())
+    i.update(s.encode(encoding='utf-8', errors='strict'))
     return i.hexdigest()
 
 
     return s
 
 
+def string_to_bytes(s, encoding='utf-8', errors='strict'):
+    if isinstance(s, text_type):
+        s = bytes(s, encoding, errors)
+    s = bytes(s)
+
+
 def hexdump(prefix, byts, length=16):
     ''' hd: hexdump
     dump in hex with pretty formating the hex value and ascii value (if any)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.