<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from sys import exc_info
from dns.resolver import query, NXDOMAIN
from requests import get, post, Session
from requests.exceptions import HTTPError, Timeout, ConnectionError, InvalidSchema, InvalidURL
from itertools import izip, chain
import ipaddress
from dns import name
from collections import namedtuple
import validators
from dns.reversename import ipv4_reverse_domain, ipv6_reverse_domain, from_address as name_from_ip
from urlparse import urlparse
import re
import functools

from .exceptions import UnknownCodeError, UnathorizedAPIKeyError, InvalidHostnameError,\
InvalidURLError, InvalidHostError, InvalidIPv4Error, InvalidIPv6Error
    
def accepts_valid_urls(f):
    @functools.wraps(f)
    def wrapper(client, urls, *args, **kwargs):
        '''Run the function and return its return value
         if all given urls are valid - otherwise raise InvalidURLError
        :param client:  a client of a service
        listing hosts or urls
        :param urls: an iterable containing urls
        :returns: a return value of the function f
        :raises InvalidURLError: if the iterable contains invalid urls
        '''
        invalid_urls = filter(lambda u: not is_valid_url(u), urls)
        if invalid_urls:
            msg = 'The values: {} are not valid urls'.format(','.join(invalid_urls))
            raise InvalidURLError, msg
        
        return f(client, urls, *args, **kwargs)
    
    return wrapper

class HostList(object):
    ''' A class of clients for local or remote host list services '''
    
    def __init__(self, host_factory):
        ''' Constructor
        
        :param host_factory: a function responsible for
        creating valid host objects. It may raise InvalidHostError
        (or its subclasses) if a value passed to it is not
        a valid host of type accepted by the factory.
        '''
        
        self._host_factory = host_factory
        
    def _contains(self, host_value):
        ''' Check if the service lists an item
        matching given host value
        
        :param host_value: a host value
        :returns: True if the service lists a matching
        value
        '''
        raise NotImplementedError<commit_msg>Rename client argument in the wrapper of accepts_valid_urls<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from sys import exc_info
from dns.resolver import query, NXDOMAIN
from requests import get, post, Session
from requests.exceptions import HTTPError, Timeout, ConnectionError, InvalidSchema, InvalidURL
from itertools import izip, chain
import ipaddress
from dns import name
from collections import namedtuple
import validators
from dns.reversename import ipv4_reverse_domain, ipv6_reverse_domain, from_address as name_from_ip
from urlparse import urlparse
import re
import functools

from .exceptions import UnknownCodeError, UnathorizedAPIKeyError, InvalidHostnameError,\
InvalidURLError, InvalidHostError, InvalidIPv4Error, InvalidIPv6Error
    
def accepts_valid_urls(f):
    @functools.wraps(f)
    def wrapper(obj, urls, *args, **kwargs):
        '''Run the function and return its return value
         if all given urls are valid - otherwise raise InvalidURLError
        :param obj: an object in whose class f is defined
        :param urls: an iterable containing urls
        :returns: a return value of the function f
        :raises InvalidURLError: if the iterable contains invalid urls
        '''
        invalid_urls = filter(lambda u: not is_valid_url(u), urls)
        if invalid_urls:
            msg = 'The values: {} are not valid urls'.format(','.join(invalid_urls))
            raise InvalidURLError, msg
        
        return f(obj, urls, *args, **kwargs)
    
    return wrapper

class HostList(object):
    ''' A class of clients for local or remote host list services '''
    
    def __init__(self, host_factory):
        ''' Constructor
        
        :param host_factory: a function responsible for
        creating valid host objects. It may raise InvalidHostError
        (or its subclasses) if a value passed to it is not
        a valid host of type accepted by the factory.
        '''
        
        self._host_factory = host_factory
        
    def _contains(self, host_value):
        ''' Check if the service lists an item
        matching given host value
        
        :param host_value: a host value
        :returns: True if the service lists a matching
        value
        '''
        raise NotImplementedError
{'fraction_non_alphanumeric': 0.06255506607929516, 'fraction_numerical': 0.0022026431718061676, 'mean_word_length': 2.9079173838209984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4186339', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1226, 'n_words': 475}