Skip to content

Update Debian packaging for python-discuss 1.3, with support for Python 3 and pergamon #8

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 9 commits into
base: debian
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
10 changes: 10 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
python-discuss (1.3-0debathena1) unstable; urgency=low

* Release version 1.3.
* Add Python 3 support
* Update Debian packaging for Python 3 support
* Drop Python 2 support
* Add additional functionality for pergamon

-- Alex Dehnert <[email protected]> Fri, 21 Feb 2025 02:21:24 -0400

python-discuss (1.2-0debathena3) unstable; urgency=low

* Avoid building for Python 2.6 on distributions which support it
Expand Down
2 changes: 1 addition & 1 deletion debian/compat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7
10
9 changes: 4 additions & 5 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Source: python-discuss
Section: python
Priority: extra
Priority: optional
Maintainer: Debathena Project <[email protected]>
Build-Depends: debhelper (>= 7), python (>= 2.7)
X-Python-Version: 2.7
Build-Depends: debhelper (>= 10), dh-python, python3-all
Standards-Version: 3.9.4

Package: python-discuss
Package: python3-discuss
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, python (>= 2.7), python-kerberos
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}, python3-kerberos
Description: Python client for Project Athena forum system
Pydiscuss provides a pure-Python implementation of discuss -- the forum
protocol developed in late 80's and still used around MIT.
2 changes: 2 additions & 0 deletions debian/python3-discuss.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
etc/servers etc/discuss
etc/meetings.default etc/discuss
4 changes: 3 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export PYBUILD_NAME=discuss

%:
dh $@ --with python2
dh $@ --with python3 --buildsystem=pybuild
24 changes: 22 additions & 2 deletions discuss/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def autoreconnect(self, *args, **kwargs):
class Client(object):
"""Discuss client."""

def __init__(self, server, port = 2100, auth = True, timeout = None):
def __init__(self, server, port = 2100, auth = True, timeout = None, RPCClient=RPCClient):
self.rpc = RPCClient(server, port, auth, timeout)
if auth and self.who_am_i().startswith("???@"):
raise ProtocolError("Authentication to server failed")
Expand All @@ -65,6 +65,17 @@ def who_am_i(self):
reply = self.rpc.request(request)
return reply.read_string()

@autoreconnects
def create_mtg(self, location, long_mtg_name, public):
request = USPBlock(constants.CREATE_MTG)
request.put_string(location)
request.put_string(long_mtg_name)
request.put_boolean(public)
reply = self.rpc.request(request)
result = reply.read_long_integer()
if result != 0:
raise DiscussError(result)

def close(self):
"""Disconnect from the server."""

Expand Down Expand Up @@ -300,6 +311,15 @@ def set_access(self, principal, modes):
if result != 0:
raise DiscussError(result)

def ensure_access(self, principal, modes):
current = self.get_access(principal)
self.set_access(principal, current+modes)

def remove_access(self, principal, modes):
current = self.get_access(principal)
new_modes = ''.join(c for c in current if not c in modes)
self.set_access(principal, new_modes)

@autoreconnects
def undelete_transaction(self, trn_number):
"""Undelete the transaction by its number."""
Expand Down Expand Up @@ -340,7 +360,7 @@ def get_text(self):
if result != 0:
raise DiscussError(result)

return tfile.buffer
return tfile.buffer.decode()

@autoreconnects
def delete(self):
Expand Down
2 changes: 1 addition & 1 deletion discuss/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _read_server_list(filename):

lines = map(remove_comments, lines) # comments
lines = map(str.strip, lines) # whitespace
lines = filter(lambda x: x, lines) # empty lines
lines = [x for x in lines if x] # empty lines

return lines
except IOError as err:
Expand Down
37 changes: 30 additions & 7 deletions discuss/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
#

import errno
import fcntl
import socket
from struct import pack, unpack, calcsize
import subprocess
from functools import partial

from . import constants
Expand Down Expand Up @@ -91,9 +93,9 @@ def _get_krb5_ap_req(service, server):
# bindings myself, but this is the yak I am not ready to shave at the
# moment.

body_start = token_gssapi.find( chr(0x01) + chr(0x00) ) # 01 00 indicates that this is AP_REQ
if token_gssapi[0] != chr(0x60) or \
not (token_gssapi[2] == chr(0x06) or token_gssapi[4] == chr(0x06)) or \
body_start = token_gssapi.find(b'\x01\x00') # 01 00 indicates that this is AP_REQ
if token_gssapi[0:1] != b'\x60' or \
not (token_gssapi[2:3] == b'\x06' or token_gssapi[4:5] == b'\x06') or \
body_start == -1 or body_start < 8 or body_start > 64:
raise ProtocolError("Invalid GSSAPI token provided by Python's Kerberos API")

Expand Down Expand Up @@ -135,13 +137,13 @@ def put_string(self, s):
# technical reasons from 1980s I do not really want to know. This works
# out because input is null-terminated and wire format is has length
# specified.
encoded = s.replace("\r", "\r\0").replace("\n", "\r\n")
encoded = s.encode().replace(b"\r", b"\r\0").replace(b"\n", b"\r\n")
self.put_cardinal(len(encoded))
self.buffer += encoded

# Padding
if len(encoded) % 2 == 1:
self.buffer += "\0"
self.buffer += b"\0"

def send(self, sock):
"""Sends the block over a socket."""
Expand Down Expand Up @@ -193,7 +195,7 @@ def read_string(self):
omit = size + 1 if size % 2 ==1 else size # due to padding
encoded, self.buffer = self.buffer[0:size], self.buffer[omit:]

return encoded.replace("\r\n", "\n").replace("\r\0", "\r")
return encoded.replace(b"\r\n", b"\n").replace(b"\r\0", b"\r").decode()

@staticmethod
def receive(sock):
Expand Down Expand Up @@ -272,7 +274,9 @@ def connect(self):

auth_block.put_cardinal(len(authenticator))
for byte in authenticator:
auth_block.put_cardinal(ord(byte))
if str == bytes:
byte = ord(byte)
auth_block.put_cardinal(byte)
else:
auth_block.put_cardinal(0)

Expand Down Expand Up @@ -314,3 +318,22 @@ def request(self, block):
raise ProtocolError("Transport-level error")
return reply

class RPCLocalClient(RPCClient):
# Args are for compatibility with the remote RPC; most aren't used
def __init__(self, server, port, auth, timeout):
# Used as the id field on meeting objects, so copy it in
self.server = server
# port 2100 is the default port -> use the binary
if port == 2100:
port = '/usr/sbin/disserve'
self.cmd = port

self.connect()
self.make_wrapper()

def connect(self):
pair = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
subprocess.Popen([self.cmd], stdin=pair[1], close_fds=True)
pair[1].close()
fcntl.fcntl(pair[0].fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
self.socket = pair[0]
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python

from distutils.core import setup
from setuptools import setup

setup(name='discuss',
version='1.2',
version='1.3',
description='Python client for Project Athena forum system',
author='Victor Vasiliev',
maintainer='Debathena Project',
Expand Down
38 changes: 19 additions & 19 deletions tools/constants_gen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python

from __future__ import print_function
# This file generates the constants from discuss sources.
# The first argument is path to those sources.
#
Expand All @@ -16,7 +16,7 @@

basepath = sys.argv[1]
if not os.path.isdir(basepath):
print "ERROR: the specified path is not a directory"
print("ERROR: the specified path is not a directory")
exit()

with open(basepath + "/ets/dsc_et.et", "r") as et_file_handler:
Expand All @@ -28,35 +28,35 @@
header_match_entries = re.findall( r'#define ([A-Z0-9_]+)\s+(".+"|[0-9x\-]+)', header_file )

if not et_match_entries:
print "ERROR: unable to parse dsc_et file correctly"
print("ERROR: unable to parse dsc_et file correctly")
exit()
if not header_match_entries:
print "ERROR: unable to parse rpc.h file correctly"
print("ERROR: unable to parse rpc.h file correctly")
exit()

##### Code file header #####
print "# Discuss status codes and other constants, generated from discuss sources"
print "#"
print "# NOTE: this file was autogenerated from the following files:"
print ""
print("# Discuss status codes and other constants, generated from discuss sources")
print("#")
print("# NOTE: this file was autogenerated from the following files:")
print("")

##### Discuss error codes #####
print "# Error codes"
print("# Error codes")
cur_code = et_base
for match in et_match_entries:
print '%s = %s' % (match[0], repr(cur_code))
print('%s = %s' % (match[0], repr(cur_code)))
cur_code += 1
print ""
print("")

print "# Error code descriptions"
print "errors = {"
print("# Error code descriptions")
print("errors = {")
for match in et_match_entries:
print ' %s : "%s",' % match
print "}"
print ""
print(' %s : "%s",' % match)
print("}")
print("")

##### Constatns from rpc.h #####
print "# Definitions from rpc.h"
print("# Definitions from rpc.h")
for match in header_match_entries:
print '%s = %s' % match
print ""
print('%s = %s' % match)
print("")