def has_length(value,
               minimum = None,
               maximum = None,
               **kwargs):
    """Indicate whether ``value`` has a length greater than or equal to a
    supplied ``minimum`` and/or less than or equal to ``maximum``.

    .. note::

      This function works on any ``value`` that supports the
      :func:`len() <python:len>` operation. This means that ``value`` must implement
      the :func:`__len__ <python:__len__>` magic method.

      If ``value`` does not support length evaluation, the checker will raise
      :class:`NotImplemented <python:NotImplemented>`.

    :param value: The ``value`` to check.
    :type value: anything that supports length evaluation

    :param minimum: If supplied, will return ``True`` if ``value`` is greater than or
      equal to this value.
    :type minimum: numeric

    :param maximum: If supplied, will return ``True`` if ``value`` is less than or
      equal to this value.
    :type maximum: numeric

    :returns: ``True`` if ``value`` has length greater than or equal to a
      supplied ``minimum`` and less than or equal to a supplied ``maximum``.
      Otherwise, returns ``False``.
    :rtype: :class:`bool <python:bool>`


    :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
      keyword parameters passed to the underlying validator
    :raises TypeError: if ``value`` does not support length evaluation
    :raises ValueError: if both ``minimum`` and ``maximum`` are
      :obj:`None <python:None>`
    """
    if minimum is None and maximum is None:
        raise ValueError('minimum and maximum cannot both be None')

    length = len(value)
    minimum = validators.numeric(minimum,
                                 allow_empty = True)
    maximum = validators.numeric(maximum,
                                 allow_empty = True)

    return is_between(length,
                      minimum = minimum,
                      maximum = maximum)
Esempio n. 2
0
def is_numeric(value, minimum=None, maximum=None, **kwargs):
    """Indicate whether ``value`` is a numeric value.

    :param value: The value to evaluate.

    :param minimum: If supplied, will make sure that ``value`` is greater than or
      equal to this value.
    :type minimum: numeric

    :param maximum: If supplied, will make sure that ``value`` is less than or
      equal to this value.
    :type maximum: numeric

    :returns: ``True`` if ``value`` is valid, ``False`` if it is not.
    :rtype: :class:`bool <python:bool>`
    """
    try:
        value = validators.numeric(value,
                                   minimum=minimum,
                                   maximum=maximum,
                                   **kwargs)
    except Exception:
        return False

    return True
Esempio n. 3
0
 def align_max_deviation(self, val: Tuple[float, float]):
     val = validators.iterable(
         val, minimum_length=2, maximum_length=2, allow_empty=True
     )
     self._align_max_deviation = val if val is None else tuple([
         validators.numeric(i, minimum=0) for i in val
     ])
def is_numeric(value,
               minimum = None,
               maximum = None,
               **kwargs):
    """Indicate whether ``value`` is a numeric value.

    :param value: The value to evaluate.

    :param minimum: If supplied, will make sure that ``value`` is greater than or
      equal to this value.
    :type minimum: numeric

    :param maximum: If supplied, will make sure that ``value`` is less than or
      equal to this value.
    :type maximum: numeric

    :returns: ``True`` if ``value`` is valid, ``False`` if it is not.
    :rtype: :class:`bool <python:bool>`

    :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
      keyword parameters passed to the underlying validator

    """
    try:
        value = validators.numeric(value,
                                   minimum = minimum,
                                   maximum = maximum,
                                   **kwargs)
    except SyntaxError as error:
        raise error
    except Exception:
        return False

    return True
Esempio n. 5
0
    def missing_range_metadata(self, value):
        value = validators.iterable(value, allow_empty = True)
        if not value:
            self._missing_range_metadata = None
        else:
            ranges = [validators.dict(x, allow_empty = False) for x in value]
            validated_ranges = []
            for range in ranges:
                if 'high' not in range or 'low' not in range:
                    raise ValueError('missing_range_metadata requires a "high" and "low"'
                                     ' boundary to be defined.')

                validated_range = {
                    'high': validators.numeric(range.get('high'), allow_empty = False),
                    'low': validators.numeric(range.get('low'), allow_empty = False)
                }

                validated_ranges.append(validated_range)

            self._missing_range_metadata = validated_ranges
Esempio n. 6
0
 def video_face_memory(self, val: (float, int)):
     self._faces_time_memory = validators.numeric(val, minimum=0)
Esempio n. 7
0
 def face_align_size(self, val: (float, int)):
     self._face_align_size = int(validators.numeric(val))
def from_numeric(value):
    return validators.numeric(value, allow_empty=True)
Esempio n. 9
0
 def force_cpu(self, val: bool):
     self._force_cpu = bool(validators.numeric(val))
Esempio n. 10
0
    def get_score(self,
                  latitude,
                  longitude,
                  address=None,
                  return_transit_score=True,
                  return_bike_score=True,
                  max_retries=None):
        """Retrieve the :term:`WalkScore`, :term:`TransitScore`, and/or
              :term:`BikeScore` for a given location from the WalkScore API.

              :param latitude: The latitude of the location whose score(s) should
                be retrieved.
              :type latitude: numeric

              :param longitude: The longitude of the location whose score(s) should
                be retrieved.
              :type longitude: numeric

              :param address: The address whose score(s) should be retrieved.
                Defaults to :obj:`None <python:None>`.
              :type address: :class:`str <python:str>` / :obj:`None <python:None>`

              :param return_transit_score: If ``True``, will
                return the location's :term:`TransitScore`. Defaults to
                ``True``.
              :type return_transit_score: :class:`bool <python:bool>`

              :param return_bike_score: If ``True``, will
                return the location's :term:`BikeScore`. Defaults to
                ``True``.
              :type return_bike_score: :class:`bool <python:bool>`

              :param max_retries: The maximum number of retries to attempt if the
                WalkScore API times out or otherwise fails to return a response.
                If :obj:`None <python:None>`, will apply the default the configured
                when initializing the WalkScore API object. To suppress all retries,
                set to 0. Defaults to :obj:`None <python:None>`.
              :type max_retries: :obj:`None <python:None>` / :class:`int <python:int>`

              :returns: The location's :term:`WalkScore`, :term:`TransitScore`,
                and :term:`BikeScore` with meta-data.
              :rtype: :class:`LocationScore <walkscore.locationscore.LocationScore>`

              :raises AuthenticationError: if the API key is invalid
              :raises ScoreInProgressError: if the score is being calculated and is not
                currently available
              :raises WalkScoreError: if an internal WalkScore API error occurred
              :raises QuotaError: if your daily quota has been exceeded
              :raises BlockedIPError: if your IP address has been blocked
              :raises InvalidCoordinatesError: if your latitude/longitude coordinates
                are not valid

              """
        if not self.api_key:
            raise AuthenticationError('No API key supplied.')

        if not (latitude and longitude):
            raise InvalidCoordinatesError('No coordinates supplied.')

        if latitude:
            latitude = validators.numeric(latitude, allow_empty=False)
            latitude = str(latitude)
        if longitude:
            longitude = validators.numeric(longitude, allow_empty=False)
            longitude = str(longitude)

        if max_retries is None:
            max_retries = self.max_retries

        method = 'GET'
        parameters = {
            'address': address,
            'lat': latitude,
            'lon': longitude,
            'format': 'json',
            'transit': 1,
            'bike': 1,
            'wsapikey': self.api_key
        }

        if not return_bike_score:
            parameters['bike'] = None

        if not return_transit_score:
            parameters['transit'] = None

        if max_retries:
            response = self.http_client.request_with_retries(
                method,
                self._API_URL,
                parameters=parameters,
                request_body=None)
        else:
            response = self.http_client.request(method,
                                                self._API_URL,
                                                parameters=parameters,
                                                request_body=None)

        result_set = check_for_errors(*response)

        result = LocationScore.from_json(result_set[0], api_compatible=True)

        result.address = address
        result.original_latitude = latitude
        result.original_longitude = longitude

        return result
Esempio n. 11
0
 def store_face_frames(self, val: bool):
     self._store_face_frames = bool(validators.numeric(val))
Esempio n. 12
0
 def log_to_console(self, val: bool):
     self._log_to_console = bool(validators.numeric(val))
Esempio n. 13
0
 def detection_only(self, val: bool):
     self._detection_only = bool(validators.numeric(val))
Esempio n. 14
0
 def video_roi_adapt(self, val: bool):
     self._video_roi_adapt = bool(validators.numeric(val))
Esempio n. 15
0
 def max_frame_size(self, val: (float, int)):
     self._max_frame_size = int(validators.numeric(val))
Esempio n. 16
0
 def video_detect_interval(self, val: (int, float)):
     self._video_detect_interval = validators.numeric(val, minimum=0)
Esempio n. 17
0
 def video_capture_resize_to(self, val: int):
     self._video_capture_resize_to = int(validators.numeric(val))
Esempio n. 18
0
 def video_real_time(self, val: bool):
     self._video_real_time = bool(validators.numeric(val))
Esempio n. 19
0
 def similarity_thresh(self, val: (float, int)):
     self._similarity_thresh = validators.numeric(val, minimum=0, maximum=1)
Esempio n. 20
0
 def video_stop_at(self, val: (float, int)):
     self._video_stop_at = validators.numeric(val)
Esempio n. 21
0
 def detection_min_height(self, val: (float, int)):
     self._detection_min_height = int(validators.numeric(val, minimum=1))