Skip to content

Commit 0d9dd07

Browse files
committed
Move the DepotFile class to utils.
1 parent 947fecb commit 0d9dd07

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed
File renamed without changes.
File renamed without changes.

sc2reader/factories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import urlparse, time
1313
from sc2reader import utils
1414
from sc2reader import log_utils
15-
from sc2reader.objects import DepotFile
1615
from sc2reader.resources import Resource, Replay, Map, GameSummary, MapInfo, MapHeader, Localization
1716

1817
@log_utils.loggable
@@ -186,7 +185,7 @@ def _load_resource(self, resource, options=None, **new_options):
186185
"""http links, filesystem locations, and file-like objects"""
187186
options = options or self._get_options(Resource, **new_options)
188187

189-
if isinstance(resource, DepotFile):
188+
if isinstance(resource, utils.DepotFile):
190189
resource = resource.url
191190

192191
if isinstance(resource, basestring):

sc2reader/objects.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,6 @@
1212
ColorData = namedtuple('ColorData',['a','r','g','b'])
1313
BnetData = namedtuple('BnetData',['gateway','unknown2','subregion','uid'])
1414

15-
class DepotFile(object):
16-
url_template = 'http://{0}.depot.battle.net:1119/{1}.{2}'
17-
18-
def __init__(self, bytes):
19-
self.server = bytes[4:8].strip('\x00 ')
20-
self.hash = bytes[8:].encode('hex')
21-
self.type = bytes[0:4]
22-
23-
@property
24-
def url(self):
25-
return self.url_template.format(self.server, self.hash, self.type)
26-
27-
def __hash__(self):
28-
return hash(self.url)
29-
30-
def __str__(self):
31-
return self.url
32-
33-
3415
class Team(object):
3516
"""
3617
The team object primarily a container object for organizing :class:`Player`

sc2reader/readers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sc2reader.events.game import *
1212
from sc2reader.events.message import *
1313
from sc2reader.events.tracker import *
14-
from sc2reader.utils import AttributeDict
14+
from sc2reader.utils import AttributeDict, DepotFile
1515
from sc2reader.decoders import BitPackedDecoder, ByteDecoder
1616

1717
class Reader(object):

sc2reader/resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from sc2reader import exceptions
2525
from sc2reader.data import builds as datapacks
2626
from sc2reader.exceptions import SC2ReaderLocalizationError
27-
from sc2reader.objects import Player, Observer, Team, PlayerSummary, Graph, DepotFile, BuildEntry
27+
from sc2reader.objects import Player, Observer, Team, PlayerSummary, Graph, BuildEntry
2828
from sc2reader.constants import REGIONS, LOCALIZED_RACES, GAME_SPEED_FACTOR, LOBBY_PROPERTIES, GATEWAY_LOOKUP
2929

3030

@@ -761,7 +761,7 @@ def __init__(self, summary_file, filename=None, lang='enUS', **options):
761761
# The s2gs file also keeps reference to a series of s2mv files
762762
# Some of these appear to be encoded bytes and others appear to be
763763
# the preview images that authors may bundle with their maps.
764-
self.s2mv_urls = [str(DepotFile(file_hash)) for file_hash in self.parts[0][6][7]]
764+
self.s2mv_urls = [str(utils.DepotFile(file_hash)) for file_hash in self.parts[0][6][7]]
765765

766766
def load_translations(self):
767767
# This section of the file seems to map numerical ids to their
@@ -807,7 +807,7 @@ def load_translations(self):
807807
files = list()
808808
for file_hash in localization[1]:
809809
if file_hash[:4] != '\x00\x00\x00\x00':
810-
files.append(DepotFile(file_hash))
810+
files.append(utils.DepotFile(file_hash))
811811
self.localization_urls[language] = files
812812

813813
# Grab the gateway from the one of the files

sc2reader/utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,39 @@
88
from sc2reader.exceptions import MPQError
99
from sc2reader.constants import COLOR_CODES, COLOR_CODES_INV
1010

11+
class DepotFile(object):
12+
"""
13+
:param bytes: The raw bytes representing the depot file
14+
15+
The DepotFile object parses bytes for a dependency into their components
16+
and assembles them into a URL so that the dependency can be fetched.
17+
"""
18+
19+
#: The url template for all DepotFiles
20+
url_template = 'http://{0}.depot.battle.net:1119/{1}.{2}'
21+
22+
def __init__(self, bytes):
23+
#: The server the file is hosted on
24+
self.server = bytes[4:8].strip('\x00 ')
25+
26+
#: The unique content based hash of the file
27+
self.hash = bytes[8:].encode('hex')
28+
29+
#: The extension of the file on the server
30+
self.type = bytes[0:4]
31+
32+
@property
33+
def url(self):
34+
""" Returns url of the depot file. """
35+
return self.url_template.format(self.server, self.hash, self.type)
36+
37+
def __hash__(self):
38+
return hash(self.url)
39+
40+
def __str__(self):
41+
return self.url
42+
43+
1144
class PersonDict(dict):
1245
"""
1346
Supports lookup on both the player name and player id

0 commit comments

Comments
 (0)