Skip to content

Commit 04d6e0d

Browse files
Make python3 compatible
1 parent 457f4d5 commit 04d6e0d

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

discuss/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def get_text(self):
340340
if result != 0:
341341
raise DiscussError(result)
342342

343-
return tfile.buffer
343+
return tfile.buffer.decode()
344344

345345
@autoreconnects
346346
def delete(self):

discuss/locator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _read_server_list(filename):
2828

2929
lines = map(remove_comments, lines) # comments
3030
lines = map(str.strip, lines) # whitespace
31-
lines = filter(lambda x: x, lines) # empty lines
31+
lines = [x for x in lines if x] # empty lines
3232

3333
return lines
3434
except IOError as err:

discuss/rpc.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def _get_krb5_ap_req(service, server):
9191
# bindings myself, but this is the yak I am not ready to shave at the
9292
# moment.
9393

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

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

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

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

196-
return encoded.replace("\r\n", "\n").replace("\r\0", "\r")
196+
return encoded.replace(b"\r\n", b"\n").replace(b"\r\0", b"\r").decode()
197197

198198
@staticmethod
199199
def receive(sock):
@@ -272,7 +272,9 @@ def connect(self):
272272

273273
auth_block.put_cardinal(len(authenticator))
274274
for byte in authenticator:
275-
auth_block.put_cardinal(ord(byte))
275+
if str == bytes:
276+
byte = ord(byte)
277+
auth_block.put_cardinal(byte)
276278
else:
277279
auth_block.put_cardinal(0)
278280

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/python
22

3-
from distutils.core import setup
3+
from setuptools import setup
44

55
setup(name='discuss',
6-
version='1.2',
6+
version='1.3',
77
description='Python client for Project Athena forum system',
88
author='Victor Vasiliev',
99
maintainer='Debathena Project',

tools/constants_gen.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python
2-
2+
from __future__ import print_function
33
# This file generates the constants from discuss sources.
44
# The first argument is path to those sources.
55
#
@@ -16,7 +16,7 @@
1616

1717
basepath = sys.argv[1]
1818
if not os.path.isdir(basepath):
19-
print "ERROR: the specified path is not a directory"
19+
print("ERROR: the specified path is not a directory")
2020
exit()
2121

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

3030
if not et_match_entries:
31-
print "ERROR: unable to parse dsc_et file correctly"
31+
print("ERROR: unable to parse dsc_et file correctly")
3232
exit()
3333
if not header_match_entries:
34-
print "ERROR: unable to parse rpc.h file correctly"
34+
print("ERROR: unable to parse rpc.h file correctly")
3535
exit()
3636

3737
##### Code file header #####
38-
print "# Discuss status codes and other constants, generated from discuss sources"
39-
print "#"
40-
print "# NOTE: this file was autogenerated from the following files:"
41-
print ""
38+
print("# Discuss status codes and other constants, generated from discuss sources")
39+
print("#")
40+
print("# NOTE: this file was autogenerated from the following files:")
41+
print("")
4242

4343
##### Discuss error codes #####
44-
print "# Error codes"
44+
print("# Error codes")
4545
cur_code = et_base
4646
for match in et_match_entries:
47-
print '%s = %s' % (match[0], repr(cur_code))
47+
print('%s = %s' % (match[0], repr(cur_code)))
4848
cur_code += 1
49-
print ""
49+
print("")
5050

51-
print "# Error code descriptions"
52-
print "errors = {"
51+
print("# Error code descriptions")
52+
print("errors = {")
5353
for match in et_match_entries:
54-
print ' %s : "%s",' % match
55-
print "}"
56-
print ""
54+
print(' %s : "%s",' % match)
55+
print("}")
56+
print("")
5757

5858
##### Constatns from rpc.h #####
59-
print "# Definitions from rpc.h"
59+
print("# Definitions from rpc.h")
6060
for match in header_match_entries:
61-
print '%s = %s' % match
62-
print ""
61+
print('%s = %s' % match)
62+
print("")

0 commit comments

Comments
 (0)