From 95389f8da8715a7bf5b759d359b5aeff914c0acb Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sun, 6 Mar 2016 19:46:14 +0000 Subject: [PATCH] few py3 comp changes --- steam/client/__init__.py | 4 ++-- steam/core/cm.py | 9 +++------ steam/core/connection.py | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/steam/client/__init__.py b/steam/client/__init__.py index 9e48a8e..d3d317f 100644 --- a/steam/client/__init__.py +++ b/steam/client/__init__.py @@ -239,7 +239,7 @@ class SteamClient(EventEmitter, FeatureBase): if filepath and os.path.isfile(filepath): try: - with open(filepath, 'r') as f: + with open(filepath, 'rb') as f: return f.read() except IOError as e: logger.error("get_sentry: %s" % str(e)) @@ -258,7 +258,7 @@ class SteamClient(EventEmitter, FeatureBase): filepath = self._get_sentry_path(username) if filepath: try: - with open(filepath, 'w') as f: + with open(filepath, 'wb') as f: f.write(sentry_bytes) return True except IOError as e: diff --git a/steam/core/cm.py b/steam/core/cm.py index e6f33fa..3e2e809 100644 --- a/steam/core/cm.py +++ b/steam/core/cm.py @@ -5,10 +5,7 @@ import zipfile from time import time from collections import defaultdict -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO +from io import BytesIO import gevent from gevent import event, queue @@ -266,7 +263,7 @@ class CMClient(EventEmitter): if msg.body.size_unzipped: logger.debug("Unzipping body") - data = zipfile.ZipFile(StringIO(msg.body.message_body)).read('z') + data = zipfile.ZipFile(BytesIO(msg.body.message_body)).read('z') if len(data) != msg.body.size_unzipped: logger.fatal("Unzipped size mismatch") @@ -415,7 +412,7 @@ class CMServerList(object): def __iter__(self): def genfunc(): while True: - good_servers = filter(lambda x: x[1]['quality'] == CMServerList.Good, self.list.items()) + good_servers = list(filter(lambda x: x[1]['quality'] == CMServerList.Good, self.list.items())) if len(good_servers) == 0: self.reset_all() diff --git a/steam/core/connection.py b/steam/core/connection.py index 6b8f579..8dfcfef 100644 --- a/steam/core/connection.py +++ b/steam/core/connection.py @@ -11,7 +11,7 @@ logger = logging.getLogger("Connection") class Connection(object): - MAGIC = 'VT01' + MAGIC = b'VT01' FMT = '