<commit_before>from urllib.parse import urlencode

from mongoframes.factory.makers import Maker

__all__ = [
    'ImageURL'
    ]


class ImageURL(Maker):
    """
    Return a fake image URL (by default we use the http://fakeimg.pl service).
    """

    def __init__(self,
        width,
        height,
        options=None,
        service_url='http://fakeimg.pl',
        service_formatter=None
        ):

        # The size of the image to generate
        self._width = width
        self._height = height

        # A dictionary of options used when generating the image
        self._options = options

        # The service URL to use when calling the service
        self._service_url = service_url

        # A formatter function that can produce an image URL for the service
        self._service_formatter = service_formatter or \
                ImageURL._default_service_formatter

    def _assemble(self):
        return self._service_formatter(
            self._service_url,
            int(self._width),
            int(self._height),
            self._options
            )

    def _finish(self, value):
        min_date = self.parse_date_obj(self._min_date)
        max_date = self.parse_date_obj(self._max_date)
        seconds = random.randint(0, int((max_date - min_date).total_seconds()))
        return min_date + datetime.timedelta(seconds=seconds)

    @staticmethod
    def _default_service_formatter(service_url, width, height, options):
        """Generate an image URL for a service"""

        # Build the base URL
        image_url = '{service_url}/{width}x{height}/'.format(
            service_url=service_url,
            width=width,
            height=height
            )

        # Add any options
        if options:
            image_url += '?' + urlencode(options)

        return image_url<commit_msg>Updated Image maker to support background/foreground colours.<commit_after>from urllib.parse import urlencode

from mongoframes.factory.makers import Maker

__all__ = [
    'ImageURL'
    ]


class ImageURL(Maker):
    """
    Return a fake image URL (by default we use the http://fakeimg.pl service).
    """

    def __init__(self,
        width,
        height,
        background='CCCCCC',
        foreground='8D8D8D',
        options=None,
        service_url='http://fakeimg.pl',
        service_formatter=None
        ):

        # The size of the image to generate
        self._width = width
        self._height = height

        # The foreground/background colours for the image
        self._background = background
        self._foreground = foreground

        # A dictionary of options used when generating the image
        self._options = options

        # The service URL to use when calling the service
        self._service_url = service_url

        # A formatter function that can produce an image URL for the service
        self._service_formatter = service_formatter or \
                ImageURL._default_service_formatter

    def _assemble(self):
        return self._service_formatter(
            self._service_url,
            int(self._width),
            int(self._height),
            self._background,
            self._foreground,
            self._options
            )

    def _finish(self, value):
        min_date = self.parse_date_obj(self._min_date)
        max_date = self.parse_date_obj(self._max_date)
        seconds = random.randint(0, int((max_date - min_date).total_seconds()))
        return min_date + datetime.timedelta(seconds=seconds)

    @staticmethod
    def _default_service_formatter(
        service_url,
        width,
        height,
        background,
        foreground,
        options
        ):
        """Generate an image URL for a service"""

        # Build the base URL
        image_tmp = '{service_url}/{width}x{height}/{background}/{foreground}'
        image_url = image_tmp.format(
            service_url=service_url,
            width=width,
            height=height,
            background=background,
            foreground=foreground
            )

        # Add any options
        if options:
            image_url += '?' + urlencode(options)

        return image_url
{'fraction_non_alphanumeric': 0.07992388201712655, 'fraction_numerical': 0.0011893434823977164, 'mean_word_length': 2.0471014492753623, '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': '1992616', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1100, 'n_words': 292}