<s> import operator <EOL> import collections <EOL> import datetime <EOL> from . enums import RACE , CLASS , QUALITY , RACE_TO_FACTION , RAIDS , EXPANSION <EOL> from . utils import make_icon_url , normalize , make_connection <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class Thing ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . _data = data <EOL> def to_json ( self ) : <EOL> return json . dumps ( self . _data ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , ) <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , self . __class__ ) : <EOL> return False <EOL> return getattr ( self , '<STR_LIT>' ) == getattr ( other , '<STR_LIT>' ) <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> class LazyThing ( Thing ) : <EOL> def __init__ ( self , data , fields = None ) : <EOL> super ( LazyThing , self ) . __init__ ( data ) <EOL> self . _fields = set ( fields or [ ] ) <EOL> def _refresh_if_not_present ( self , field ) : <EOL> if not hasattr ( self , '<STR_LIT:_>' + field ) : <EOL> if field not in self . _data : <EOL> self . refresh ( field ) <EOL> return True <EOL> def _delete_property_fields ( self ) : <EOL> for field in self . _fields : <EOL> try : <EOL> delattr ( self , '<STR_LIT:_>' + field ) <EOL> except AttributeError : <EOL> pass <EOL> def _populate_data ( self , data ) : <EOL> raise NotImplementedError <EOL> def refresh ( self , * fields ) : <EOL> raise NotImplementedError <EOL> class Character ( LazyThing ) : <EOL> MALE = <NUM_LIT:0> <EOL> FEMALE = <NUM_LIT:1> <EOL> ALLIANCE = '<STR_LIT>' <EOL> HORDE = '<STR_LIT>' <EOL> DRAENEI = '<STR_LIT>' <EOL> DWARF = '<STR_LIT>' <EOL> GNOME = '<STR_LIT>' <EOL> HUMAN = '<STR_LIT>' <EOL> NIGHT_ELF = '<STR_LIT>' <EOL> WORGEN = '<STR_LIT>' <EOL> BLOOD_ELF = '<STR_LIT>' <EOL> UNDEAD = '<STR_LIT>' <EOL> GOBLIN = '<STR_LIT>' <EOL> ORC = '<STR_LIT>' <EOL> TAUREN = '<STR_LIT>' <EOL> TROLL = '<STR_LIT>' <EOL> DEATH_KNIGHT = '<STR_LIT>' <EOL> DRUID = '<STR_LIT>' <EOL> HUNTER = '<STR_LIT>' <EOL> MAGE = '<STR_LIT>' <EOL> PALADIN = '<STR_LIT>' <EOL> PRIEST = '<STR_LIT>' <EOL> ROGUE = '<STR_LIT>' <EOL> SHAMAN = '<STR_LIT>' <EOL> WARLOCK = '<STR_LIT>' <EOL> WARRIOR = '<STR_LIT>' <EOL> ALCHEMY = '<STR_LIT>' <EOL> BLACKSMITHING = '<STR_LIT>' <EOL> ENCHANTING = '<STR_LIT>' <EOL> ENGINEERING = '<STR_LIT>' <EOL> HERBALISM = '<STR_LIT>' <EOL> INSCRIPTION = '<STR_LIT>' <EOL> JEWELCRATING = '<STR_LIT>' <EOL> LEATHERWORKING = '<STR_LIT>' <EOL> MINING = '<STR_LIT>' <EOL> Skinning = '<STR_LIT>' <EOL> TAILORING = '<STR_LIT>' <EOL> ARCHAEOLOGY = '<STR_LIT>' <EOL> COOKING = '<STR_LIT>' <EOL> FIRST_AID = '<STR_LIT>' <EOL> FISHING = '<STR_LIT>' <EOL> STATS = '<STR_LIT>' <EOL> TALENTS = '<STR_LIT>' <EOL> ITEMS = '<STR_LIT>' <EOL> REPUTATIONS = '<STR_LIT>' <EOL> TITLES = '<STR_LIT>' <EOL> PROFESSIONS = '<STR_LIT>' <EOL> APPEARANCE = '<STR_LIT>' <EOL> COMPANIONS = '<STR_LIT>' <EOL> MOUNTS = '<STR_LIT>' <EOL> GUILD = '<STR_LIT>' <EOL> QUESTS = '<STR_LIT>' <EOL> HUNTER_PETS = '<STR_LIT>' <EOL> PROGRESSION = '<STR_LIT>' <EOL> ACHIEVEMENTS = '<STR_LIT>' <EOL> ALL_FIELDS = [ STATS , TALENTS , ITEMS , REPUTATIONS , TITLES , PROFESSIONS , <EOL> APPEARANCE , COMPANIONS , MOUNTS , GUILD , QUESTS , HUNTER_PETS , <EOL> PROGRESSION , ACHIEVEMENTS ] <EOL> def __init__ ( self , region , realm = None , name = None , data = None , fields = None , connection = None ) : <EOL> super ( Character , self ) . __init__ ( data , fields ) <EOL> self . region = region <EOL> self . connection = connection or make_connection ( ) <EOL> if realm and name and not data : <EOL> data = self . connection . get_character ( region , realm , name , raw = True , fields = self . _fields ) <EOL> self . _populate_data ( data ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name , normalize ( self . _data [ '<STR_LIT>' ] ) ) <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , Character ) : <EOL> return False <EOL> return self . connection == other . connection and self . name == other . name and self . get_realm_name ( ) == other . get_realm_name ( ) <EOL> def _populate_data ( self , data ) : <EOL> self . _data = data <EOL> self . name = normalize ( data [ '<STR_LIT:name>' ] ) <EOL> self . level = data [ '<STR_LIT>' ] <EOL> self . class_ = data [ '<STR_LIT:class>' ] <EOL> self . race = data [ '<STR_LIT>' ] <EOL> self . thumbnail = data [ '<STR_LIT>' ] <EOL> self . gender = data [ '<STR_LIT>' ] <EOL> self . achievement_points = data [ '<STR_LIT>' ] <EOL> self . faction = RACE_TO_FACTION . get ( self . race , '<STR_LIT>' ) <EOL> if Character . GUILD in self . _fields and Character . GUILD not in self . _data : <EOL> self . _data [ Character . GUILD ] = None <EOL> if '<STR_LIT>' in data : <EOL> self . last_modified = datetime . datetime . fromtimestamp ( data [ '<STR_LIT>' ] / <NUM_LIT:1000> ) <EOL> else : <EOL> self . last_modified = None <EOL> if '<STR_LIT>' in data : <EOL> self . hunter_pets = [ HunterPet ( hunter_pet ) for hunter_pet in self . _data [ '<STR_LIT>' ] ] <EOL> @ property <EOL> def realm ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _realm = Realm ( self . region , self . _data [ '<STR_LIT>' ] , connection = self . connection ) <EOL> return self . _realm <EOL> @ property <EOL> def professions ( self ) : <EOL> if self . _refresh_if_not_present ( Character . PROFESSIONS ) : <EOL> professions = { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] <EOL> } <EOL> for type_ in professions . keys ( ) : <EOL> professions [ type_ ] = [ Profession ( self , profession ) <EOL> for profession in self . _data [ Character . PROFESSIONS ] [ type_ ] ] <EOL> self . _professions = professions <EOL> return self . _professions <EOL> @ property <EOL> def progression ( self ) : <EOL> if self . _refresh_if_not_present ( Character . PROGRESSION ) : <EOL> instances = { '<STR_LIT>' : [ ] } <EOL> for type_ in instances . keys ( ) : <EOL> instances [ type_ ] = [ Instance ( self , instance , type_ ) for instance in self . _data [ Character . PROGRESSION ] [ type_ ] ] <EOL> self . _progression = instances <EOL> return self . _progression <EOL> @ property <EOL> def equipment ( self ) : <EOL> if self . _refresh_if_not_present ( Character . ITEMS ) : <EOL> self . _items = Equipment ( self , self . _data [ Character . ITEMS ] ) <EOL> return self . _items <EOL> @ property <EOL> def mounts ( self ) : <EOL> if self . _refresh_if_not_present ( Character . MOUNTS ) : <EOL> self . _mounts = list ( self . _data [ Character . MOUNTS ] ) <EOL> return self . _mounts <EOL> @ property <EOL> def companions ( self ) : <EOL> if self . _refresh_if_not_present ( Character . COMPANIONS ) : <EOL> self . _companions = list ( self . _data [ Character . COMPANIONS ] ) <EOL> return self . _companions <EOL> @ property <EOL> def reputations ( self ) : <EOL> if self . _refresh_if_not_present ( Character . REPUTATIONS ) : <EOL> self . _reputation = [ Reputation ( reputation ) for reputation in self . _data [ Character . REPUTATIONS ] ] <EOL> return self . _reputation <EOL> @ property <EOL> def titles ( self ) : <EOL> if self . _refresh_if_not_present ( Character . TITLES ) : <EOL> self . _titles = [ Title ( self , title ) for title in self . _data [ Character . TITLES ] ] <EOL> return self . _titles <EOL> @ property <EOL> def guild ( self ) : <EOL> if self . _refresh_if_not_present ( Character . GUILD ) : <EOL> data = self . _data [ Character . GUILD ] <EOL> if data : <EOL> data [ '<STR_LIT>' ] = self . faction . lower ( ) <EOL> self . _guild = Guild ( self . region , realm = self . _data [ '<STR_LIT>' ] , data = data , connection = self . connection ) <EOL> else : <EOL> self . _guild = None <EOL> return self . _guild <EOL> @ property <EOL> def appearance ( self ) : <EOL> if self . _refresh_if_not_present ( Character . APPEARANCE ) : <EOL> self . _appearance = Appearance ( self . _data [ Character . APPEARANCE ] ) <EOL> return self . _appearance <EOL> @ property <EOL> def talents ( self ) : <EOL> if self . _refresh_if_not_present ( Character . TALENTS ) : <EOL> self . _talents = [ Build ( self , build ) for build in self . _data [ Character . TALENTS ] ] <EOL> return self . _talents <EOL> @ property <EOL> def stats ( self ) : <EOL> if self . _refresh_if_not_present ( Character . STATS ) : <EOL> self . _stats = Stats ( self , self . _data [ Character . STATS ] ) <EOL> return self . _stats <EOL> @ property <EOL> def achievements ( self ) : <EOL> if self . _refresh_if_not_present ( Character . ACHIEVEMENTS ) : <EOL> self . _achievements = { } <EOL> achievements_completed = self . _data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> achievements_completed_ts = self . _data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> for id_ , timestamp in zip ( achievements_completed , achievements_completed_ts ) : <EOL> self . _achievements [ id_ ] = datetime . datetime . fromtimestamp ( timestamp / <NUM_LIT:1000> ) <EOL> return self . _achievements <EOL> def refresh ( self , * fields ) : <EOL> for field in fields : <EOL> self . _fields . add ( field ) <EOL> self . _populate_data ( self . connection . get_character ( self . region , self . _data [ '<STR_LIT>' ] , <EOL> self . name , raw = True , fields = self . _fields ) ) <EOL> self . _delete_property_fields ( ) <EOL> def get_realm_name ( self ) : <EOL> return normalize ( self . _data [ '<STR_LIT>' ] ) <EOL> def get_class_name ( self ) : <EOL> return CLASS . get ( self . class_ , '<STR_LIT>' ) <EOL> def get_spec_name ( self ) : <EOL> for talent in self . talents : <EOL> if talent . selected : <EOL> return talent . name <EOL> return '<STR_LIT>' <EOL> def get_full_class_name ( self ) : <EOL> spec_name = self . get_spec_name ( ) <EOL> class_name = self . get_class_name ( ) <EOL> return ( '<STR_LIT>' % ( spec_name , class_name ) ) . strip ( ) <EOL> def get_race_name ( self ) : <EOL> return RACE . get ( self . race , '<STR_LIT>' ) <EOL> def get_thumbnail_url ( self ) : <EOL> return '<STR_LIT>' % { <EOL> '<STR_LIT>' : self . region , <EOL> '<STR_LIT:path>' : self . thumbnail <EOL> } <EOL> class Title ( Thing ) : <EOL> def __init__ ( self , character , data ) : <EOL> super ( Title , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . format = data [ '<STR_LIT:name>' ] <EOL> self . selected = data . get ( '<STR_LIT>' , False ) <EOL> def __str__ ( self ) : <EOL> return self . format % self . _character . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . format ) <EOL> class Reputation ( Thing ) : <EOL> def __init__ ( self , data ) : <EOL> super ( Reputation , self ) . __init__ ( data ) <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . standing = data [ '<STR_LIT>' ] <EOL> self . value = data [ '<STR_LIT:value>' ] <EOL> self . max = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> @ property <EOL> def percent ( self ) : <EOL> return int ( <NUM_LIT> * self . value / self . max ) <EOL> class Stats ( Thing ) : <EOL> def __init__ ( self , character , data ) : <EOL> super ( Stats , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> self . agility = data [ '<STR_LIT>' ] <EOL> self . armor = data [ '<STR_LIT>' ] <EOL> self . attack_power = data [ '<STR_LIT>' ] <EOL> self . block = data [ '<STR_LIT>' ] <EOL> self . block_rating = data [ '<STR_LIT>' ] <EOL> self . crit = data [ '<STR_LIT>' ] <EOL> self . crit_rating = data [ '<STR_LIT>' ] <EOL> self . dodge = data [ '<STR_LIT>' ] <EOL> self . dodge_rating = data [ '<STR_LIT>' ] <EOL> self . expertise_rating = data [ '<STR_LIT>' ] <EOL> self . haste_rating = data [ '<STR_LIT>' ] <EOL> self . health = data [ '<STR_LIT>' ] <EOL> self . hit_rating = data [ '<STR_LIT>' ] <EOL> self . intellect = data [ '<STR_LIT:int>' ] <EOL> self . main_hand_damage_max = data [ '<STR_LIT>' ] <EOL> self . main_hand_damage_min = data [ '<STR_LIT>' ] <EOL> self . main_hand_dps = data [ '<STR_LIT>' ] <EOL> self . main_hand_expertise = data [ '<STR_LIT>' ] <EOL> self . main_hand_speed = data [ '<STR_LIT>' ] <EOL> self . mana_regen = data [ '<STR_LIT>' ] <EOL> self . mana_regen_combat = data [ '<STR_LIT>' ] <EOL> self . mastery = data [ '<STR_LIT>' ] <EOL> self . mastery_rating = data [ '<STR_LIT>' ] <EOL> self . off_hand_damage_max = data [ '<STR_LIT>' ] <EOL> self . off_hand_damage_min = data [ '<STR_LIT>' ] <EOL> self . off_hand_dps = data [ '<STR_LIT>' ] <EOL> self . off_hand_expertise = data [ '<STR_LIT>' ] <EOL> self . off_hand_speed = data [ '<STR_LIT>' ] <EOL> self . parry = data [ '<STR_LIT>' ] <EOL> self . parry_rating = data [ '<STR_LIT>' ] <EOL> self . power = data [ '<STR_LIT>' ] <EOL> self . power_type = data [ '<STR_LIT>' ] <EOL> self . ranged_attack_power = data [ '<STR_LIT>' ] <EOL> self . ranged_crit = data [ '<STR_LIT>' ] <EOL> self . ranged_crit_rating = data [ '<STR_LIT>' ] <EOL> self . ranged_damage_max = data [ '<STR_LIT>' ] <EOL> self . ranged_damage_min = data [ '<STR_LIT>' ] <EOL> self . ranged_dps = data [ '<STR_LIT>' ] <EOL> self . ranged_hit_rating = data [ '<STR_LIT>' ] <EOL> self . ranged_speed = data [ '<STR_LIT>' ] <EOL> self . resilience = data [ '<STR_LIT>' ] <EOL> self . resilience_rating = data [ '<STR_LIT>' ] <EOL> self . spell_crit = data [ '<STR_LIT>' ] <EOL> self . spell_crit_rating = data [ '<STR_LIT>' ] <EOL> self . spell_penetration = data [ '<STR_LIT>' ] <EOL> self . spell_power = data [ '<STR_LIT>' ] <EOL> self . spirit = data [ '<STR_LIT>' ] <EOL> self . stamina = data [ '<STR_LIT>' ] <EOL> self . strength = data [ '<STR_LIT:str>' ] <EOL> @ property <EOL> def hit ( self ) : <EOL> return self . _convert_rating_to_percent ( { <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> <EOL> } , self . hit_rating ) <EOL> @ property <EOL> def spell_hit ( self ) : <EOL> return self . _convert_rating_to_percent ( { <EOL> <NUM_LIT> : <NUM_LIT:8> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> <EOL> } , self . hit_rating ) <EOL> @ property <EOL> def haste ( self ) : <EOL> return self . _convert_rating_to_percent ( { <EOL> <NUM_LIT> : <NUM_LIT:10> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> <EOL> } , self . haste_rating ) <EOL> def _convert_rating_to_percent ( self , ratios , rating ) : <EOL> percent = None <EOL> for threshold in sorted ( ratios . keys ( ) ) : <EOL> if self . _character . level <= threshold : <EOL> percent = rating / ratios [ threshold ] <EOL> if percent is None : <EOL> percent = rating / rating [ max ( ratios . keys ( ) ) ] <EOL> return percent <EOL> class Appearance ( Thing ) : <EOL> def __init__ ( self , data ) : <EOL> super ( Appearance , self ) . __init__ ( data ) <EOL> self . face = data [ '<STR_LIT>' ] <EOL> self . feature = data [ '<STR_LIT>' ] <EOL> self . hair = data [ '<STR_LIT>' ] <EOL> self . hair_color = data [ '<STR_LIT>' ] <EOL> self . show_cloak = data [ '<STR_LIT>' ] <EOL> self . show_helm = data [ '<STR_LIT>' ] <EOL> self . skin_color = data [ '<STR_LIT>' ] <EOL> class Equipment ( Thing ) : <EOL> def __init__ ( self , character , data ) : <EOL> super ( Equipment , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> self . average_item_level = data [ '<STR_LIT>' ] <EOL> self . average_item_level_equipped = data [ '<STR_LIT>' ] <EOL> self . main_hand = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . off_hand = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . ranged = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . head = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . neck = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . shoulder = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . back = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . chest = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . shirt = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . tabard = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . wrist = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . hands = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . waist = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . legs = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . feet = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . finger1 = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . finger2 = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . trinket1 = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> self . trinket2 = EquippedItem ( self . _character . region , data [ '<STR_LIT>' ] ) if data . get ( '<STR_LIT>' ) else None <EOL> def __getitem__ ( self , item ) : <EOL> try : <EOL> return getattr ( self , item ) <EOL> except AttributeError : <EOL> raise IndexError <EOL> class Build ( Thing ) : <EOL> def __init__ ( self , character , data ) : <EOL> super ( Build , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> spec = data . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' in data : <EOL> self . icon = spec . get ( '<STR_LIT>' ) <EOL> self . name = spec . get ( '<STR_LIT:name>' ) <EOL> else : <EOL> self . icon = '<STR_LIT>' <EOL> self . name = '<STR_LIT:None>' <EOL> self . talents = data [ '<STR_LIT>' ] <EOL> self . selected = data . get ( '<STR_LIT>' , False ) <EOL> self . glyphs = { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> self . trees = [ ] <EOL> def __str__ ( self ) : <EOL> return self . name + '<STR_LIT>' % tuple ( map ( operator . attrgetter ( '<STR_LIT>' ) , self . trees ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , str ( self ) ) <EOL> def get_icon_url ( self , size = '<STR_LIT>' ) : <EOL> return make_icon_url ( self . _character . region , self . icon , size ) <EOL> class Glyph ( Thing ) : <EOL> def __init__ ( self , character , data ) : <EOL> super ( Glyph , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . glyph = data [ '<STR_LIT>' ] <EOL> self . item = data [ '<STR_LIT>' ] <EOL> self . icon = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> def get_icon_url ( self , size = '<STR_LIT>' ) : <EOL> return make_icon_url ( self . _character . region , self . icon , size ) <EOL> class Instance ( Thing ) : <EOL> def __init__ ( self , character , data , type_ ) : <EOL> super ( Instance , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> self . _type = type_ <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . normal = data [ '<STR_LIT>' ] <EOL> self . heroic = data [ '<STR_LIT>' ] <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . bosses = [ Boss ( self , boss ) for boss in data [ '<STR_LIT>' ] ] <EOL> def is_complete ( self , type_ ) : <EOL> assert type_ in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> return self . _data [ type_ ] == <NUM_LIT:2> <EOL> def is_started ( self , type_ ) : <EOL> assert type_ in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> return self . _data [ type_ ] == <NUM_LIT:1> <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> class Boss ( Thing ) : <EOL> def __init__ ( self , instance , data ) : <EOL> super ( Boss , self ) . __init__ ( data ) <EOL> self . _instance = instance <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . normal = data . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . heroic = data . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> class Profession ( Thing ) : <EOL> def __init__ ( self , character , data ) : <EOL> super ( Profession , self ) . __init__ ( data ) <EOL> self . _character = character <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . max = data [ '<STR_LIT>' ] <EOL> self . rank = data [ '<STR_LIT>' ] <EOL> self . icon = data [ '<STR_LIT>' ] <EOL> self . recipes = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> class HunterPet ( Thing ) : <EOL> def __init__ ( self , data ) : <EOL> super ( HunterPet , self ) . __init__ ( data ) <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . creature = data [ '<STR_LIT>' ] <EOL> self . slot = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> class Guild ( LazyThing ) : <EOL> ACHIEVEMENTS = '<STR_LIT>' <EOL> MEMBERS = '<STR_LIT>' <EOL> ALL_FIELDS = [ ACHIEVEMENTS , MEMBERS ] <EOL> def __init__ ( self , region , realm = None , name = None , data = None , fields = None , connection = None ) : <EOL> super ( Guild , self ) . __init__ ( data , fields ) <EOL> self . region = region <EOL> self . connection = connection or make_connection ( ) <EOL> if realm and name : <EOL> data = self . connection . get_guild ( region , realm , name , raw = True , fields = self . _fields ) <EOL> data [ '<STR_LIT>' ] = realm <EOL> self . _populate_data ( data ) <EOL> def __len__ ( self ) : <EOL> if '<STR_LIT>' in self . _data and isinstance ( self . _data [ '<STR_LIT>' ] , int ) : <EOL> return self . _data [ '<STR_LIT>' ] <EOL> return len ( self . members ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name , self . _data [ '<STR_LIT>' ] ) <EOL> def _populate_data ( self , data ) : <EOL> if self . _data is not None : <EOL> data [ '<STR_LIT>' ] = self . _data [ '<STR_LIT>' ] <EOL> self . _data = data <EOL> self . name = normalize ( data [ '<STR_LIT:name>' ] ) <EOL> self . emblem = Emblem ( data [ '<STR_LIT>' ] ) if '<STR_LIT>' in data else None <EOL> self . achievement_points = data [ '<STR_LIT>' ] <EOL> self . faction = ( { <EOL> <NUM_LIT:0> : '<STR_LIT>' , <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> } [ data [ '<STR_LIT>' ] ] if isinstance ( data [ '<STR_LIT>' ] , int ) else data [ '<STR_LIT>' ] ) . capitalize ( ) <EOL> def refresh ( self , * fields ) : <EOL> for field in fields : <EOL> self . _fields . add ( field ) <EOL> self . _populate_data ( self . connection . get_guild ( self . region , self . _data [ '<STR_LIT>' ] , <EOL> self . name , raw = True , fields = self . _fields ) ) <EOL> self . _delete_property_fields ( ) <EOL> @ property <EOL> def perks ( self ) : <EOL> return [ perk for perk in self . connection . get_guild_perks ( self . region ) if perk . guild_level <= self . level ] <EOL> @ property <EOL> def rewards ( self ) : <EOL> return [ reward for reward in self . connection . get_guild_rewards ( self . region ) <EOL> if reward . min_guild_level <= self . level ] <EOL> @ property <EOL> def achievements ( self ) : <EOL> if self . _refresh_if_not_present ( Guild . ACHIEVEMENTS ) : <EOL> self . _achievements = { } <EOL> achievements_completed = self . _data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> achievements_completed_ts = self . _data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> for id_ , timestamp in zip ( achievements_completed , achievements_completed_ts ) : <EOL> self . _achievements [ id_ ] = datetime . datetime . fromtimestamp ( timestamp / <NUM_LIT:1000> ) <EOL> return self . _achievements <EOL> @ property <EOL> def members ( self ) : <EOL> if self . _refresh_if_not_present ( Guild . MEMBERS ) : <EOL> self . _members = [ ] <EOL> for member in self . _data [ Guild . MEMBERS ] : <EOL> character = Character ( self . region , data = member [ '<STR_LIT>' ] , connection = self . connection ) <EOL> if not character . name : <EOL> continue <EOL> character . _guild = self <EOL> self . _members . append ( { <EOL> '<STR_LIT>' : character , <EOL> '<STR_LIT>' : member [ '<STR_LIT>' ] <EOL> } ) <EOL> return self . _members <EOL> @ property <EOL> def realm ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _realm = Realm ( self . region , self . _data [ '<STR_LIT>' ] , connection = self . connection ) <EOL> return self . _realm <EOL> def get_leader ( self ) : <EOL> for member in self . members : <EOL> if member [ '<STR_LIT>' ] is <NUM_LIT:0> : <EOL> return member [ '<STR_LIT>' ] <EOL> def get_realm_name ( self ) : <EOL> return normalize ( self . _data [ '<STR_LIT>' ] ) <EOL> class Emblem ( Thing ) : <EOL> def __init__ ( self , data ) : <EOL> super ( Emblem , self ) . __init__ ( data ) <EOL> self . border = data [ '<STR_LIT>' ] <EOL> self . border_color = data [ '<STR_LIT>' ] <EOL> self . icon = data [ '<STR_LIT>' ] <EOL> self . icon_color = data [ '<STR_LIT>' ] <EOL> self . background_color = data [ '<STR_LIT>' ] <EOL> class Perk ( Thing ) : <EOL> def __init__ ( self , region , data ) : <EOL> super ( Perk , self ) . __init__ ( data ) <EOL> self . _region = region <EOL> self . id = data [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] <EOL> self . name = data [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . description = data [ '<STR_LIT>' ] [ '<STR_LIT:description>' ] <EOL> self . subtext = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . cooldown = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . cast_time = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> self . icon = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> self . range = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> self . guild_level = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> if self . subtext : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name , self . subtext ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> def get_icon_url ( self , size = '<STR_LIT>' ) : <EOL> if not self . icon : <EOL> return '<STR_LIT>' <EOL> return make_icon_url ( self . _region , self . icon , size ) <EOL> class Reward ( Thing ) : <EOL> def __init__ ( self , region , data ) : <EOL> super ( Reward , self ) . __init__ ( data ) <EOL> self . min_guild_level = data [ '<STR_LIT>' ] <EOL> self . min_guild_reputation = data [ '<STR_LIT>' ] <EOL> self . races = data . get ( '<STR_LIT>' , [ ] ) <EOL> self . achievement = data . get ( '<STR_LIT>' ) <EOL> self . item = EquippedItem ( region , data [ '<STR_LIT>' ] ) <EOL> def __str__ ( self ) : <EOL> return self . item . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , str ( self ) ) <EOL> def get_race_names ( self ) : <EOL> return [ RACE [ race ] for race in self . races ] <EOL> class Realm ( Thing ) : <EOL> PVP = '<STR_LIT>' <EOL> PVE = '<STR_LIT>' <EOL> RP = '<STR_LIT>' <EOL> RPPVP = '<STR_LIT>' <EOL> HIGH = '<STR_LIT>' <EOL> MEDIUM = '<STR_LIT>' <EOL> LOW = '<STR_LIT>' <EOL> def __init__ ( self , region , name = None , data = None , connection = None ) : <EOL> super ( Realm , self ) . __init__ ( data ) <EOL> self . region = region <EOL> self . connection = connection or make_connection ( ) <EOL> if name and not data : <EOL> data = self . connection . get_realm ( region , name , raw = True ) <EOL> self . _populate_data ( data ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name , self . region . upper ( ) ) <EOL> def _populate_data ( self , data ) : <EOL> self . _data = data <EOL> self . name = normalize ( data [ '<STR_LIT:name>' ] ) <EOL> self . slug = data [ '<STR_LIT>' ] <EOL> self . status = data [ '<STR_LIT:status>' ] <EOL> self . queue = data [ '<STR_LIT>' ] <EOL> self . population = data [ '<STR_LIT>' ] <EOL> self . type = data [ '<STR_LIT:type>' ] <EOL> def refresh ( self ) : <EOL> self . _populate_data ( self . connection . get_realm ( self . name , raw = True ) ) <EOL> def has_queue ( self ) : <EOL> return self . queue <EOL> def is_online ( self ) : <EOL> return self . status <EOL> def is_offline ( self ) : <EOL> return not self . status <EOL> class EquippedItem ( Thing ) : <EOL> def __init__ ( self , region , data ) : <EOL> super ( EquippedItem , self ) . __init__ ( data ) <EOL> self . _region = region <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . quality = data [ '<STR_LIT>' ] <EOL> self . icon = data [ '<STR_LIT>' ] <EOL> self . reforge = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> self . set = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> self . enchant = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> self . extra_socket = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' , False ) <EOL> self . gems = collections . defaultdict ( lambda : None ) <EOL> for key , value in data [ '<STR_LIT>' ] . items ( ) : <EOL> if key . startswith ( '<STR_LIT>' ) : <EOL> self . gems [ int ( key [ <NUM_LIT:3> : ] ) ] = value <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> def get_quality_name ( self ) : <EOL> return QUALITY . get ( self . quality , '<STR_LIT>' ) <EOL> def get_icon_url ( self , size = '<STR_LIT>' ) : <EOL> return make_icon_url ( self . _region , self . icon , size ) <EOL> class Class ( Thing ) : <EOL> def __init__ ( self , data ) : <EOL> super ( Class , self ) . __init__ ( data ) <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . mask = data [ '<STR_LIT>' ] <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . power_type = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> class Race ( Thing ) : <EOL> def __init__ ( self , data ) : <EOL> super ( Race , self ) . __init__ ( data ) <EOL> self . id = data [ '<STR_LIT:id>' ] <EOL> self . mask = data [ '<STR_LIT>' ] <EOL> self . name = data [ '<STR_LIT:name>' ] <EOL> self . side = data [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> class Raid ( Thing ) : <EOL> def __init__ ( self , id ) : <EOL> self . id = id <EOL> def expansion ( self ) : <EOL> for exp , ids in RAIDS . items ( ) : <EOL> if self . id in ids : <EOL> for e in EXPANSION . keys ( ) : <EOL> if EXPANSION [ e ] [ <NUM_LIT:0> ] == exp : <EOL> return exp , EXPANSION [ e ] [ <NUM_LIT:1> ] <EOL> return ( None , None ) </s>
