def get_period(self, size):
        """ Automatically find a suitable period to use.
            Factors are best, because they will have 1 left over when 
            dividing SIZE+1.
            This only needs to be run once, on import.
        """
        # Check in the cache first
        if self._period_cache in size:
            return self._period_cache[size]

        # The highest acceptable factor will be the square root of the size.
        highest_acceptable_factor = int(math.sqrt(size))
    
        # Too high a factor (eg SIZE/2) and the interval is too small, too 
        # low (eg 2) and the period is too small.
        # We would prefer it to be lower than the number of VALID_CHARS, but more
        # than say 4.
        # Each is done separately for efficiency
        starting_point = len(self.valid_chars) > 14 and len(self.valid_chars)/2 or 13
        for p in xrange(starting_point, 7, -1):
            # If p is a factor
            if size % p == 0:
                # Save to the cache and return
                self._period_cache[size] = p
                return p
        for p in xrange(highest_acceptable_factor, starting_point+1, -1):
            if size % p == 0:
                self._period_cache[size] = p
                return p
        for p in [6,5,4,3,2]:
            if size % p == 0:
                self._period_cache[size] = p
                return p
        raise Exception, "No valid period could be found for SIZE=%d.\n" \
                         "Try avoiding prime numbers :-)" % SIZE
dataset/ETHPy150Open willhardy/Roll-Your-Own/rollyourown/commerce/utils/friendly_id.py/FriendlyID.get_period/swapped operands of `in`