Skip to content

Commit 0e6286f

Browse files
committed
Replace all references to gateway with region.
1 parent 4d068bf commit 0e6286f

File tree

6 files changed

+25
-35
lines changed

6 files changed

+25
-35
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
0.7.0 -
55
---------------------------
66

7+
* All references to the gateway attribute have been replaced in favor of region; e.g. replay.region
78
* Use generic UnitType and Ability classes for data. This means no more unit._type_class.__class__.__name__. But hopefully people were not doing that anyway.
89
* Now a CorruptTrackerFileError is raised when the tracker file is corrupted (generally only older resume_from_replay replays)
910
* Added replay.resume_from_replay flag. See replay.resume_user_info for additional info.

sc2reader/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
COLOR_CODES_INV = dict(zip(COLOR_CODES.values(), COLOR_CODES.keys()))
110110

111-
REGIONS = {
111+
SUBREGIONS = {
112112
# United States
113113
'us': {
114114
1: 'us',

sc2reader/factories/plugins/replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def toDict(replay):
6262

6363
# Consolidate replay metadata into dictionary
6464
return {
65-
'gateway': getattr(replay, 'gateway', None),
65+
'region': getattr(replay, 'region', None),
6666
'map_name': getattr(replay, 'map_name', None),
6767
'file_time': getattr(replay, 'file_time', None),
6868
'filehash': getattr(replay, 'filehash', None),

sc2reader/objects.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ def __init__(self, sid, slot_data):
124124
#: The Battle.net region the entity is registered to
125125
self.region = GATEWAY_LOOKUP[int(parts[0])]
126126

127-
#: Deprecated, see Entity.region
128-
self.gateway = self.region
129-
130127
#: The Battle.net subregion the entity is registered to
131128
self.subregion = int(parts[2])
132129

@@ -198,9 +195,6 @@ def __init__(self, pid, detail_data, attribute_data):
198195
#: The Battle.net region the entity is registered to
199196
self.region = GATEWAY_LOOKUP[detail_data['bnet']['region']]
200197

201-
#: Deprecated, see `Player.region`
202-
self.gateway = self.region
203-
204198
#: The Battle.net subregion the entity is registered to
205199
self.subregion = detail_data['bnet']['subregion']
206200

@@ -346,12 +340,7 @@ class PlayerSummary():
346340
#: Subregion id of player
347341
subregion = int()
348342

349-
#: The player's gateway, such as us, eu
350-
gateway = str()
351-
352-
#: The player's region, such as na, la, eu or ru. This is
353-
# provided for convenience, but as of 20121018 is strictly a
354-
# function of gateway and subregion.
343+
#: The player's region, such as us, eu, sea
355344
region = str()
356345

357346
#: unknown1

sc2reader/resources.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sc2reader.data import datapacks
1818
from sc2reader.exceptions import SC2ReaderLocalizationError, CorruptTrackerFileError
1919
from sc2reader.objects import Participant, Observer, Computer, Team, PlayerSummary, Graph, BuildEntry, MapInfo
20-
from sc2reader.constants import REGIONS, GAME_SPEED_FACTOR, LOBBY_PROPERTIES
20+
from sc2reader.constants import GAME_SPEED_FACTOR, LOBBY_PROPERTIES
2121

2222

2323
class Resource(object):
@@ -120,8 +120,8 @@ class Replay(Resource):
120120
#: The :class:`Length` of the replay in real time adjusted for the game speed
121121
real_length = None
122122

123-
#: The gateway the game was played on: us, eu, sea, etc
124-
gateway = str()
123+
#: The region the game was played on: us, eu, sea, etc
124+
region = str()
125125

126126
#: An integrated list of all the game events
127127
events = list()
@@ -211,7 +211,7 @@ def __init__(self, replay_file, filename=None, load_level=4, engine=sc2reader.en
211211
self.is_private = False
212212
self.map = None
213213
self.map_hash = ""
214-
self.gateway = ""
214+
self.region = ""
215215
self.events = list()
216216
self.teams, self.team = list(), dict()
217217

@@ -329,13 +329,13 @@ def load_details(self):
329329

330330
self.map_name = details['map_name']
331331

332-
self.gateway = details['cache_handles'][0].server.lower()
332+
self.region = details['cache_handles'][0].server.lower()
333333
self.map_hash = details['cache_handles'][-1].hash
334334
self.map_file = details['cache_handles'][-1]
335335

336336
#Expand this special case mapping
337-
if self.gateway == 'sg':
338-
self.gateway = 'sea'
337+
if self.region == 'sg':
338+
self.region = 'sea'
339339

340340
dependency_hashes = [d.hash for d in details['cache_handles']]
341341
if hashlib.sha256('Standard Data: Swarm.SC2Mod'.encode('utf8')).hexdigest() in dependency_hashes:
@@ -467,7 +467,7 @@ def get_team(team_id):
467467
self.recorder = None
468468

469469
entity_names = sorted(map(lambda p: p.name, self.entities))
470-
hash_input = self.gateway+":"+','.join(entity_names)
470+
hash_input = self.region+":"+','.join(entity_names)
471471
self.people_hash = hashlib.sha256(hash_input.encode('utf8')).hexdigest()
472472

473473
# The presence of observers and/or computer players makes this not actually ladder
@@ -616,17 +616,17 @@ class Map(Resource):
616616
#: The map description as written by author
617617
description = str()
618618

619-
def __init__(self, map_file, filename=None, gateway=None, map_hash=None, **options):
619+
def __init__(self, map_file, filename=None, region=None, map_hash=None, **options):
620620
super(Map, self).__init__(map_file, filename, **options)
621621

622622
#: The unique hash used to identify this map on bnet's depots.
623623
self.hash = map_hash
624624

625-
#: The gateway this map was posted to. Maps must be posted individually to each gateway.
626-
self.gateway = gateway
625+
#: The region this map was posted to. Maps must be posted individually to each region.
626+
self.region = region
627627

628628
#: A URL reference to the location of this map on bnet's depots.
629-
self.url = Map.get_url(gateway, map_hash)
629+
self.url = Map.get_url(self.region, map_hash)
630630

631631
#: The opened MPQArchive for this map
632632
self.archive = mpyq.MPQArchive(map_file)
@@ -672,12 +672,12 @@ def __init__(self, map_file, filename=None, gateway=None, map_hash=None, **optio
672672
self.dependencies.append(dependency_node.text)
673673

674674
@classmethod
675-
def get_url(cls, gateway, map_hash):
675+
def get_url(cls, region, map_hash):
676676
"""Builds a download URL for the map from its components."""
677-
if gateway and map_hash:
677+
if region and map_hash:
678678
# it seems like sea maps are stored on us depots.
679-
gateway = 'us' if gateway == 'sea' else gateway
680-
return cls.url_template.format(gateway, map_hash)
679+
region = 'us' if region == 'sea' else region
680+
return cls.url_template.format(region, map_hash)
681681
else:
682682
return None
683683

@@ -837,8 +837,8 @@ def load_translations(self):
837837
files.append(utils.DepotFile(file_hash))
838838
self.localization_urls[language] = files
839839

840-
# Grab the gateway from the one of the files
841-
self.gateway = list(self.localization_urls.values())[0][0].server.lower()
840+
# Grab the region from the one of the files
841+
self.region = list(self.localization_urls.values())[0][0].server.lower()
842842

843843
# Each of the localization urls points to an XML file with a set of
844844
# localization strings and their unique ids. After reading these mappings
@@ -1008,9 +1008,9 @@ def load_players(self):
10081008
settings = self.player_settings[index]
10091009
player.is_ai = not isinstance(struct[0][1], dict)
10101010
if not player.is_ai:
1011-
player.gateway = self.gateway
1011+
player.region = self.region
10121012
player.subregion = struct[0][1][0][2]
1013-
player.region = REGIONS[player.gateway].get(player.subregion, 'Unknown')
1013+
player.region = REGIONS[player.region].get(player.subregion, 'Unknown')
10141014
player.bnetid = struct[0][1][0][3]
10151015
player.unknown1 = struct[0][1][0]
10161016
player.unknown2 = struct[0][1][1]

sc2reader/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def toDict(replay):
328328

329329
# Consolidate replay metadata into dictionary
330330
return {
331-
'gateway': getattr(replay, 'gateway', None),
331+
'region': getattr(replay, 'region', None),
332332
'map_name': getattr(replay, 'map_name', None),
333333
'file_time': getattr(replay, 'file_time', None),
334334
'filehash': getattr(replay, 'filehash', None),

0 commit comments

Comments
 (0)