Skip to content

Commit

Permalink
Python samples: Properly write strings to log
Browse files Browse the repository at this point in the history
In the commented code for Python 3, use decode() to write a string
instead of a byte string (b'...').

close #260
  • Loading branch information
Julien-Elie committed Sep 17, 2023
1 parent 97bff2d commit 9af984e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
12 changes: 10 additions & 2 deletions samples/filter_innd.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,21 @@ def filter_art(self, art):

# Example of decoding the Newsgroups header field with Python 3.x
# using bytes object.
# header = art[Newsgroups].tobytes().decode("utf-8")
# header = (
# art[Newsgroups]
# .tobytes()
# .decode("utf-8", errors="backslashreplace")
# )
# syslog("notice", "Newsgroups header field: %s" % header)
#
# Another example with the Distribution header field, that may not
# be present in the headers, and also not in UTF-8.
# if art[Distribution]:
# header = art[Distribution].tobytes()
# header = (
# art[Distribution]
# .tobytes()
# .decode(errors="backslashreplace")
# )
# syslog("notice", "Distribution header field: %s" % header)
#
# Other examples:
Expand Down
14 changes: 9 additions & 5 deletions samples/nnrpd_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ def access(self, attributes):
# "n_a access() invoked: hostname %s, ipaddress %s, port %lu,"
# " interface %s, intipaddr %s, intport %lu, user %s"
# % (
# attributes["hostname"].tobytes(),
# attributes["ipaddress"].tobytes(),
# attributes["hostname"]
# .tobytes()
# .decode(errors="backslashreplace"),
# attributes["ipaddress"].tobytes().decode(),
# attributes["port"],
# attributes["interface"].tobytes(),
# attributes["intipaddr"].tobytes(),
# attributes["interface"].tobytes().decode(),
# attributes["intipaddr"].tobytes().decode(),
# attributes["intport"],
# (
# attributes["user"].tobytes()
# attributes["user"]
# .tobytes()
# .decode(errors="backslashreplace")
# if attributes["user"]
# else "-"
# ),
Expand Down
14 changes: 9 additions & 5 deletions samples/nnrpd_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ def authenticate(self, attributes):
# "n_a authenticate() invoked: hostname %s, ipaddress %s,"
# " port %lu, interface %s, intipaddr %s, intport %lu, user %s"
# % (
# attributes["hostname"].tobytes(),
# attributes["ipaddress"].tobytes(),
# attributes["hostname"]
# .tobytes()
# .decode(errors="backslashreplace"),
# attributes["ipaddress"].tobytes().decode(),
# attributes["port"],
# attributes["interface"].tobytes(),
# attributes["intipaddr"].tobytes(),
# attributes["interface"].tobytes().decode(),
# attributes["intipaddr"].tobytes().decode(),
# attributes["intport"],
# (
# attributes["user"].tobytes()
# attributes["user"]
# .tobytes()
# .decode(errors="backslashreplace")
# if attributes["user"]
# else "-"
# ),
Expand Down
20 changes: 13 additions & 7 deletions samples/nnrpd_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,22 @@ def dynamic(self, attributes):
# " ipaddress %s, port %lu, interface %s, intipaddr %s,"
# " intport %lu, user %s"
# % (
# attributes["type"].tobytes(),
# attributes["newsgroup"].tobytes(),
# attributes["hostname"].tobytes(),
# attributes["ipaddress"].tobytes(),
# attributes["type"].tobytes().decode(),
# attributes["newsgroup"]
# .tobytes()
# .decode(errors="backslashreplace"),
# attributes["hostname"]
# .tobytes()
# .decode(errors="backslashreplace"),
# attributes["ipaddress"].tobytes().decode(),
# attributes["port"],
# attributes["interface"].tobytes(),
# attributes["intipaddr"].tobytes(),
# attributes["interface"].tobytes().decode(),
# attributes["intipaddr"].tobytes().decode(),
# attributes["intport"],
# (
# attributes["user"].tobytes()
# attributes["user"]
# .tobytes()
# .decode(errors="backslashreplace")
# if attributes["user"]
# else "-"
# ),
Expand Down

0 comments on commit 9af984e

Please sign in to comment.