# Path: pricing/nav.py
# def nav(d, ks):
#     def nav2(d, ks):
#         if len(ks) == 0:
#             return d
#         if not isinstance(d, dict):
#             raise KeyError(ks)
#         if ks[0] not in d:
#             return None
#         return nav2(d[ks[0]], ks[1:])
#     return nav2(d, ks.split('.'))
# 
# Path: pricing/aws_regions.py
# AWS_REGION_LONG_NAMES = {
#     "us-east-1": "US East (N. Virginia)",
#     "us-west-1": "US West (N. California)",
#     "us-west-2": "US West (Oregon)",
#     "eu-west-1": "EU (Ireland)",
#     "eu-central-1": "EU (Frankfurt)",
#     "ap-northeast-1": "Asia Pacific (Tokyo)",
#     "ap-northeast-2": "Asia Pacific (Seoul)",
#     "ap-southeast-1": "Asia Pacific (Singapore)",
#     "ap-southeast-2": "Asia Pacific (Sydney)",
#     "sa-east-1": "South America (Sao Paulo)"
# }
# 
# Path: pricing/memoizer.py
# class memoized(object):
#     '''Decorator. Caches a function's return value each time it is called.
#     If called later with the same arguments, the cached value is returned
#     (not reevaluated).
#     '''
#     def __init__(self, func):
#         self.func = func
#         self.cache = {}
#     def __call__(self, *args):
#         if not isinstance(args, collections.Hashable):
#           # uncacheable. a list, for instance.
#           # better to not cache than blow up.
#             return self.func(*args)
#         if args in self.cache:
#             return self.cache[args]
#         else:
#             value = self.func(*args)
#             self.cache[args] = value
#             return value
#     def __repr__(self):
#         '''Return the function's docstring.'''
#         return self.func.__doc__
#     def __get__(self, obj, objtype):
#         '''Support instance methods.'''
#         return functools.partial(self.__call__, obj)


import os
import json
import requests
import urlparse
from pricing.nav import nav
from pricing.aws_regions import AWS_REGION_LONG_NAMES
from pricing.memoizer import memoized
#!/usr/bin/python

from __future__ import print_function



# evil
INSTANCE_PRICES_FILENAME = '/tmp/aws-prices.json'

INSTANCE_PRICES_URL_PREFIX="https://pricing.us-east-1.amazonaws.com/"
OPERATING_SYSTEM="Linux"
TENANCY='Shared'


class InstancePricing(object):
    def __init__(self):
        if not os.path.isfile(INSTANCE_PRICES_FILENAME):
            self.retrieve_pricing_file()
        with open(INSTANCE_PRICES_FILENAME, 'r') as infile:
            pricing = json.load(infile)

# Path: pricing/nav.py
# def nav(d, ks):
#     def nav2(d, ks):
#         if len(ks) == 0:
#             return d
#         if not isinstance(d, dict):
#             raise KeyError(ks)
#         if ks[0] not in d:
#             return None
#         return nav2(d[ks[0]], ks[1:])
#     return nav2(d, ks.split('.'))
# 
# Path: pricing/aws_regions.py
# AWS_REGION_LONG_NAMES = {
#     "us-east-1": "US East (N. Virginia)",
#     "us-west-1": "US West (N. California)",
#     "us-west-2": "US West (Oregon)",
#     "eu-west-1": "EU (Ireland)",
#     "eu-central-1": "EU (Frankfurt)",
#     "ap-northeast-1": "Asia Pacific (Tokyo)",
#     "ap-northeast-2": "Asia Pacific (Seoul)",
#     "ap-southeast-1": "Asia Pacific (Singapore)",
#     "ap-southeast-2": "Asia Pacific (Sydney)",
#     "sa-east-1": "South America (Sao Paulo)"
# }
# 
# Path: pricing/memoizer.py
# class memoized(object):
#     '''Decorator. Caches a function's return value each time it is called.
#     If called later with the same arguments, the cached value is returned
#     (not reevaluated).
#     '''
#     def __init__(self, func):
#         self.func = func
#         self.cache = {}
#     def __call__(self, *args):
#         if not isinstance(args, collections.Hashable):
#           # uncacheable. a list, for instance.
#           # better to not cache than blow up.
#             return self.func(*args)
#         if args in self.cache:
#             return self.cache[args]
#         else:
#             value = self.func(*args)
#             self.cache[args] = value
#             return value
#     def __repr__(self):
#         '''Return the function's docstring.'''
#         return self.func.__doc__
#     def __get__(self, obj, objtype):
#         '''Support instance methods.'''
#         return functools.partial(self.__call__, obj)


# Path: pricing/instance_pricing.py
import os
import json
import requests
import urlparse
from pricing.nav import nav
from pricing.aws_regions import AWS_REGION_LONG_NAMES
from pricing.memoizer import memoized

#!/usr/bin/python

from __future__ import print_function



# evil
INSTANCE_PRICES_FILENAME = '/tmp/aws-prices.json'

INSTANCE_PRICES_URL_PREFIX="https://pricing.us-east-1.amazonaws.com/"
OPERATING_SYSTEM="Linux"
TENANCY='Shared'


class InstancePricing(object):
    def __init__(self):
        if not os.path.isfile(INSTANCE_PRICES_FILENAME):
            self.retrieve_pricing_file()
        with open(INSTANCE_PRICES_FILENAME, 'r') as infile:
            pricing = json.load(infile)

        vers = nav(pricing, 'formatVersion')