示例#1
0
 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])
     )
示例#2
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
示例#3
0
 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)
示例#4
0
 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
示例#5
0
 def parse(cls, input):
     try:
         return ictime.parse_user_duration(input)
     except ValueError:
         raise errors.ParseError("Invalid duration.")
示例#6
0
 def parse(cls, input):
     try:
         return super(ICDateStaticParser, cls).parse(input).date
     except errors.ParseError:
         raise errors.ParseError("Invalid date.")
示例#7
0
 def parse(cls, input):
     try:
         return ictime.parse_user_datetime(input)
     except ValueError:
         raise errors.ParseError("Invalid timestamp.")
示例#8
0
 def parse_ip(ipstr):
     if re.match(r'[.*0-9]+', ipstr):
         return ipstr
     else:
         raise errors.ParseError('Invalid IP pattern: %s' % ipstr)
示例#9
0
 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.")
示例#10
0
 def parse(cls, input):
     try:
         q = utils.units.parse(input)
     except ValueError:
         raise errors.ParseError("Invalid quantity.")
     return q
示例#11
0
 def parse(cls, input):
     try:
         return utils.time.dhms_to_seconds(input)
     except ValueError:
         raise errors.ParseError("Invalid DHMS value. Example: 1d5h30m")