# Path: restapi/utils/decorators.py
# def crossdomain(func, allow_origin=None, allow_headers=None, max_age=None):
#     """
#     Enable CORS.
#     @param func: wrapped function
#     @param allow_origin: specify origin
#     @param allow_headers: allow headers
#     @param max_age: define max age
#     @return: function
#     """
#     if not allow_origin:
#         allow_origin = "*"
#     if not allow_headers:
#         allow_headers = "content-type, accept"
#     if not max_age:
#         max_age = 60
# 
#     @wraps(func)
#     def wrapper(*args, **kwargs):
#         response = func(*args, **kwargs)
#         cors_headers = {
#             "Access-Control-Allow-Origin": allow_origin,
#             "Access-Control-Allow-Methods": func.__name__.upper(),
#             "Access-Control-Allow-Headers": allow_headers,
#             "Access-Control-Max-Age": max_age,
#         }
#         if isinstance(response, tuple):
#             if len(response) == 3:
#                 headers = response[-1]
#             else:
#                 headers = {}
#             headers.update(cors_headers)
#             return response[0], response[1], headers
#         else:
#             return response, 200, cors_headers
#     return wrapper
# 
# Path: restapi/modules/responses.py
# def create_single_object_response(status, object, object_naming_singular):
# def create_multiple_object_response(status, list_of_objects, objects_naming_plural):
# 
# Path: restapi/modules/errors.py
# def log_exception(sender, exception, **extra):
# def error_incorrect_version(version):
# def error_object_not_found():
# def error_commit_error(ex):
# 
# Path: restapi/modules/statuscodes.py
# HTTP_OK = 200
# HTTP_CREATED = 201
# HTTP_ACCEPTED = 202
# HTTP_NON_AUTH_INFO = 203
# HTTP_NO_CONTENT = 204
# HTTP_RESET = 205
# HTTP_PARTIAL_CONTENT = 206
# HTTP_BAD_REQUEST = 400
# HTTP_UNAUTHORIZED = 401
# HTTP_PAYMENT_REQUIRED = 402
# HTTP_FORBIDDEN = 403
# HTTP_NOT_FOUND = 404
# HTTP_METHOD_NOT_ALLOWED = 405
# HTTP_NOT_ACCEPTABLE = 406
# HTTP_PROXY_AUTH_REQUIRED = 407
# HTTP_REQUEST_TIMEOUT = 408
# HTTP_CONFLICT = 409
# HTTP_GONE = 410
# HTTP_REQ_TO_LARGE = 413
# HTTP_REQ_TO_LONG = 414
# HTTP_UNSUPPORTED_MEDIA_TYPE = 415
# HTTP_TOO_MANY_REQUESTS = 429
# HTTP_INTERNAL_ERROR = 500
# HTTP_NOT_IMPLEMENTED = 501
# HTTP_BAD_GATEWAY = 502
# HTTP_SERVICE_UNAVAILABLE = 503
# HTTP_GATEWAY_TIMEOUT = 504
# HTTP_VERSION_UNSUPPORTED = 505
# 
# Path: restapi/components/auth/decorators.py
# def require_app_key(f):
#     """
#     @param f: flask function
#     @return: decorator, return the wrapped function or abort json object.
#     """
# 
#     @wraps(f)
#     def decorated(*args, **kwargs):
#         if match_api_keys(request.args.get('key'), request.remote_addr):
#             return f(*args, **kwargs)
#         else:
#             with log_to_file:
#                 log.warning("Unauthorized address trying to use API: " + request.remote_addr)
#             abort(401)
# 
#     return decorated
# 
# Path: restapi/utils/conversion/xmltodict.py
# class ParsingInterrupted(Exception):
# class _DictSAXHandler(object):
#     def __init__(self,
#                  item_depth=0,
#                  item_callback=lambda *args: True,
#                  xml_attribs=True,
#                  attr_prefix='@',
#                  cdata_key='#text',
#                  force_cdata=False,
#                  cdata_separator='',
#                  postprocessor=None,
#                  dict_constructor=OrderedDict,
#                  strip_whitespace=True,
#                  namespace_separator=':',
#                  namespaces=None):
#     def _build_name(self, full_name):
#     def _attrs_to_dict(self, attrs):
#     def startElement(self, full_name, attrs):
#     def endElement(self, full_name):
#     def characters(self, data):
#     def push_data(self, item, key, data):
# def parse(xml_input, encoding=None, expat=expat, process_namespaces=False,
#           namespace_separator=':', **kwargs):
# def _emit(key, value, content_handler,
#           attr_prefix='@',
#           cdata_key='#text',
#           depth=0,
#           preprocessor=None,
#           pretty=False,
#           newl='\n',
#           indent='\t'):
# def unparse(input_dict, output=None, encoding='utf-8', **kwargs):
#     def handle_item(path, item):
# 
# Path: restapi/utils/filters.py
# def filter_strings_nested_dict(node, search_term):
# def filter_nested_dicts_values(node, vals):
# def filter_nested_dicts_keys(node, vals):
# 
# Path: restapi/modules/weather/constants.py
# YAHOO_API_URI = 'http://weather.yahooapis.com/forecastrss'


import math
import httplib2
import constants
from flask import Blueprint, jsonify
from restapi.utils.decorators import crossdomain
from restapi.modules import responses, errors, statuscodes
from restapi.components.auth.decorators import require_app_key
from restapi.utils.conversion import xmltodict
from restapi.utils import filters
from .constants import YAHOO_API_URI



mod = Blueprint('weather', __name__, url_prefix='/api/v<float:version>/weather')

"""
Routes
"""


@mod.route('/<string:woeid>', methods=['GET'])
@crossdomain

# Path: restapi/utils/decorators.py
# def crossdomain(func, allow_origin=None, allow_headers=None, max_age=None):
#     """
#     Enable CORS.
#     @param func: wrapped function
#     @param allow_origin: specify origin
#     @param allow_headers: allow headers
#     @param max_age: define max age
#     @return: function
#     """
#     if not allow_origin:
#         allow_origin = "*"
#     if not allow_headers:
#         allow_headers = "content-type, accept"
#     if not max_age:
#         max_age = 60
# 
#     @wraps(func)
#     def wrapper(*args, **kwargs):
#         response = func(*args, **kwargs)
#         cors_headers = {
#             "Access-Control-Allow-Origin": allow_origin,
#             "Access-Control-Allow-Methods": func.__name__.upper(),
#             "Access-Control-Allow-Headers": allow_headers,
#             "Access-Control-Max-Age": max_age,
#         }
#         if isinstance(response, tuple):
#             if len(response) == 3:
#                 headers = response[-1]
#             else:
#                 headers = {}
#             headers.update(cors_headers)
#             return response[0], response[1], headers
#         else:
#             return response, 200, cors_headers
#     return wrapper
# 
# Path: restapi/modules/responses.py
# def create_single_object_response(status, object, object_naming_singular):
# def create_multiple_object_response(status, list_of_objects, objects_naming_plural):
# 
# Path: restapi/modules/errors.py
# def log_exception(sender, exception, **extra):
# def error_incorrect_version(version):
# def error_object_not_found():
# def error_commit_error(ex):
# 
# Path: restapi/modules/statuscodes.py
# HTTP_OK = 200
# HTTP_CREATED = 201
# HTTP_ACCEPTED = 202
# HTTP_NON_AUTH_INFO = 203
# HTTP_NO_CONTENT = 204
# HTTP_RESET = 205
# HTTP_PARTIAL_CONTENT = 206
# HTTP_BAD_REQUEST = 400
# HTTP_UNAUTHORIZED = 401
# HTTP_PAYMENT_REQUIRED = 402
# HTTP_FORBIDDEN = 403
# HTTP_NOT_FOUND = 404
# HTTP_METHOD_NOT_ALLOWED = 405
# HTTP_NOT_ACCEPTABLE = 406
# HTTP_PROXY_AUTH_REQUIRED = 407
# HTTP_REQUEST_TIMEOUT = 408
# HTTP_CONFLICT = 409
# HTTP_GONE = 410
# HTTP_REQ_TO_LARGE = 413
# HTTP_REQ_TO_LONG = 414
# HTTP_UNSUPPORTED_MEDIA_TYPE = 415
# HTTP_TOO_MANY_REQUESTS = 429
# HTTP_INTERNAL_ERROR = 500
# HTTP_NOT_IMPLEMENTED = 501
# HTTP_BAD_GATEWAY = 502
# HTTP_SERVICE_UNAVAILABLE = 503
# HTTP_GATEWAY_TIMEOUT = 504
# HTTP_VERSION_UNSUPPORTED = 505
# 
# Path: restapi/components/auth/decorators.py
# def require_app_key(f):
#     """
#     @param f: flask function
#     @return: decorator, return the wrapped function or abort json object.
#     """
# 
#     @wraps(f)
#     def decorated(*args, **kwargs):
#         if match_api_keys(request.args.get('key'), request.remote_addr):
#             return f(*args, **kwargs)
#         else:
#             with log_to_file:
#                 log.warning("Unauthorized address trying to use API: " + request.remote_addr)
#             abort(401)
# 
#     return decorated
# 
# Path: restapi/utils/conversion/xmltodict.py
# class ParsingInterrupted(Exception):
# class _DictSAXHandler(object):
#     def __init__(self,
#                  item_depth=0,
#                  item_callback=lambda *args: True,
#                  xml_attribs=True,
#                  attr_prefix='@',
#                  cdata_key='#text',
#                  force_cdata=False,
#                  cdata_separator='',
#                  postprocessor=None,
#                  dict_constructor=OrderedDict,
#                  strip_whitespace=True,
#                  namespace_separator=':',
#                  namespaces=None):
#     def _build_name(self, full_name):
#     def _attrs_to_dict(self, attrs):
#     def startElement(self, full_name, attrs):
#     def endElement(self, full_name):
#     def characters(self, data):
#     def push_data(self, item, key, data):
# def parse(xml_input, encoding=None, expat=expat, process_namespaces=False,
#           namespace_separator=':', **kwargs):
# def _emit(key, value, content_handler,
#           attr_prefix='@',
#           cdata_key='#text',
#           depth=0,
#           preprocessor=None,
#           pretty=False,
#           newl='\n',
#           indent='\t'):
# def unparse(input_dict, output=None, encoding='utf-8', **kwargs):
#     def handle_item(path, item):
# 
# Path: restapi/utils/filters.py
# def filter_strings_nested_dict(node, search_term):
# def filter_nested_dicts_values(node, vals):
# def filter_nested_dicts_keys(node, vals):
# 
# Path: restapi/modules/weather/constants.py
# YAHOO_API_URI = 'http://weather.yahooapis.com/forecastrss'


# Path: restapi/modules/weather/controllers.py
import math
import httplib2
import constants
from flask import Blueprint, jsonify
from restapi.utils.decorators import crossdomain
from restapi.modules import responses, errors, statuscodes
from restapi.components.auth.decorators import require_app_key
from restapi.utils.conversion import xmltodict
from restapi.utils import filters
from .constants import YAHOO_API_URI




mod = Blueprint('weather', __name__, url_prefix='/api/v<float:version>/weather')

"""
Routes
"""


@mod.route('/<string:woeid>', methods=['GET'])
@crossdomain

@require_app_key