From ce19872115aba2ef56308eb294c11d60fc25f0a2 Mon Sep 17 00:00:00 2001 From: Jeppe Klitgaard Date: Mon, 6 Apr 2015 02:11:26 +0200 Subject: [PATCH] start.py fixed, added compat.py --- minecraft/compat.py | 13 +++++++++++++ start.py | 12 ++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 minecraft/compat.py diff --git a/minecraft/compat.py b/minecraft/compat.py new file mode 100644 index 0000000..b30ef45 --- /dev/null +++ b/minecraft/compat.py @@ -0,0 +1,13 @@ +""" +This module stores code used for making pyCraft compatible with +both Python2 and Python3 while using the same codebase. +""" + +# Raw input -> input shenangians +# example +# > from minecraft.compat import input +# > input("asd") +try: + input = raw_input +except NameError: + pass diff --git a/start.py b/start.py index 6b1d98b..15d8ee3 100644 --- a/start.py +++ b/start.py @@ -2,12 +2,11 @@ import getpass import sys from optparse import OptionParser -from pprint import pprint - from minecraft import authentication from minecraft.exceptions import YggdrasilError from minecraft.networking.connection import Connection from minecraft.networking.packets import ChatMessagePacket, ChatPacket +from minecraft.compat import input def get_options(): @@ -25,13 +24,14 @@ def get_options(): (options, args) = parser.parse_args() if not options.username: - options.username = raw_input("Enter your username: ") + options.username = input("Enter your username: ") if not options.password: options.password = getpass.getpass("Enter your password: ") if not options.server: - options.server = raw_input("Please enter server address (including port): ") + options.server = input("Please enter server address" + " (including port): ") # Try to split out port and address if ':' in options.server: server = options.server.split(":") @@ -66,7 +66,7 @@ def main(): connection.register_packet_listener(print_chat, ChatMessagePacket) while True: try: - text = raw_input() + text = input() packet = ChatPacket() packet.message = text connection.write_packet(packet) @@ -76,4 +76,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main()