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

Make python3 compatible #7

Merged
merged 1 commit into from
Feb 22, 2025
Merged
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
2 changes: 1 addition & 1 deletion discuss/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,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
16 changes: 9 additions & 7 deletions discuss/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,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 +135,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 +193,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 +272,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
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("")