Пример #1
0
 def _parse_isd_str(self, raw):
     try:
         self._isd = int(raw)
     except ValueError:
         raise SCIONParseError("Unable to parse ISD from string: %s" %
                               raw) from None
     if self._isd > self.MAX_ISD:
         raise SCIONParseError("ISD too large (max: %d): %s" %
                               (self.MAX_ISD, raw))
Пример #2
0
 def _parse_dec_as(self, raw):
     try:
         self._as = int(raw, base=10)
     except ValueError:
         raise SCIONParseError(
             "Unable to parse decimal AS from string: %s" % raw) from None
     if self._as > self.MAX_BGP_AS:
         raise SCIONParseError("Decimal AS too large (max: %d): %s" %
                               (self.MAX_BGP_AS, raw))
Пример #3
0
 def _parse_hex_as(self, raw, as_sep=HEX_SEPARATOR):
     try:
         as_parts = raw.split(as_sep)
     except ValueError:
         raise SCIONParseError("Unable to parse hex AS from string: %s" %
                               raw) from None
     if len(as_parts) != self.HEX_AS_PARTS:
         raise SCIONParseError(
             "Wrong number of separators (%s) in hex AS number (expected: %d actual: %s): %s"
             % (self.HEX_SEPARATOR, self.HEX_AS_PARTS, as_parts, raw))
     self._as = 0
     for i, s in enumerate(as_parts):
         self._as <<= 16
         v = int(s, base=16)
         if v > self.MAX_HEX_AS_PART:
             raise SCIONParseError(
                 "Hex AS number has part greater than %x: %s" %
                 (self.MAX_HEX_AS_PART, raw))
         self._as |= v
     if self._as > self.MAX_AS:
         raise SCIONParseError("AS too large (max: %d): %s" %
                               (self.MAX_AS, raw))
Пример #4
0
 def _parse(self, raw):
     """
     :param str raw: a string of the format "isd-as".
     """
     parts = raw.split("-")
     if len(parts) != 2:
         raise SCIONParseError("Unable to split ISD-AS in string: %s" % raw)
     isd_s, as_s = parts
     self._parse_isd_str(isd_s)
     for as_sep in [self.HEX_SEPARATOR, self.HEX_FILE_SEPARATOR]:
         if as_sep in as_s:
             self._parse_hex_as(as_s, as_sep)
             break
     else:
         self._parse_dec_as(as_s)