1
1
#!/usr/bin/python
2
2
3
+ from __future__ import print_function
3
4
import hesiod
4
5
import os
5
6
import select
6
7
import socket
7
8
import sys
9
+ import six
8
10
from optparse import OptionParser
9
11
10
12
MESSAGE_VERS = 'GMS:0'
@@ -25,7 +27,7 @@ def parse(msg):
25
27
"""Parse a gms message, returning a version, timestamp, text tuple
26
28
if successful, and an Exception otherwise."""
27
29
try :
28
- header , text = msg .split ('\n ' , 1 )
30
+ header , text = six . ensure_str ( msg ) .split ('\n ' , 1 )
29
31
version , timestamp = header .split (' ' , 1 )
30
32
if version != MESSAGE_VERS :
31
33
raise Exception ('Incompatible version of GMS [%s] found' % (version ,))
@@ -59,7 +61,7 @@ def write_message_times(timestamp):
59
61
def fetch_message ():
60
62
"""Connect to the globalmessage server, and read a message."""
61
63
server = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
62
- server .sendto ('%s 0\n ' % (MESSAGE_VERS ,), (get_server (), GMS_PORT ))
64
+ server .sendto (six . ensure_binary ( '%s 0\n ' % (MESSAGE_VERS ,) ), (get_server (), GMS_PORT ))
63
65
message = None
64
66
readable , _ , _ = select .select ([server ], [], [], MESSAGE_TIMEOUT )
65
67
for i in readable :
@@ -100,15 +102,15 @@ def main():
100
102
options , args = parser .parse_args (
101
103
[old_args .get (x , x ) for x in sys .argv [1 :]])
102
104
if options .zephyr :
103
- print >> sys . stderr , "get_message: The -z/-zephyr option is deprecated."
105
+ print ( "get_message: The -z/-zephyr option is deprecated." , file = sys . stderr )
104
106
version , timestamp , content = get_message ()
105
107
if options .new and has_seen (timestamp ):
106
108
# This is an already-seen message, and new-only was requested.
107
109
sys .exit (0 )
108
110
if not options .login :
109
111
# Update the timestamp so we know this message has been seen
110
112
write_message_times (timestamp )
111
- print content
113
+ print ( content )
112
114
113
115
if __name__ == "__main__" :
114
116
main ()
0 commit comments