Skip to content

Henok alem py2 to py3 #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ nohup.out
.pydevproject
.idea/
/.cache/


# envs
.gevent-socketio_env/

4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.6"
sudo: true

before_install: "sudo apt-get install python-dev libevent-dev"
Expand Down
5 changes: 3 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tempfile

from optparse import OptionParser
import imp

tmpeggs = tempfile.mkdtemp()

Expand Down Expand Up @@ -73,7 +74,7 @@
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from urllib.request import urlopen

# XXX use a more permanent ez_setup.py URL when available.
exec(urlopen('https://bitbucket.org/pypa/setuptools/raw/0.7.2/ez_setup.py'
Expand All @@ -82,7 +83,7 @@
ez['use_setuptools'](**setup_args)

if to_reload:
reload(pkg_resources)
imp.reload(pkg_resources)
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
Expand Down
14 changes: 7 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
master_doc = 'index'

# General information about the project.
project = u'gevent-socketio'
project = 'gevent-socketio'
copyright = '2011-%s, Jeffrey Gelens, Alexandre Bourget, and John Anderson' % datetime.datetime.now().year


Expand Down Expand Up @@ -185,8 +185,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'gevent-socketio.tex', u'gevent-socketio Documentation',
u'Jeffrey Gelens,Alex Bourget,John Anderson', 'manual'),
('index', 'gevent-socketio.tex', 'gevent-socketio Documentation',
'Jeffrey Gelens,Alex Bourget,John Anderson', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -215,8 +215,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'gevent-socketio', u'gevent-socketio Documentation',
[u'Jeffrey Gelens,Alex Bourget,John Anderson'], 1)
('index', 'gevent-socketio', 'gevent-socketio Documentation',
['Jeffrey Gelens,Alex Bourget,John Anderson'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -229,8 +229,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'gevent-socketio', u'gevent-socketio Documentation',
u'Jeffrey Gelens,Alex Bourget,John Anderson', 'gevent-socketio', 'One line description of project.',
('index', 'gevent-socketio', 'gevent-socketio Documentation',
'Jeffrey Gelens,Alex Bourget,John Anderson', 'gevent-socketio', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
2 changes: 1 addition & 1 deletion examples/cross_origin/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Hello(namespace.BaseNamespace):

def on_hello(self, data):
print "hello", data
print("hello", data)
self.emit('greetings', {'from': 'sockets'})


Expand Down
15 changes: 8 additions & 7 deletions examples/django_chat/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
use the -c option to specify an alternate configuration file.
"""

import os, shutil, sys, tempfile, urllib, urllib2, subprocess
import os, shutil, sys, tempfile, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, subprocess
from optparse import OptionParser
import imp

if sys.platform == 'win32':
def quote(c):
Expand Down Expand Up @@ -50,7 +51,7 @@ def quote(c):
# We will restart with python -S.
args = sys.argv[:]
args[0:0] = [sys.executable, '-S']
args = map(quote, args)
args = list(map(quote, args))
os.execv(sys.executable, args)
# Now we are running with -S. We'll get the clean sys.path, import site
# because distutils will do it later, and then reset the path and clean
Expand All @@ -59,7 +60,7 @@ def quote(c):
clean_path = sys.path[:]
import site # imported because of its side effects
sys.path[:] = clean_path
for k, v in sys.modules.items():
for k, v in list(sys.modules.items()):
if k in ('setuptools', 'pkg_resources') or (
hasattr(v, '__path__') and
len(v.__path__) == 1 and
Expand All @@ -78,7 +79,7 @@ def normalize_to_url(option, opt_str, value, parser):
if value:
if '://' not in value: # It doesn't smell like a URL.
value = 'file://%s' % (
urllib.pathname2url(
urllib.request.pathname2url(
os.path.abspath(os.path.expanduser(value))),)
if opt_str == '--download-base' and not value.endswith('/'):
# Download base needs a trailing slash to make the world happy.
Expand Down Expand Up @@ -161,18 +162,18 @@ def normalize_to_url(option, opt_str, value, parser):
if not hasattr(pkg_resources, '_distribute'):
raise ImportError
except ImportError:
ez_code = urllib2.urlopen(
ez_code = urllib.request.urlopen(
options.setup_source).read().replace('\r\n', '\n')
ez = {}
exec ez_code in ez
exec(ez_code, ez)
setup_args = dict(to_dir=eggs_dir, download_delay=0)
if options.download_base:
setup_args['download_base'] = options.download_base
if options.use_distribute:
setup_args['no_fake'] = True
ez['use_setuptools'](**setup_args)
if 'pkg_resources' in sys.modules:
reload(sys.modules['pkg_resources'])
imp.reload(sys.modules['pkg_resources'])
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from re import match
from thread import start_new_thread
from _thread import start_new_thread
from time import sleep
from os import getpid, kill, environ
from signal import SIGINT
Expand Down Expand Up @@ -47,16 +47,16 @@ def handle(self, addrport="", *args, **options):
start_new_thread(reload_watcher, ())
try:
bind = (self.addr, int(self.port))
print
print "SocketIOServer running on %s:%s" % bind
print
print()
print("SocketIOServer running on %s:%s" % bind)
print()
handler = self.get_handler(*args, **options)
server = SocketIOServer(bind, handler, resource="socket.io", policy_server=True)
server.serve_forever()
except KeyboardInterrupt:
if RELOAD:
server.stop()
print "Reloading..."
print("Reloading...")
restart_with_reloader()
else:
raise
Expand Down
2 changes: 1 addition & 1 deletion examples/flask_chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __unicode__(self):
# utils
def slugify(value):
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
value = str(re.sub('[^\w\s-]', '', value).strip().lower())
return re.sub('[-\s]+', '-', value)


Expand Down
2 changes: 1 addition & 1 deletion examples/flask_chat/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
PORT = 5000

if __name__ == '__main__':
print 'Listening on http://127.0.0.1:%s and on port 10843 (flash policy server)' % PORT
print('Listening on http://127.0.0.1:%s and on port 10843 (flash policy server)' % PORT)
SocketIOServer(('', PORT), app, resource="socket.io").serve_forever()
2 changes: 1 addition & 1 deletion examples/live_cpu_graph/live_cpu_graph/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def not_found(start_response):


if __name__ == '__main__':
print 'Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)'
print('Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)')
SocketIOServer(('0.0.0.0', 8080), Application(),
resource="socket.io", policy_server=True,
policy_listener=('0.0.0.0', 10843)).serve_forever()
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

def usage(argv): # pragma: no cover
cmd = os.path.basename(argv[0])
print('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd))
print(('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd)))
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion examples/pyramid_backbone_redis_chat/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

app = get_app('development.ini')

print 'Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)'
print('Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)')

SocketIOServer(('0.0.0.0', 8080), app,
resource="socket.io", policy_server=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

def usage(argv): # pragma: no cover
cmd = os.path.basename(argv[0])
print('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd))
print(('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd)))
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion examples/pyramid_backbone_redis_chat_persistence/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

app = get_app('development.ini')

print 'Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)'
print('Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)')

SocketIOServer(('0.0.0.0', 8080), app,
resource="socket.io", policy_server=True,
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def on_user_message(self, msg):
self.socket.session['nickname'], msg)

def recv_message(self, message):
print "PING!!!", message
print("PING!!!", message)

class Application(object):
def __init__(self):
Expand Down Expand Up @@ -78,7 +78,7 @@ def not_found(start_response):


if __name__ == '__main__':
print 'Listening on port 8080 and on port 843 (flash policy server)'
print('Listening on port 8080 and on port 843 (flash policy server)')
SocketIOServer(('0.0.0.0', 8080), Application(),
resource="socket.io", policy_server=True,
policy_listener=('0.0.0.0', 10843)).serve_forever()
4 changes: 2 additions & 2 deletions examples/simple_pyramid_chat/chatter2/scripts/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

def usage(argv): # pragma: no cover
cmd = os.path.basename(argv[0])
print('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd))
print(('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd)))
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion examples/simple_pyramid_chat/chatter2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def emit_to_room(self, event, args, room):
args=args,
endpoint=self.ns_name)
room_name = self._get_room_name(room)
for sessid, socket in self.socket.server.sockets.iteritems():
for sessid, socket in self.socket.server.sockets.items():
if not hasattr(socket, 'rooms'):
continue
if room_name in socket.rooms:
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_pyramid_chat/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if __name__ == '__main__':

app = get_app('development.ini')
print 'Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)'
print('Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)')

SocketIOServer(('0.0.0.0', 8080), app,
resource="socket.io", policy_server=True,
Expand Down
2 changes: 1 addition & 1 deletion examples/testapp/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
if __name__ == '__main__':

app = get_app('development.ini')
print 'Listening on port http://127.0.0.1:8080 and on port 843 (flash policy server)'
print('Listening on port http://127.0.0.1:8080 and on port 843 (flash policy server)')
SocketIOServer(('127.0.0.1', 8080), app, policy_server=False,
transports=['websocket']).serve_forever()
4 changes: 2 additions & 2 deletions examples/testapp/testapp/scripts/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

def usage(argv):# pragma: no cover
cmd = os.path.basename(argv[0])
print('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd))
print(('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd)))
sys.exit(1)

def main(argv=sys.argv): # pragma: no cover
Expand Down
18 changes: 9 additions & 9 deletions examples/testapp/testapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def index(request):
class GlobalIONamespace(BaseNamespace, BroadcastMixin):
def on_chat(self, *args):
self.emit("bob", {'hello': 'world'})
print "Received chat message", args
print("Received chat message", args)
self.broadcast_event_not_me('chat', *args)

def recv_connect(self):
print "CONNNNNNNN"
print("CONNNNNNNN")
self.emit("you_just_connected", {'bravo': 'kid'})
self.spawn(self.cpu_checker_process)

Expand All @@ -105,28 +105,28 @@ def cpu_checker_process(self):

class ChatIONamespace(BaseNamespace, RoomsMixin):
def on_mymessage(self, msg):
print "In on_mymessage"
print("In on_mymessage")
self.send("little message back")
self.send({'blah': 'blah'}, json=True)
for x in xrange(2):
for x in range(2):
self.emit("pack", {'the': 'more', 'you': 'can'})

def on_my_callback(self, packet):
return (1, 2)

def on_trigger_server_callback(self, superbob):
def cb():
print "OK, WE WERE CALLED BACK BY THE ACK! THANKS :)"
print("OK, WE WERE CALLED BACK BY THE ACK! THANKS :)")
self.emit('callmeback', 'this is a first param',
'this is the last param', callback=cb)

def cb2(param1, param2):
print "OK, GOT THOSE VALUES BACK BY CB", param1, param2
print("OK, GOT THOSE VALUES BACK BY CB", param1, param2)
self.emit('callmeback', 'this is a first param',
'this is the last param', callback=cb2)

def on_rtc_invite(self, sdp):
print "Got an RTC invite, now pushing to others..."
print("Got an RTC invite, now pushing to others...")
self.emit_to_room('room1', 'rtc_invite', self.session['nickname'],
sdp)

Expand All @@ -135,11 +135,11 @@ def recv_connect(self):
self.join('room1')

def recv_message(self, data):
print "Received a 'message' with data:", data
print("Received a 'message' with data:", data)


def on_disconnect_me(self, data):
print "Disconnecting you buddy", data
print("Disconnecting you buddy", data)
self.disconnect()


Expand Down
Loading