Exemple #1
0
 def test_DateTime2StringCompact(self):
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22, 123456)
     self.assertEqual(utils.DateTime2String(dt, True),
                      "2008,358,01:30:22.1234")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22)
     self.assertEqual(utils.DateTime2String(dt, True), "2008,358,01:30:22")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30)
     self.assertEqual(utils.DateTime2String(dt, True), "2008,358,01:30")
     dt = UTCDateTime(2008, 12, 23, 0o1)
     self.assertEqual(utils.DateTime2String(dt, True), "2008,358,01")
     dt = UTCDateTime(2008, 12, 23)
     self.assertEqual(utils.DateTime2String(dt, True), "2008,358")
Exemple #2
0
 def test_DateTime2String(self):
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22, 123456)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:30:22.1234")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22, 98765)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:30:22.0987")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22, 1234)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:30:22.0012")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22, 123)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:30:22.0001")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 22, 9)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:30:22.0000")
     dt = UTCDateTime(2008, 12, 23, 0o1, 30, 21)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:30:21.0000")
     dt = UTCDateTime(2008, 12, 23, 0o1, 0, 0, 0)
     self.assertEqual(utils.DateTime2String(dt), "2008,358,01:00:00.0000")
     dt = UTCDateTime(2008, 12, 23)
     self.assertEqual(utils.DateTime2String(dt), "2008,358")
Exemple #3
0
    def _formatString(self, s):
        """
        Using SEED specific flags to format strings.

        This method is partly adopted from fseed.py, the SEED builder for
        SeisComP written by Andres Heinloo, GFZ Potsdam in 2005.
        """
        if isinstance(s, bytes):
            sn = s.decode('utf-8').strip()
        else:
            sn = str(s).strip()
        if self.flags and 'T' in self.flags:
            if not sn and self.default_value:
                return self.default_value
            return utils.DateTime2String(sn, self.compact)
        if not self.flags:
            return sn
        rx_list = []
        if 'U' in self.flags:
            rx_list.append("[A-Z]")
        if 'L' in self.flags:
            rx_list.append("[a-z]")
        if 'N' in self.flags:
            rx_list.append("[0-9]")
        if 'P' in self.flags:
            rx_list.append("[^A-Za-z0-9 ]")
        if 'S' in self.flags:
            rx_list.append(" ")
        if '_' in self.flags:
            rx_list.append("_")
        if 'U' in self.flags and 'L' not in self.flags:
            sn = sn.upper()
        elif 'L' in self.flags and 'U' not in self.flags:
            sn = sn.lower()
        if 'S' in self.flags and 'X' not in self.flags:
            sn = sn.replace("_", " ")
        elif 'X' in self.flags and 'S' not in self.flags:
            sn = sn.replace(" ", "_")
        rx = "|".join(rx_list)
        sn = "".join(re.findall(rx, sn))
        if re.match("(" + rx + ")*$", sn) is None:
            msg = "Can't convert string %s with flags %s" % (s, self.flags)
            raise SEEDTypeException(msg)
        return sn