def parse(cls, input): m = cls.regex.match(input) if not m: raise errors.ParseError('Invalid dimension syntax.') inputs = m.groupdict() values = {} default_unit = None for dim in inputs.iterkeys(): try: value = utils.units.parse(inputs[dim]) except ValueError: raise errors.ParseError('Invalid quantity: %s' % inputs[dim]) values[dim] = value if default_unit is None and not value.unitless: default_unit = value.units if default_unit is None: raise errors.ParseError('No units specified.') for dim in inputs.iterkeys(): if values[dim].unitless: values[dim] = utils.units.Quantity(values[dim].magnitude, default_unit) return mudsling.utils.measurements.Dimensions( length=values['length'], width=values['width'], height=values['height'], units=str(default_unit.keys()[0]) )
def parse(self, input, actor=None): q = UnitStaticParser.parse(input) dims = self.dimensions if isinstance(dims, basestring): if not q.is_simple_dimension(dims): raise errors.ParseError("Invalid %s." % dims) elif isinstance(dims, utils.units.UnitsContainer): if dims != q.dimensionality: raise errors.ParseError("Units not compatible with %s." % dims) return q
def parse(cls, input): m = input.strip().lower() if m in cls.true_vals: return True elif m in cls.false_vals: return False else: raise errors.ParseError(cls.err % input)
def parse(cls, input): objClass = registry.classes.get_class(input) if objClass is None: # noinspection PyBroadException try: objClass = utils.modules.class_from_path(input) except: objClass = None if objClass is None or not issubclass(objClass, StoredObject): raise errors.ParseError("Invalid object class name: %r" % input) return objClass
def parse(cls, input): try: return ictime.parse_user_duration(input) except ValueError: raise errors.ParseError("Invalid duration.")
def parse(cls, input): try: return super(ICDateStaticParser, cls).parse(input).date except errors.ParseError: raise errors.ParseError("Invalid date.")
def parse(cls, input): try: return ictime.parse_user_datetime(input) except ValueError: raise errors.ParseError("Invalid timestamp.")
def parse_ip(ipstr): if re.match(r'[.*0-9]+', ipstr): return ipstr else: raise errors.ParseError('Invalid IP pattern: %s' % ipstr)
def parse(cls, input): if isinstance(input, str) or isinstance(input, unicode): return map(str.strip, input.split(cls.delimiter)) raise errors.ParseError("Cannot parse strings from non-string.")
def parse(cls, input): try: q = utils.units.parse(input) except ValueError: raise errors.ParseError("Invalid quantity.") return q
def parse(cls, input): try: return utils.time.dhms_to_seconds(input) except ValueError: raise errors.ParseError("Invalid DHMS value. Example: 1d5h30m")