def test_filter_strings(): eq_( wpi_utils.filter_strings("^INSERT", ["INSERT INTO `witch` VALUES ('使用者')", "ALTER TABLE"]).next(), "INSERT INTO `witch` VALUES ('使用者')", ) eq_(list(wpi_utils.filter_strings(r"foo", ["bar", "baz"])), []) eq_(list(wpi_utils.filter_strings(r"foo", [])), [])
def generic_pipeline(seq): """Preprocessing pipeline needed for all dump files. Steps in this pipeline: * Extract INSERT statements * Convert strings to unicode * Strip strings * Replace MySQL quotes with psql ones :param seq: Sequence of strings :type seq: Iterable """ seq = wpi_utils.filter_strings(r'^INSERT', seq) seq = wpi_utils.convert_multirow_to_unicode(seq) seq = (el.strip() for el in seq) seq = psql_quotation(seq) return seq