# Path: tilenol/widgets/base.py
# class Widget(metaclass=ABCMeta):
# 
#     bar = dependency(Bar, 'bar')
#     stretched = False
# 
#     def __init__(self, right=False):
#         self.right = right
# 
#     @abstractmethod
#     def draw(self, canvas, left, right):
#         return left, right
# 
# Path: tilenol/theme.py
# class Theme(SubTheme):
# 
#     def __init__(self):
# 
#         blue = 0x4c4c99
#         dark_blue = 0x191933
#         orange = 0x99994c
#         gray = 0x808080
#         red = 0x994c4c
#         black = 0x000000
#         white = 0xffffff
# 
#         self.window = SubTheme('window')
#         self.window.border_width = 2
#         self.window.set_color('active_border', blue)
#         self.window.set_color('inactive_border', gray)
#         self.window.set_color('background', black)
# 
#         self.bar = SubTheme('bar')
#         self.bar.set_color('background', black)
#         self.bar.font = Font('Consolas', 18)
#         self.bar.box_padding = Padding(2, 2, 2, 2)
#         self.bar.text_padding = Padding(2, 4, 7, 4)
#         self.bar.icon_spacing = 2
#         self.bar.set_color('text_color', white)
#         self.bar.set_color('dim_color', gray)
#         self.bar.set_color('bright_color', orange)
#         self.bar.set_color('active_border', blue)
#         self.bar.set_color('subactive_border', gray)
#         self.bar.set_color('urgent_border', red)
#         self.bar.border_width = 2
#         self.bar.height = 24
#         self.bar.set_color('graph_color', blue)
#         self.bar.set_color('graph_fill_color', dark_blue)
#         self.bar.graph_line_width = 2
#         self.bar.separator_width = 1
#         self.bar.set_color('separator_color', gray)
# 
#         self.menu = SubTheme('bar')
#         self.menu.set_color('background', gray)
#         self.menu.set_color('text', white)
#         self.menu.set_color('highlight', blue)
#         self.menu.set_color('selection', blue)
#         self.menu.set_color('selection_text', white)
#         self.menu.set_color('cursor', black)
#         self.menu.font = Font('Consolas', 18)
#         self.menu.padding = Padding(2, 4, 7, 4)
#         self.menu.line_height = 24
# 
#         self.hint = SubTheme('hint')
#         self.hint.font = Font('Consolas', 18)
#         self.hint.set_color('background', black)
#         self.hint.set_color('border_color', gray)
#         self.hint.set_color('text_color', white)
#         self.hint.border_width = 2
#         self.hint.padding = Padding(5, 6, 9, 6)
# 
#         self.tabs = SubTheme('tabs')
#         self.tabs.font = Font('Monofur', 12)
#         self.tabs.set_color('background', black)
#         self.tabs.set_color('inactive_title', gray)
#         self.tabs.set_color('inactive_bg', black)
#         self.tabs.set_color('active_title', white)
#         self.tabs.set_color('active_bg', blue)
#         self.tabs.set_color('urgent_title', white)
#         self.tabs.set_color('urgent_bg', orange)
#         self.tabs.section_font = Font('Monofur', 12)
#         self.tabs.set_color('section_color', gray)
#         self.tabs.padding = Padding(5, 6, 6, 4)
#         self.tabs.margin = Padding(4, 4, 4, 4)
#         self.tabs.border_radius = 5
#         self.tabs.spacing = 2
#         self.tabs.icon_size = 14
#         self.tabs.icon_spacing = 6
#         self.tabs.section_padding = Padding(6, 2, 2, 2)
# 
#     def update_from(self, dic):
#         for key, sub in self.__dict__.items():
#             if isinstance(sub, SubTheme) and key in dic:
#                 sub.update_from(dic[key])
# 
# Path: tilenol/util.py
# def fetchurl(url, query=None):
#     if query is not None:
#         assert '?' not in url, ("Either include query in url"
#                                 "or pass as parameter, but not both")
#         url += '?' + urlencode(query)
#     proto, tail = splittype(url)
#     if proto != 'http':
#         raise RuntimeError("Unsupported protocol HTTP")
#     host, tail = splithost(tail)
#     ip = gethub().dns_resolver.gethostbyname(host)
#     cli = HTTPClient(ip)
#     resp = cli.request(tail, headers={'Host': host})
#     if resp.status.endswith('200 OK'):
#         return resp.body
#     raise RequestError(resp.status, resp)


from urllib.parse import urlencode
from xml.etree import ElementTree as ET
from io import BytesIO
from zorro import gethub, sleep
from zorro.http import HTTPClient
from zorro.di import has_dependencies, dependency
from .base import Widget
from tilenol.theme import Theme
from tilenol.util import fetchurl
import json
import logging
import cairo
            self.image = cairo.ImageSurface.create_from_png(BytesIO(data))
            self.oldimg_url = img_url
        except Exception as e:
            log.exception("Error fetching picture %r", img_url, exc_info=e)
            self.image = None

    def fetch_woeid(self):
        woeid = None
        while woeid is None:
            try:
                data = fetchurl(QUERY_URL, query={
                    'q': "select woeid from geo.places "
                    "where text='{0}'".format(self.location),
                    'format': 'json'
                })
                data = json.loads(data.decode('ascii'))['query']
                if data['count'] > 1:
                    woeid = data['results']['place'][0]['woeid']
                else:
                    woeid = data['results']['place']['woeid']
            except Exception as e:
                log.exception("Error fetching woeid", exc_info=e)
                sleep(60)
            else:
                if woeid is None:
                    sleep(60)
        return woeid

    def fetch(self):
        try:

# Path: tilenol/widgets/base.py
# class Widget(metaclass=ABCMeta):
# 
#     bar = dependency(Bar, 'bar')
#     stretched = False
# 
#     def __init__(self, right=False):
#         self.right = right
# 
#     @abstractmethod
#     def draw(self, canvas, left, right):
#         return left, right
# 
# Path: tilenol/theme.py
# class Theme(SubTheme):
# 
#     def __init__(self):
# 
#         blue = 0x4c4c99
#         dark_blue = 0x191933
#         orange = 0x99994c
#         gray = 0x808080
#         red = 0x994c4c
#         black = 0x000000
#         white = 0xffffff
# 
#         self.window = SubTheme('window')
#         self.window.border_width = 2
#         self.window.set_color('active_border', blue)
#         self.window.set_color('inactive_border', gray)
#         self.window.set_color('background', black)
# 
#         self.bar = SubTheme('bar')
#         self.bar.set_color('background', black)
#         self.bar.font = Font('Consolas', 18)
#         self.bar.box_padding = Padding(2, 2, 2, 2)
#         self.bar.text_padding = Padding(2, 4, 7, 4)
#         self.bar.icon_spacing = 2
#         self.bar.set_color('text_color', white)
#         self.bar.set_color('dim_color', gray)
#         self.bar.set_color('bright_color', orange)
#         self.bar.set_color('active_border', blue)
#         self.bar.set_color('subactive_border', gray)
#         self.bar.set_color('urgent_border', red)
#         self.bar.border_width = 2
#         self.bar.height = 24
#         self.bar.set_color('graph_color', blue)
#         self.bar.set_color('graph_fill_color', dark_blue)
#         self.bar.graph_line_width = 2
#         self.bar.separator_width = 1
#         self.bar.set_color('separator_color', gray)
# 
#         self.menu = SubTheme('bar')
#         self.menu.set_color('background', gray)
#         self.menu.set_color('text', white)
#         self.menu.set_color('highlight', blue)
#         self.menu.set_color('selection', blue)
#         self.menu.set_color('selection_text', white)
#         self.menu.set_color('cursor', black)
#         self.menu.font = Font('Consolas', 18)
#         self.menu.padding = Padding(2, 4, 7, 4)
#         self.menu.line_height = 24
# 
#         self.hint = SubTheme('hint')
#         self.hint.font = Font('Consolas', 18)
#         self.hint.set_color('background', black)
#         self.hint.set_color('border_color', gray)
#         self.hint.set_color('text_color', white)
#         self.hint.border_width = 2
#         self.hint.padding = Padding(5, 6, 9, 6)
# 
#         self.tabs = SubTheme('tabs')
#         self.tabs.font = Font('Monofur', 12)
#         self.tabs.set_color('background', black)
#         self.tabs.set_color('inactive_title', gray)
#         self.tabs.set_color('inactive_bg', black)
#         self.tabs.set_color('active_title', white)
#         self.tabs.set_color('active_bg', blue)
#         self.tabs.set_color('urgent_title', white)
#         self.tabs.set_color('urgent_bg', orange)
#         self.tabs.section_font = Font('Monofur', 12)
#         self.tabs.set_color('section_color', gray)
#         self.tabs.padding = Padding(5, 6, 6, 4)
#         self.tabs.margin = Padding(4, 4, 4, 4)
#         self.tabs.border_radius = 5
#         self.tabs.spacing = 2
#         self.tabs.icon_size = 14
#         self.tabs.icon_spacing = 6
#         self.tabs.section_padding = Padding(6, 2, 2, 2)
# 
#     def update_from(self, dic):
#         for key, sub in self.__dict__.items():
#             if isinstance(sub, SubTheme) and key in dic:
#                 sub.update_from(dic[key])
# 
# Path: tilenol/util.py
# def fetchurl(url, query=None):
#     if query is not None:
#         assert '?' not in url, ("Either include query in url"
#                                 "or pass as parameter, but not both")
#         url += '?' + urlencode(query)
#     proto, tail = splittype(url)
#     if proto != 'http':
#         raise RuntimeError("Unsupported protocol HTTP")
#     host, tail = splithost(tail)
#     ip = gethub().dns_resolver.gethostbyname(host)
#     cli = HTTPClient(ip)
#     resp = cli.request(tail, headers={'Host': host})
#     if resp.status.endswith('200 OK'):
#         return resp.body
#     raise RequestError(resp.status, resp)


# Path: tilenol/widgets/yahoo_weather.py
from urllib.parse import urlencode
from xml.etree import ElementTree as ET
from io import BytesIO
from zorro import gethub, sleep
from zorro.http import HTTPClient
from zorro.di import has_dependencies, dependency
from .base import Widget
from tilenol.theme import Theme
from tilenol.util import fetchurl
import json
import logging
import cairo

            self.image = cairo.ImageSurface.create_from_png(BytesIO(data))
            self.oldimg_url = img_url
        except Exception as e:
            log.exception("Error fetching picture %r", img_url, exc_info=e)
            self.image = None

    def fetch_woeid(self):
        woeid = None
        while woeid is None:
            try:
                data = fetchurl(QUERY_URL, query={
                    'q': "select woeid from geo.places "
                    "where text='{0}'".format(self.location),
                    'format': 'json'
                })
                data = json.loads(data.decode('ascii'))['query']
                if data['count'] > 1:
                    woeid = data['results']['place'][0]['woeid']
                else:
                    woeid = data['results']['place']['woeid']
            except Exception as e:
                log.exception("Error fetching woeid", exc_info=e)
                sleep(60)
            else:
                if woeid is None:
                    sleep(60)
        return woeid

    def fetch(self):
        try:

            data = fetchurl(self.uri)