Skip to content

Commit 8685d8c

Browse files
committed
Add autodoc strings for Length, PersonDict, and Color classes.
1 parent 4947278 commit 8685d8c

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

sc2reader/utils.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,22 @@ def read(self, bytes=0, bits=0):
419419
raise EOFError("Cannot read requested bits/bytes. End of buffer reached")
420420

421421
class PersonDict(dict):
422-
"""Delete is supported on the pid index only"""
422+
"""
423+
Supports lookup on both the player name and player id
424+
425+
::
426+
427+
person = PersonDict()
428+
person[1] = Player(1,"ShadesofGray")
429+
me = person["ShadesofGray"]
430+
del person[me.pid]
431+
432+
Delete is supported on the player id only
433+
"""
423434
def __init__(self, *args, **kwargs):
424435
self._key_map = dict()
425436

426437
if args:
427-
print args
428438
for arg in args[0]:
429439
self[arg[0]] = arg[1]
430440

@@ -478,8 +488,27 @@ def copy(self):
478488
return AttributeDict(super(AttributeDict,self).copy())
479489

480490
class Color(AttributeDict):
491+
"""
492+
Stores the string and rgba representation of a color. Individual components
493+
of the color can be retrieved with the dot operator::
494+
495+
color = Color(r=255, g=0, b=0, a=75)
496+
tuple(color.r,color.g, color.b, color.a) = color.rgba
497+
498+
Because Color is an implementation of an AttributeDict you must specify
499+
each component by name in the constructor.
500+
501+
Can print the string representation with str(Color)
502+
"""
503+
504+
@property
505+
def rgba(self):
506+
"""Tuple containing the (r,g,b,a) representation of the color"""
507+
return tuple(self.r,self.g,self.b,self.a)
508+
481509
@property
482510
def hex(self):
511+
"""The hexadecimal representation of the color"""
483512
return "{0.r:02X}{0.g:02X}{0.b:02X}".format(self)
484513

485514
def __str__(self):
@@ -585,16 +614,23 @@ def get_replay_files(path, exclude=[], depth=-1, followlinks=False, **extras):
585614

586615
from datetime import timedelta
587616
class Length(timedelta):
617+
618+
#: The total number of seconds represented
619+
seconds = int()
620+
588621
@property
589622
def hours(self):
623+
"""The number of hours in represented."""
590624
return self.seconds/3600
591625

592626
@property
593627
def mins(self):
628+
"""The number of minutes in excess of the hours."""
594629
return self.seconds/60
595630

596631
@property
597632
def secs(self):
633+
"""The number of seconds in excess of the minutes."""
598634
return self.seconds%60
599635

600636
def __str__(self):

0 commit comments

Comments
 (0)