Skip to content
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

python3 version: #5

Open
wants to merge 1 commit 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
1 change: 0 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Now you can make your changes locally.
tests, including testing other Python versions with tox::

$ flake8 socket_server tests
$ python setup.py test
$ tox

To get flake8 and tox, just pip install them into your virtualenv.
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@
],
include_package_data=True,
install_requires=[
'Django>=1.6.1',
'wheel==0.23.0',
'Django>=2.2',
'wheel',
'autobahn',
'twisted',
],
license="BSD",
zip_safe=False,
keywords='django-socket-server',
python_requires=">=3.7",
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
)
2 changes: 1 addition & 1 deletion socket_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.4'
__version__ = '1.0.0'
26 changes: 20 additions & 6 deletions socket_server/management/commands/start_socket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from optparse import make_option
import os
import sys
import time
import signal
from importlib import import_module

from django.core.management.base import BaseCommand
from django.utils.importlib import import_module
from django.conf import settings

from socket_server.server import SocketServerFactory
Expand Down Expand Up @@ -38,10 +41,13 @@ class Command(BaseCommand):
# type='int',
# help='Port used for incomings websocket requests default to 3000',)
# )


def add_arguments(self, parser):
parser.add_argument('--test',action='store_true',help='Start server and close it')

def handle(self, *args, **options):
options.update({'port': 3000})
print 'Listening on port localhost:%s' % options['port']
print('Listening on port localhost:%s' % options['port'])

import sys

Expand All @@ -50,8 +56,16 @@ def handle(self, *args, **options):

log.startLogging(sys.stdout)

factory = SocketServerFactory("ws://localhost:%s" % options['port'], debug=False)
factory = SocketServerFactory("ws://localhost:%s" % options['port'])
factory.setNamespaces(namespaces)

reactor.listenTCP(options['port'], factory)
reactor.run()
if 'test' in options and options['test']:
r = os.fork()
if r == 0:
reactor.run()
else:
os.kill(r, signal.SIGKILL)
os.waitpid(r,0)
else:
reactor.run()
44 changes: 16 additions & 28 deletions socket_server/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
# Generated by Django 3.2.6 on 2021-08-10 08:35

from django.db import migrations, models

class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'SocketLog'
db.create_table(u'socket_server_socketlog', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created_at', self.gf('django.db.models.fields.DateTimeField')()),
('content', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal(u'socket_server', ['SocketLog'])
class Migration(migrations.Migration):

initial = True

def backwards(self, orm):
# Deleting model 'SocketLog'
db.delete_table(u'socket_server_socketlog')
dependencies = [
]


models = {
u'socket_server.socketlog': {
'Meta': {'object_name': 'SocketLog'},
'content': ('django.db.models.fields.TextField', [], {}),
'created_at': ('django.db.models.fields.DateTimeField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}

complete_apps = ['socket_server']
operations = [
migrations.CreateModel(
name='SocketLog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
]
3 changes: 1 addition & 2 deletions socket_server/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def _fire_callback(self, client, event, **kwargs):
try:
self.callbacks[event](client, **kwargs)
except TypeError:
print 'An Error occurred calling event [%s]' % event
pass
print('An Error occurred calling event [%s]' % event)

def _parse_inbound_message(self, message):
""" Parse inbound JSON message """
Expand Down
4 changes: 1 addition & 3 deletions socket_server/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from autobahn.twisted.websocket import WebSocketServerProtocol, WebSocketServerFactory

from .exceptions import NamespaceNotFound
Expand Down Expand Up @@ -71,4 +69,4 @@ def stopFactory(self):
namespaces = self.getNamespaces()
for key in namespaces.keys():
namespace = namespaces[key]
namespace.on_stop('500', 'SHUTDOWN')
namespace.on_stop('500', 'SHUTDOWN')
21 changes: 11 additions & 10 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

Tests for `django-socket-server` models module.
"""

import os
import shutil
from io import StringIO

from django.test import TestCase
from django.core.management import call_command

from socket_server import models
from socket_server.models import SocketLog


class TestSocket_server(TestCase):

def setUp(self):
pass

def test_something(self):
pass
def test_model(self):
log = SocketLog(content='test log entry')
log.save()
self.assertTrue(log)

def tearDown(self):
pass
def test_command(self):
out = StringIO()
call_command('start_socket', stdout=out, test=0)
self.assertTrue(True)
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[tox]
envlist = py26, py27, py33
envlist = py38, py39

[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/socket_server
commands = python runtests.py
deps =
-r{toxinidir}/requirements-test.txt

[flake8]
ignore = E501