# Path: context/config.py
# def configuration():
#     """Return SafeConfigParser for config file"""
#     global _config
#     if _config is None:
#         _config = ConfigParser.SafeConfigParser()
#         path = config_file_path()
#         with open(path) as f:
#             _config.readfp(f)
#     return _config


import urllib
import requests
from ..config import configuration
# -*- coding: utf-8 -*-

config = configuration()
BING_ACCOUNT = config.get('context', 'bing_account')
BING_SEARCH_ACCOUNT_KEY = config.get('context', 'bing_search_account_key')

BING_URL = 'https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%%27web%%27&$format=json&Query=%s'


def search(query):
    query = "'%s'" % query
    req = BING_URL % urllib.quote(query)
    if len(req) > 2047:
        raise Exception

# Path: context/config.py
# def configuration():
#     """Return SafeConfigParser for config file"""
#     global _config
#     if _config is None:
#         _config = ConfigParser.SafeConfigParser()
#         path = config_file_path()
#         with open(path) as f:
#             _config.readfp(f)
#     return _config


# Path: context/services/bing.py
import urllib
import requests
from ..config import configuration

# -*- coding: utf-8 -*-

config = configuration()
BING_ACCOUNT = config.get('context', 'bing_account')
BING_SEARCH_ACCOUNT_KEY = config.get('context', 'bing_search_account_key')

BING_URL = 'https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%%27web%%27&$format=json&Query=%s'


def search(query):
    query = "'%s'" % query
    req = BING_URL % urllib.quote(query)
    if len(req) > 2047:
        raise Exception

    r = requests.get(req, auth=(BING_ACCOUNT, BING_SEARCH_ACCOUNT_KEY))