Exemple #1
0
 def _validate_instruction_format(self, instruction_format):
     if instruction_format is not None and \
        instruction_format not in self.valid_instruction_formats:
         raise errors.InvalidParameterError(
             "{0} is not a valid instruction format".format(
                 instruction_format))
     return instruction_format
Exemple #2
0
    def _validate_radius(self, radius):
        if radius is None:
            return None

        if isinstance(radius, string_type):
            if radius != 'unlimited':
                raise errors.InvalidParameterError(
                    '{0} is not a valid radius'.format(radius))
        elif isinstance(radius, Number):
            if radius <= 0:
                raise errors.InvalidParameterError(
                    'radius must be greater than zero'.format(radius))
        else:
            raise errors.InvalidParameterError(
                '{0} is not a valid radius'.format(radius))

        return radius
Exemple #3
0
    def _validate_snapping(self, snaps, features):
        bearings = []
        radii = []
        if snaps is None:
            return (None, None)
        if len(snaps) != len(features):
            raise errors.InvalidParameterError(
                'Must provide exactly one snapping element for each input feature'
            )
        for snap in snaps:
            if snap is None:
                bearings.append(None)
                radii.append(None)
            else:
                try:
                    # radius-only
                    radius = self._validate_radius(snap)
                    bearing = None
                except errors.InvalidParameterError:
                    # (radius, angle, range) tuple
                    try:
                        radius, angle, rng = snap
                    except ValueError:
                        raise errors.InvalidParameterError(
                            'waypoint snapping should contain 3 elements: '
                            '(bearing, angle, range)')
                    self._validate_radius(radius)

                    try:
                        assert angle >= 0
                        assert angle <= 360
                        assert rng >= 0
                        assert rng <= 360
                    except (TypeError, AssertionError):
                        raise errors.InvalidParameterError(
                            'angle and range must be between 0 and 360')
                    bearing = (angle, rng)

                bearings.append(bearing)
                radii.append(radius)

        if all([b is None for b in bearings]):
            bearings = None

        return (bearings, radii)
Exemple #4
0
 def _validate_annotations(self, annotations):
     results = []
     if annotations is None:
         return None
     for annotation in annotations:
         if annotation not in self.valid_annotations:
             raise errors.InvalidParameterError(
                 "{0} is not a valid annotation".format(annotation))
         else:
             results.append(annotation)
     return results
Exemple #5
0
 def _validate_geom_overview(self, overview):
     if overview is not None and overview not in self.valid_geom_overview:
         raise errors.InvalidParameterError(
             "{0} is not a valid geometry overview type".format(overview))
     return overview
Exemple #6
0
 def _validate_geom_encoding(self, geom_encoding):
     if geom_encoding is not None and \
        geom_encoding not in self.valid_geom_encoding:
         raise errors.InvalidParameterError(
             "{0} is not a valid geometry format".format(geom_encoding))
     return geom_encoding