def test_custom_separator_with_negative_indexes(self): self.assertEqual( replace_segment('foo.bar..spam', -1, 'REPLACED', sep='..'), 'foo.bar..REPLACED') self.assertEqual( replace_segment('foo.bar..spam', -2, 'REPLACED', sep='..'), 'REPLACED..spam') with self.assertRaises(IndexError): replace_segment('foo.bar..spam', -3, 'REPLACED', sep='..')
def input_callback(self, routing_key, body, properties): data = RecordDict.from_json(body) with self.setting_error_event_info(data): enriched = self.enrich(data) rk = replace_segment(routing_key, 1, 'enriched') body = enriched.get_ready_json() self.publish_output(routing_key=rk, body=body)
def input_callback(self, routing_key: str, body: bytes, properties: pika.BasicProperties) -> None: for converted in self.converter.convert(body.decode()): rk = replace_segment(routing_key, 1, self.components_id) self.publish_output(routing_key=rk, body=converted)
def test_single_with_negative_indexes(self): self.assertEqual(replace_segment('foo', -1, 'REPLACED'), 'REPLACED') self.assertEqual(replace_segment('', -1, 'REPLACED'), 'REPLACED') with self.assertRaises(IndexError): replace_segment('foo', -2, 'REPLACED') with self.assertRaises(IndexError): replace_segment('', -2, 'REPLACED')
def publish_event(self, data, rk): """ Push the given event into the output queue. Args: `data` (RecordDict instance): The event data. `rk` (string): The *input* routing key. """ output_rk = replace_segment(rk, 1, 'filtered') body = data.get_ready_json() self.publish_output(routing_key=output_rk, body=body)
def test_with_negative_indexes(self): self.assertEqual(replace_segment('foo.bar..spam', -1, 'REPLACED'), 'foo.bar..REPLACED') self.assertEqual(replace_segment('foo.bar..spam', -2, 'REPLACED'), 'foo.bar.REPLACED.spam') self.assertEqual(replace_segment('foo.bar..spam', -3, 'REPLACED'), 'foo.REPLACED..spam') self.assertEqual(replace_segment('foo.bar..spam', -4, 'REPLACED'), 'REPLACED.bar..spam') with self.assertRaises(IndexError): replace_segment('foo.bar..spam', -5, 'REPLACED')
def test_with_non_negative_indexes(self): self.assertEqual(replace_segment('foo.bar..spam', 0, 'REPLACED'), 'REPLACED.bar..spam') self.assertEqual(replace_segment('foo.bar..spam', 1, b'REPLACED'), 'foo.REPLACED..spam') self.assertEqual(replace_segment(b'foo.bar..spam', 2, 'REPLACED'), b'foo.bar.REPLACED.spam') self.assertEqual(replace_segment(b'foo.bar..spam', 3, b'REPLACED'), b'foo.bar..REPLACED') with self.assertRaises(IndexError): replace_segment('foo.bar..spam', 4, 'REPLACED')
def insert_new_event(self, items, with_transact=True, recorded=False): """ New events and new blacklist add to database, default in the transaction, or the outer transaction(with_transact=False). """ try: if with_transact: with transact: self.session_db.add_all(items) else: self.session_db.add_all(items) except IntegrityError as exc: LOGGER.warning("IntegrityError %r", exc) else: if recorded and not self.cmdline_args.n6recovery: rk = replace_segment(self.routing_key, 1, 'recorded') LOGGER.debug( 'Publish for email notifications ' '-- rk: %r, record_dict: %r', rk, self.record_dict) self.publish_event(self.record_dict, rk)