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

Support Python 3 #19

Merged
merged 4 commits into from
Aug 26, 2017
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
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
colorama==0.3.9
nose==1.3.7
PyYAML==3.12
requests==2.18.3
PyYAML>=3.12,<4
requests>=2.18.3,<3
Requires==0.0.3
-e git+https://github.com/tedivm/python-screeps.git@master#egg=screepsapi
six==1.10.0
six>=1.10.0,<2
urwid==1.3.1
websocket-client==0.43.0
websocket-client==0.44.0
9 changes: 4 additions & 5 deletions screeps_console/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ def __init__(self, comp):
def loadList(self, listname):

if not listname in self.lists:
autocomplete = pkg_resources.resource_string(__name__, 'data/autocomplete/' + listname + '.dat')
autocomplete = pkg_resources.resource_string(__name__, 'data/autocomplete/' + listname + '.dat').decode("utf-8")
autocomplete_list = autocomplete.splitlines()
autocomplete_list_unique = self.sortList(autocomplete_list)
self.lists[listname] = autocomplete_list_unique
return self.lists[listname]


def sortList(self, list):
autocomplete_list_filtered = [x for x in list if not x.startswith('#') and x != '']
autocomplete_list_unique = {}.fromkeys(autocomplete_list_filtered).keys()
autocomplete_list_unique.sort()
def sortList(self, lst):
autocomplete_list_filtered = (x for x in lst if not x.startswith('#') and x != '')
autocomplete_list_unique = sorted(set(autocomplete_list_filtered))
return autocomplete_list_unique


Expand Down
15 changes: 7 additions & 8 deletions screeps_console/console.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env python

from base64 import b64decode
import getopt
import json
import logging
from outputparser import parseLine
from outputparser import tagLine
import screepsapi
import settings
from time import sleep
import websocket
from StringIO import StringIO
import sys
import zlib

Expand Down Expand Up @@ -43,6 +40,7 @@ def on_message(self, ws, message):
except:
print("Unexpected error:", sys.exc_info())
return

data = json.loads(message)

if 'shard' in data[1]:
Expand All @@ -54,13 +52,14 @@ def on_message(self, ws, message):
if 'messages' in data[1]:
stream = []

if 'log' in data[1]['messages']:
stream = stream + data[1]['messages']['log']
messages = data[1]["messages"]
if 'log' in messages:
stream.extend(messages['log'])

if 'results' in data[1]['messages']:
results = data[1]['messages']['results']
if 'results' in messages:
results = messages['results']
results = map(lambda x:'<type="result">'+x+'</type>',results)
stream = stream + results
stream.extend(results)

message_count = len(stream)

Expand Down
24 changes: 11 additions & 13 deletions screeps_console/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def getProcess(self):
console_path = os.path.join(os.path.dirname(sys.argv[0]), 'console.py ')
write_fd = self.loop.watch_pipe(self.onUpdate)
self.proc = subprocess.Popen(
[console_path + ' ' + self.connectionname + ' json'],
[sys.executable + ' ' + console_path + ' ' + self.connectionname + ' json'],
stdout=write_fd,
preexec_fn=os.setsid,
close_fds=True,
Expand All @@ -278,25 +278,23 @@ def disconnect(self):
self.proc = False

def onUpdate(self, data):

# If we lose the connection to the remote system close the console.
if data.startswith('### closed ###'):
if data.startswith(b'### closed ###'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of turning these into "bytes" instead of just strings? You do it in some other areas as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data is a byte array, in Python 3. startswith will throw on mismatched types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense.

self.proc = False
self.getProcess()
lostprocess_message = 'reconnecting to server . . .'
self.walker.append(urwid.Text(('logged_response', lostprocess_message)))
self.widget.set_focus(len(self.walker)-1)
return
if data[-1:] != '\n':
self.buffer += data
if data[-1:] != b'\n':
self.buffer += data.decode("utf-8")
return
if len(self.buffer) > 0:
data = self.buffer + data
data = self.buffer + data.decode("utf-8")
self.buffer = ''
data_lines = data.rstrip().split('\n')
data_lines = data.decode("utf-8").rstrip().split('\n')
for line_json in data_lines:
try:

if len(line_json) <= 0:
continue
try:
Expand Down Expand Up @@ -388,7 +386,7 @@ def __del__(self):
if server == 'main' or server == 'ptr':
legacyConfig = settings.getLegacySettings()
if legacyConfig:
if raw_input("Upgrade settings file to the new format? (y/n) ") != "y":
if input("Upgrade settings file to the new format? (y/n) ") != "y":
sys.exit(-1)
settings.addConnection('main', legacyConfig['screeps_username'], legacyConfig['screeps_password'])
config = settings.getSettings()
Expand All @@ -403,10 +401,10 @@ def __del__(self):
host = 'screeps.com'
secure = True
else:
host = raw_input("Host: ")
secure = raw_input("Secure (y/n) ") == "y"
username = raw_input("Username: ")
password = raw_input("Password: ")
host = input("Host: ")
secure = input("Secure (y/n) ") == "y"
username = input("Username: ")
password = input("Password: ")
settings.addConnection(server, username, password, host, secure)


Expand Down