# Path: battlenet/enums.py
# RACE = {
#     1: 'Human',
#     2: 'Orc',
#     3: 'Dwarf',
#     4: 'Night Elf',
#     5: 'Undead',
#     6: 'Tauren',
#     7: 'Gnome',
#     8: 'Troll',
#     9: 'Goblin',
#     10: 'Blood Elf',
#     11: 'Draenei',
#     22: 'Worgen',
# }
# 
# CLASS = {
#     1: 'Warrior',
#     2: 'Paladin',
#     3: 'Hunter',
#     4: 'Rogue',
#     5: 'Priest',
#     7: 'Shaman',
#     8: 'Mage',
#     9: 'Warlock',
#     11: 'Druid',
#     6: 'Death Knight',
# }
# 
# QUALITY = {
#     1: 'Common',
#     2: 'Uncommon',
#     3: 'Rare',
#     4: 'Epic',
#     5: 'Legendary',
# }
# 
# RACE_TO_FACTION = {
#     1: 'Alliance',
#     2: 'Horde',
#     3: 'Alliance',
#     4: 'Alliance',
#     5: 'Horde',
#     6: 'Horde',
#     7: 'Alliance',
#     8: 'Horde',
#     9: 'Horde',
#     10: 'Horde',
#     11: 'Alliance',
#     22: 'Alliance',
# }
# 
# Path: battlenet/utils.py
# def make_icon_url(region, icon, size='large'):
#     if not icon:
#         return ''
# 
#     if size == 'small':
#         size = 18
#     else:
#         size = 56
# 
#     return 'http://%s.media.blizzard.com/wow/icons/%d/%s.jpg' % (region, size, icon)
# 
# def normalize(name):
#     if not isinstance(name, unicode):
#         name = name.decode('utf8')
# 
#     return unicodedata.normalize('NFKC', name).encode('utf8')
# 
# def make_connection():
#     if not hasattr(make_connection, 'Connection'):
#         from .connection import Connection
#         make_connection.Connection = Connection
# 
#     return make_connection.Connection()


import operator
import collections
import datetime
    import simplejson as json
    import json
from .enums import RACE, CLASS, QUALITY, RACE_TO_FACTION
from .utils import make_icon_url, normalize, make_connection
    def __init__(self, character, data):
        NONE = 'None'
        NOICON = 'inv_misc_questionmark' # The infamous macro 'question mark' icon, because Blizzard uses it in this situation.
        self._character = character
        self._data = data

        self.build = data['build']
        self.icon = data.get('icon') if self.build.strip('0') else NOICON
        self.name = data['name'] if self.build.strip('0') else NONE
        self.selected = data.get('selected', False)
        self.glyphs = {
            'prime': [],
            'major': [],
            'minor': [],
        }

        if 'glyphs' in data:
            for type_ in self.glyphs.keys():
                self.glyphs[type_] = [Glyph(self, glyph) for glyph in data['glyphs'][type_]]

        Tree = collections.namedtuple('Tree', ('points', 'total',))
        self.trees = [Tree(**tree) for tree in data['trees']]

    def __str__(self):
        return self.name + ' (%d/%d/%d)' % tuple(map(operator.attrgetter('total'), self.trees))

    def __repr__(self):
        return '<%s: %s>' % (self.__class__.__name__, str(self))

    def get_icon_url(self, size='large'):

# Path: battlenet/enums.py
# RACE = {
#     1: 'Human',
#     2: 'Orc',
#     3: 'Dwarf',
#     4: 'Night Elf',
#     5: 'Undead',
#     6: 'Tauren',
#     7: 'Gnome',
#     8: 'Troll',
#     9: 'Goblin',
#     10: 'Blood Elf',
#     11: 'Draenei',
#     22: 'Worgen',
# }
# 
# CLASS = {
#     1: 'Warrior',
#     2: 'Paladin',
#     3: 'Hunter',
#     4: 'Rogue',
#     5: 'Priest',
#     7: 'Shaman',
#     8: 'Mage',
#     9: 'Warlock',
#     11: 'Druid',
#     6: 'Death Knight',
# }
# 
# QUALITY = {
#     1: 'Common',
#     2: 'Uncommon',
#     3: 'Rare',
#     4: 'Epic',
#     5: 'Legendary',
# }
# 
# RACE_TO_FACTION = {
#     1: 'Alliance',
#     2: 'Horde',
#     3: 'Alliance',
#     4: 'Alliance',
#     5: 'Horde',
#     6: 'Horde',
#     7: 'Alliance',
#     8: 'Horde',
#     9: 'Horde',
#     10: 'Horde',
#     11: 'Alliance',
#     22: 'Alliance',
# }
# 
# Path: battlenet/utils.py
# def make_icon_url(region, icon, size='large'):
#     if not icon:
#         return ''
# 
#     if size == 'small':
#         size = 18
#     else:
#         size = 56
# 
#     return 'http://%s.media.blizzard.com/wow/icons/%d/%s.jpg' % (region, size, icon)
# 
# def normalize(name):
#     if not isinstance(name, unicode):
#         name = name.decode('utf8')
# 
#     return unicodedata.normalize('NFKC', name).encode('utf8')
# 
# def make_connection():
#     if not hasattr(make_connection, 'Connection'):
#         from .connection import Connection
#         make_connection.Connection = Connection
# 
#     return make_connection.Connection()


# Path: battlenet/things.py
import operator
import collections
import datetime
    import simplejson as json
    import json
from .enums import RACE, CLASS, QUALITY, RACE_TO_FACTION
from .utils import make_icon_url, normalize, make_connection

    def __init__(self, character, data):
        NONE = 'None'
        NOICON = 'inv_misc_questionmark' # The infamous macro 'question mark' icon, because Blizzard uses it in this situation.
        self._character = character
        self._data = data

        self.build = data['build']
        self.icon = data.get('icon') if self.build.strip('0') else NOICON
        self.name = data['name'] if self.build.strip('0') else NONE
        self.selected = data.get('selected', False)
        self.glyphs = {
            'prime': [],
            'major': [],
            'minor': [],
        }

        if 'glyphs' in data:
            for type_ in self.glyphs.keys():
                self.glyphs[type_] = [Glyph(self, glyph) for glyph in data['glyphs'][type_]]

        Tree = collections.namedtuple('Tree', ('points', 'total',))
        self.trees = [Tree(**tree) for tree in data['trees']]

    def __str__(self):
        return self.name + ' (%d/%d/%d)' % tuple(map(operator.attrgetter('total'), self.trees))

    def __repr__(self):
        return '<%s: %s>' % (self.__class__.__name__, str(self))

    def get_icon_url(self, size='large'):

        return make_icon_url(self._character.region, self.icon, size)