<commit_before>import json
import time
import warnings

from ..compat import compat_urllib_error, compat_urllib_request
from ..errors import ClientError
from ..http import MultipartFormDataEncoder
from ..utils import max_chunk_count_generator
from ..compatpatch import ClientCompatPatch


class UploadEndpointsMixin(object):

    EXTERNAL_LOC_SOURCES = {
        'foursquare': 'foursquare_v2_id',
        'facebook_places': 'facebook_places_id',
        'facebook_events': 'facebook_events_id'
    }

    def _validate_location(self, location):
        location_keys = ['external_source', 'name', 'address']
        if type(location) != dict:
            raise ValueError('Location must be a dict')

        # patch location object returned from location_search
        if 'external_source' not in location and 'external_id_source' in location and 'external_id' in location:
            external_source = location['external_id_source']
            location['external_source'] = external_source
            if external_source in self.EXTERNAL_LOC_SOURCES:
                location[self.EXTERNAL_LOC_SOURCES[external_source]] = location['external_id']
        for k in location_keys:
            if not location.get(k):
                raise ValueError('Location dict must contain "%s"' % k)
        for k, val in self.EXTERNAL_LOC_SOURCES.items():
            if location['external_source'] == k and not location.get(val):
                raise ValueError('Location dict must contain "%s"' % val)

        media_loc = {
            'name': location['name'],
            'address': location['lat'],
            'external_source': location['external_source'],
        }
        if 'lat' in location and 'lng' in location:
            media_loc['lat'] = location['lat']
            media_loc['lng'] = location['lng']
        for k, val in self.EXTERNAL_LOC_SOURCES.items():
            if location['external_source'] == k:
                media_loc['external_source'] = k
                media_loc[val] = location[val]
        return media_loc

    @classmethod
    def standard_ratios(cls):
        """
        Acceptable min, max values of with/height ratios for an standard media upload

        :return: tuple of (min. ratio, max. ratio)
        """
        # Based on IG sampling
        # differs from https://help.instagram.com/1469029763400082
        # return 4.0/5.0, 1.19.0/1.0
        return 4.0 / 5.0, 90.0 / 47.0

    @classmethod
    def reel_ratios(cls):
        """
        Acceptable min, max values of with/height ratios for an story upload

        :return: tuple of (min. ratio, max. ratio)
        """
        # min_ratio = 9.0/16.0
        # max_ratio = 3.0/4.0 if is_video else 9.0/16.0
        device_ratios = [(3, 4), (2, 3), (5, 8), (3, 5), (9, 16), (10, 16), (40, 71)]
        aspect_ratios = map(lambda x: 1.0 * x[0] / x[1], device_ratios)
        return min(aspect_ratios), max(aspect_ratios)

    @classmethod
    def compatible_aspect_ratio(cls, size):
        """
        Helper method to check aspect ratio for standard uploads

        :param size: tuple of (width, height)
        :return: True/False
        """
        min_ratio, max_ratio = cls.standard_ratios()
        width, height = size
        this_ratio = 1.0 * width / height
        return min_ratio <= this_ratio <= max_ratio

    @classmethod
    def reel_compatible_aspect_ratio(cls, size, is_video=False):
        """
        Helper method to check aspect ratio for story uploads

        :param size: tuple of (width, height)
        :param is_video: True/False
        :return: True/False
        """
        min_ratio, max_ratio = cls.reel_ratios()
        width, height = size
        this_ratio = 1.0 * width / height
        return min_ratio <= this_ratio <= max_ratio
<commit_msg>Py3 compat patch<commit_after>import json
import time
import warnings

from ..compat import compat_urllib_error, compat_urllib_request
from ..errors import ClientError
from ..http import MultipartFormDataEncoder
from ..utils import max_chunk_count_generator
from ..compatpatch import ClientCompatPatch


class UploadEndpointsMixin(object):

    EXTERNAL_LOC_SOURCES = {
        'foursquare': 'foursquare_v2_id',
        'facebook_places': 'facebook_places_id',
        'facebook_events': 'facebook_events_id'
    }

    def _validate_location(self, location):
        location_keys = ['external_source', 'name', 'address']
        if type(location) != dict:
            raise ValueError('Location must be a dict')

        # patch location object returned from location_search
        if 'external_source' not in location and 'external_id_source' in location and 'external_id' in location:
            external_source = location['external_id_source']
            location['external_source'] = external_source
            if external_source in self.EXTERNAL_LOC_SOURCES:
                location[self.EXTERNAL_LOC_SOURCES[external_source]] = location['external_id']
        for k in location_keys:
            if not location.get(k):
                raise ValueError('Location dict must contain "%s"' % k)
        for k, val in self.EXTERNAL_LOC_SOURCES.items():
            if location['external_source'] == k and not location.get(val):
                raise ValueError('Location dict must contain "%s"' % val)

        media_loc = {
            'name': location['name'],
            'address': location['lat'],
            'external_source': location['external_source'],
        }
        if 'lat' in location and 'lng' in location:
            media_loc['lat'] = location['lat']
            media_loc['lng'] = location['lng']
        for k, val in self.EXTERNAL_LOC_SOURCES.items():
            if location['external_source'] == k:
                media_loc['external_source'] = k
                media_loc[val] = location[val]
        return media_loc

    @classmethod
    def standard_ratios(cls):
        """
        Acceptable min, max values of with/height ratios for a standard media upload

        :return: tuple of (min. ratio, max. ratio)
        """
        # Based on IG sampling
        # differs from https://help.instagram.com/1469029763400082
        # return 4.0/5.0, 1.19.0/1.0
        return 4.0 / 5.0, 90.0 / 47.0

    @classmethod
    def reel_ratios(cls):
        """
        Acceptable min, max values of with/height ratios for a story upload

        :return: tuple of (min. ratio, max. ratio)
        """
        # min_ratio = 9.0/16.0
        # max_ratio = 3.0/4.0 if is_video else 9.0/16.0
        device_ratios = [(3, 4), (2, 3), (5, 8), (3, 5), (9, 16), (10, 16), (40, 71)]
        aspect_ratios = list(map(lambda x: 1.0 * x[0] / x[1], device_ratios))
        return min(aspect_ratios), max(aspect_ratios)

    @classmethod
    def compatible_aspect_ratio(cls, size):
        """
        Helper method to check aspect ratio for standard uploads

        :param size: tuple of (width, height)
        :return: True/False
        """
        min_ratio, max_ratio = cls.standard_ratios()
        width, height = size
        this_ratio = 1.0 * width / height
        return min_ratio <= this_ratio <= max_ratio

    @classmethod
    def reel_compatible_aspect_ratio(cls, size, is_video=False):
        """
        Helper method to check aspect ratio for story uploads

        :param size: tuple of (width, height)
        :param is_video: True/False
        :return: True/False
        """
        min_ratio, max_ratio = cls.reel_ratios()
        width, height = size
        this_ratio = 1.0 * width / height
        return min_ratio <= this_ratio <= max_ratio

{'fraction_non_alphanumeric': 0.10479081430645375, 'fraction_numerical': 0.020720601821301306, 'mean_word_length': 2.4058426966292137, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '239445', 'n_tokens_mistral': 2336, 'n_tokens_neox': 2197, 'n_words': 624}