コード例 #1
0
ファイル: str_tools.py プロジェクト: Foxboron/stem
    def test_parse_iso_timestamp(self):
        """
    Checks the _parse_iso_timestamp() function.
    """

        test_inputs = {
            '2012-11-08T16:48:41.420251':
            datetime.datetime(2012, 11, 8, 16, 48, 41, 420251),
            '2012-11-08T16:48:41.000000':
            datetime.datetime(2012, 11, 8, 16, 48, 41, 0),
            '2012-11-08T16:48:41':
            datetime.datetime(2012, 11, 8, 16, 48, 41, 0),
        }

        for arg, expected in test_inputs.items():
            self.assertEqual(expected, str_tools._parse_iso_timestamp(arg))

        invalid_input = [
            None,
            32,
            'hello world',
            '2012-11-08T16:48:41.42025',  # too few microsecond digits
            '2012-11-08T16:48:41.4202511',  # too many microsecond digits
            '2012-11-08T16:48',
        ]

        for arg in invalid_input:
            self.assertRaises(ValueError, str_tools._parse_iso_timestamp, arg)
コード例 #2
0
ファイル: str_tools.py プロジェクト: patrickod/stem
  def test_parse_iso_timestamp(self):
    """
    Checks the _parse_iso_timestamp() function.
    """

    test_inputs = {
      '2012-11-08T16:48:41.420251':
        datetime.datetime(2012, 11, 8, 16, 48, 41, 420251),
      '2012-11-08T16:48:41.000000':
        datetime.datetime(2012, 11, 8, 16, 48, 41, 0),
      '2012-11-08T16:48:41':
        datetime.datetime(2012, 11, 8, 16, 48, 41, 0),
    }

    for arg, expected in test_inputs.items():
      self.assertEqual(expected, str_tools._parse_iso_timestamp(arg))

    invalid_input = [
      None,
      32,
      'hello world',
      '2012-11-08T16:48:41.42025',    # too few microsecond digits
      '2012-11-08T16:48:41.4202511',  # too many microsecond digits
      '2012-11-08T16:48',
    ]

    for arg in invalid_input:
      self.assertRaises(ValueError, str_tools._parse_iso_timestamp, arg)
コード例 #3
0
ファイル: events.py プロジェクト: ankitmodi/Projects
  def _parse(self):
    self.path = tuple(stem.control._parse_circ_path(self.path))

    if self.build_flags is not None:
      self.build_flags = tuple(self.build_flags.split(','))

    if self.created is not None:
      try:
        self.created = str_tools._parse_iso_timestamp(self.created)
      except ValueError, exc:
        raise stem.ProtocolError("Unable to parse create date (%s): %s" % (exc, self))
コード例 #4
0
ファイル: events.py プロジェクト: sreenatha123/stem
  def _parse(self):
    self.path = tuple(stem.control._parse_circ_path(self.path))

    if self.build_flags is not None:
      self.build_flags = tuple(self.build_flags.split(','))

    if self.created is not None:
      try:
        self.created = str_tools._parse_iso_timestamp(self.created)
      except ValueError, exc:
        raise stem.ProtocolError("Unable to parse create date (%s): %s" % (exc, self))
コード例 #5
0
ファイル: events.py プロジェクト: patrickod/stem
  def _parse(self):
    self.path = tuple(stem.control._parse_circ_path(self.path))

    if self.build_flags is not None:
      self.build_flags = tuple(self.build_flags.split(','))

    if self.created is not None:
      try:
        self.created = str_tools._parse_iso_timestamp(self.created)
      except ValueError as exc:
        raise stem.ProtocolError('Unable to parse create date (%s): %s' % (exc, self))

    if not tor_tools.is_valid_circuit_id(self.id):
      raise stem.ProtocolError("Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))

    self._log_if_unrecognized('event', stem.CircEvent)
    self._log_if_unrecognized('build_flags', stem.CircBuildFlag)
    self._log_if_unrecognized('purpose', stem.CircPurpose)
    self._log_if_unrecognized('hs_state', stem.HiddenServiceState)
    self._log_if_unrecognized('old_purpose', stem.CircPurpose)
    self._log_if_unrecognized('old_hs_state', stem.HiddenServiceState)
コード例 #6
0
ファイル: events.py プロジェクト: Foxboron/stem
    def _parse(self):
        self.path = tuple(stem.control._parse_circ_path(self.path))

        if self.build_flags is not None:
            self.build_flags = tuple(self.build_flags.split(','))

        if self.created is not None:
            try:
                self.created = str_tools._parse_iso_timestamp(self.created)
            except ValueError as exc:
                raise stem.ProtocolError(
                    'Unable to parse create date (%s): %s' % (exc, self))

        if not tor_tools.is_valid_circuit_id(self.id):
            raise stem.ProtocolError(
                "Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.id, self))

        self._log_if_unrecognized('event', stem.CircEvent)
        self._log_if_unrecognized('build_flags', stem.CircBuildFlag)
        self._log_if_unrecognized('purpose', stem.CircPurpose)
        self._log_if_unrecognized('hs_state', stem.HiddenServiceState)
        self._log_if_unrecognized('old_purpose', stem.CircPurpose)
        self._log_if_unrecognized('old_hs_state', stem.HiddenServiceState)