Skip to content

Commit ee3b54a

Browse files
author
Luca De Feo
committed
Prepared for PyPI
1 parent 64e9f94 commit ee3b54a

9 files changed

+52
-24
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include LICENSE README.rst

README.md README.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# scscpy
1+
SCSCP
2+
=====
3+
24
SCSCP module for Python
File renamed without changes.

scscpy/client.py scscp/client.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from pexpect import fdpexpect, TIMEOUT, EOF
3-
from .scscp import ProcessingInstruction as PI, PI_regex, SCSCPError
3+
from .scscp import SCSCPConnectionError, SCSCPCancel
4+
from .processing_instruction import ProcessingInstruction as PI
45

56
class SCSCPClient():
67
"""
@@ -30,7 +31,7 @@ def wrapper(self, *args, **kwds):
3031
def _get_next_PI(self, expect=None, timeout=-1):
3132
while True:
3233
try:
33-
self.stream.expect(PI_regex, timeout=timeout)
34+
self.stream.expect(PI.PI_regex, timeout=timeout)
3435
except TIMEOUT:
3536
self.quit()
3637
raise TimeoutError("Server took to long to respond.")
@@ -39,20 +40,20 @@ def _get_next_PI(self, expect=None, timeout=-1):
3940

4041
try:
4142
pi = PI.parse(self.stream.after)
42-
except SCSCPError:
43+
except SCSCPConnectionError:
4344
self.quit()
4445
raise
4546
self.log.debug("Received PI: %s" % pi)
4647

4748
if expect is not None and pi.key not in expect:
4849
if pi.key == 'quit':
4950
self.quit()
50-
raise SCSCPError("Server closed session (reason: %s)." % pi.attrs.get('reason'))
51+
raise SCSCPConnectionError("Server closed session (reason: %s)." % pi.attrs.get('reason'), pi)
5152
if pi.key == 'info':
5253
self.log.info("SCSCP info: %s " % pi.attrs.get('info'))
5354
continue
5455
else:
55-
raise SCSCPError("Server sent unexpected message: %s" % pi.key)
56+
raise SCSCPConnectionError("Server sent unexpected message: %s" % pi.key, pi)
5657
else:
5758
return pi
5859

@@ -70,7 +71,7 @@ def connect(self):
7071
if ('scscp_versions' not in pi.attrs
7172
or b'1.3' not in pi.attrs['scscp_versions'].split()):
7273
self.quit()
73-
raise SCSCPError("Unsupported SCSCP versions %s." % pi.attrs.get('scscp_versions'))
74+
raise SCSCPConnectionError("Unsupported SCSCP versions %s." % pi.attrs.get('scscp_versions'), pi)
7475

7576
self.service_info = pi.attrs
7677

@@ -79,7 +80,7 @@ def connect(self):
7980
pi = self._get_next_PI([''])
8081
if pi.attrs.get('version') != b'1.3':
8182
self.quit()
82-
raise SCSCPError("Server sent unexpected response.")
83+
raise SCSCPConnectionError("Server sent unexpected response.", pi)
8384

8485
self.status = self.CONNECTED
8586

@@ -103,7 +104,7 @@ def receive(self, timeout=-1):
103104
while True:
104105
pi = self._get_next_PI(['end', 'cancel', 'info'], timeout=timeout)
105106
if pi.key == 'cancel':
106-
raise SCSCPCancel()
107+
raise SCSCPCancel('Server canceled transmission')
107108

108109
msg += self.stream.before
109110
if pi.key == 'info':
@@ -132,4 +133,3 @@ def info(self, info):
132133
def terminate(self, id):
133134
""" Send SCSCP terminate message """
134135
self._send_PI('terminate', call_id=id)
135-

scscpy/scscp.py scscp/processing_instruction.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
import re
2-
3-
PI_regex = re.compile(b"<\?scscp\s+(.{0,4084}?)\?>", re.S)
4-
PI_regex_full = re.compile(b'^<\?scscp(?:\s+(?P<key>\w+))?(?P<attrs>(?:\s+\w+=".*?")*)\s*\?>$')
5-
PI_regex_attr = re.compile(b'(\w+)="(.*?)"')
6-
7-
class SCSCPError(RuntimeError):
8-
pass
9-
class SCSCPCancel(SCSCPError):
10-
def __init__(self):
11-
super(SCSCPCancel, self).__init__('Server canceled transmission')
2+
from .scscp import SCSCPConnectionError
123

134
class ProcessingInstruction():
5+
PI_regex = re.compile(b"<\?scscp\s+(.{0,4084}?)\?>", re.S)
6+
PI_regex_full = re.compile(b'^<\?scscp(?:\s+(?P<key>\w+))?(?P<attrs>(?:\s+\w+=".*?")*)\s*\?>$')
7+
PI_regex_attr = re.compile(b'(\w+)="(.*?)"')
8+
149
@classmethod
1510
def parse(cls, bytes):
16-
match = PI_regex_full.match(bytes)
11+
match = cls.PI_regex_full.match(bytes)
1712
if match:
1813
key = (match.group('key') or b'').decode('ascii')
1914
attrs = { k.decode('ascii'): v
20-
for k, v in PI_regex_attr.findall(match.group('attrs')) }
15+
for k, v in cls.PI_regex_attr.findall(match.group('attrs')) }
2116
return cls(key, **attrs)
2217
else:
23-
raise SCSCPError("Bad SCSCP processing instruction %s." % bytes)
18+
raise SCSCPConnectionError("Bad SCSCP processing instruction %s." % bytes)
2419

2520
def __init__(self, key='', **attrs):
2621
self.key = key

scscp/scscp.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class SCSCPError(RuntimeError):
2+
pass
3+
class SCSCPConnectionError(SCSCPError):
4+
def __init__(self, msg, pi=None):
5+
super(SCSCPConnectionError, self).__init__(msg)
6+
self.pi = pi
7+
class SCSCPCancel(SCSCPError):
8+
pass

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bdist_wheel]
2+
universal=1

setup.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='scscp',
5+
version='0.1.0a1',
6+
description='Implementation of the SCSCP protocol',
7+
url='https://github.com/OpenMath/py-scscp',
8+
author='Luca De Feo',
9+
license='MIT',
10+
classifiers=[
11+
'Development Status :: 3 - Alpha',
12+
'Intended Audience :: Science/Research',
13+
'License :: OSI Approved :: MIT License',
14+
'Programming Language :: Python :: 2',
15+
'Programming Language :: Python :: 3',
16+
],
17+
keywords='openmath scscp',
18+
packages=find_packages(),
19+
install_requires=['openmath', 'pexpect'],
20+
)

tests/test_conn_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import socket
33
from threading import Thread
44

5-
from scscpy.client import SCSCPClient
5+
from scscp.client import SCSCPClient
66

77
class TestConnInit(unittest.TestCase):
88
def setUp(self):

0 commit comments

Comments
 (0)