# Path: wham/httmock.py
# def urlmatch(scheme=None, netloc=None, path=None, method=None, params=None):
#     def decorator(func):
#         @wraps(func)
#         def inner(self_or_url, url_or_request, *args, **kwargs):
#             if isinstance(self_or_url, urlparse.SplitResult):
#                 url = self_or_url
#                 request = url_or_request
#             else:
#                 url = url_or_request
#                 request = args[0]
#             if scheme is not None and scheme != url.scheme:
#                 return
#             if netloc is not None and not re.match(netloc, url.netloc):
#                 return
#             if path is not None and not re.match(path, url.path):
#                 return
#             if method is not None and method.upper() != request.method:
#                 return
#             if method is not None and method.upper() != request.method:
#                 return
#             if params is not None:
#                 if dict(urlparse.parse_qsl(url.query)) != params:
#                     return
#             print 'using mock response for path %s' % url.path
#             return func(self_or_url, url_or_request, *args, **kwargs)
#         return inner
#     return decorator


from urllib import urlencode
from wham.httmock import urlmatch
from os.path import join
from os import listdir
from os.path import isfile, join
from urlparse import urlparse, parse_qs, parse_qsl
import urllib2


# def mock_function_builder(scheme, netloc, url_name, settings, responses_dir):
#     url_path = settings['url_path']
#     params = settings.get('params', {})
#     method = settings.get('method', 'GET')
#     @urlmatch(scheme=scheme, netloc=netloc, path=url_path, method=method, params=params)
#     def mock_function(_url, _request):
#         with open(join(responses_dir, url_name)) as f:
#             return f.read()
#     return mock_function


def build_httmock_function(scheme, netloc, url_path, response_content, method='GET', params=None):
    if params is None:
        params = {}

# Path: wham/httmock.py
# def urlmatch(scheme=None, netloc=None, path=None, method=None, params=None):
#     def decorator(func):
#         @wraps(func)
#         def inner(self_or_url, url_or_request, *args, **kwargs):
#             if isinstance(self_or_url, urlparse.SplitResult):
#                 url = self_or_url
#                 request = url_or_request
#             else:
#                 url = url_or_request
#                 request = args[0]
#             if scheme is not None and scheme != url.scheme:
#                 return
#             if netloc is not None and not re.match(netloc, url.netloc):
#                 return
#             if path is not None and not re.match(path, url.path):
#                 return
#             if method is not None and method.upper() != request.method:
#                 return
#             if method is not None and method.upper() != request.method:
#                 return
#             if params is not None:
#                 if dict(urlparse.parse_qsl(url.query)) != params:
#                     return
#             print 'using mock response for path %s' % url.path
#             return func(self_or_url, url_or_request, *args, **kwargs)
#         return inner
#     return decorator


# Path: wham/tests.py
from urllib import urlencode
from wham.httmock import urlmatch
from os.path import join
from os import listdir
from os.path import isfile, join
from urlparse import urlparse, parse_qs, parse_qsl
import urllib2



# def mock_function_builder(scheme, netloc, url_name, settings, responses_dir):
#     url_path = settings['url_path']
#     params = settings.get('params', {})
#     method = settings.get('method', 'GET')
#     @urlmatch(scheme=scheme, netloc=netloc, path=url_path, method=method, params=params)
#     def mock_function(_url, _request):
#         with open(join(responses_dir, url_name)) as f:
#             return f.read()
#     return mock_function


def build_httmock_function(scheme, netloc, url_path, response_content, method='GET', params=None):
    if params is None:
        params = {}

    @urlmatch(scheme=scheme, netloc=netloc, path=url_path, method=method, params=params)