Esempio n. 1
0
def entity_matcher(query: str) -> Callable[['DXFEntity'], bool]:
    query_args = EntityQueryParser.parseString(query, parseAll=True)
    entity_matcher_ = build_entity_name_matcher(query_args.EntityQuery)
    attrib_matcher = build_entity_attributes_matcher(query_args.AttribQuery, query_args.AttribQueryOptions)

    def matcher(entity: 'DXFEntity') -> bool:
        return entity_matcher_(entity) and attrib_matcher(entity)

    return matcher
Esempio n. 2
0
def entity_matcher(query):
    query_args = EntityQueryParser.parseString(query, parseAll=True)
    entity_matcher_ = build_entity_name_matcher(query_args.EntityQuery)
    attrib_matcher = build_entity_attributes_matcher(query_args.AttribQuery, query_args.AttribQueryOptions)

    def matcher(entity):
        return entity_matcher_(entity) and attrib_matcher(entity)

    return matcher
Esempio n. 3
0
 def test_single_quoted_attributes(self):
     result = EntityQueryParser.parseString("LINE[layer=='0']", parseAll=True)
     self.assertEqual("LINE", result.EntityQuery[0])
     self.assertEqual(('layer', '==', '0'), tuple(result.AttribQuery))
Esempio n. 4
0
 def test_star_wildcard(self):
     result = EntityQueryParser.parseString("*", parseAll=True)
     name = result.EntityQuery[0]
     self.assertEqual("*", name)
Esempio n. 5
0
 def test_empty_attribute_list_not_allowed(self):
     with self.assertRaises(ParseException):
         EntityQueryParser.parseString("LINE[]", parseAll=True)
Esempio n. 6
0
 def test_appended_ignore_case_option(self):
     result = EntityQueryParser.parseString('*[layer=="IgnoreCase"]i', parseAll=True)
     self.assertEqual("i", result.AttribQueryOptions)
Esempio n. 7
0
 def test_appended_ignore_case_option(self):
     result = EntityQueryParser.parseString('*[layer=="IgnoreCase"]i', parseAll=True)
     self.assertEqual("i", result.AttribQueryOptions)
 def test_relation_ne(self):
     result = EntityQueryParser.parseString('*[layer!="0"]', parseAll=True)
     assert ("layer", "!=", "0") == tuple(result.AttribQuery)
Esempio n. 9
0
 def test_relation_gt(self):
     result = EntityQueryParser.parseString('*[layer>="0"]', parseAll=True)
     self.assertEqual(('layer', '>=', '0'), tuple(result.AttribQuery))
Esempio n. 10
0
 def test_one_attribute(self):
     result = EntityQueryParser.parseString('LINE[layer=="0"]',
                                            parseAll=True)
     assert "LINE" == result.EntityQuery[0]
     assert ('layer', '==', '0') == tuple(result.AttribQuery)
Esempio n. 11
0
 def test_single_quoted_attributes(self):
     result = EntityQueryParser.parseString("LINE[layer=='0']",
                                            parseAll=True)
     assert "LINE" == result.EntityQuery[0]
     assert ('layer', '==', '0') == tuple(result.AttribQuery)
Esempio n. 12
0
 def test_star_wildcard_2(self):
     result = EntityQueryParser.parseString("* !LINE", parseAll=True)
     assert result.EntityQuery[0] == '*'
     assert result.EntityQuery[1] == '!LINE'
Esempio n. 13
0
 def test_star_wildcard_4(self):
     with pytest.raises(ParseException):
         EntityQueryParser.parseString("* LINE", parseAll=True)
Esempio n. 14
0
 def test_wrong_star_wildcard(self):
     with pytest.raises(ParseException):
         EntityQueryParser.parseString("LIN*", parseAll=True)
Esempio n. 15
0
 def test_two_entity_names(self):
     result = EntityQueryParser.parseString("LINE CIRCLE", parseAll=True)
     assert "LINE" == result.EntityQuery[0]
     assert "CIRCLE" == result.EntityQuery[1]
Esempio n. 16
0
 def test_regex_match(self):
     result = EntityQueryParser.parseString('*[layer?"0"]', parseAll=True)
     assert ('layer', '?', '0') == tuple(result.AttribQuery)
Esempio n. 17
0
 def test_star_with_one_attribute(self):
     result = EntityQueryParser.parseString('*[layer=="0"]', parseAll=True)
     self.assertEqual("*", result.EntityQuery[0])
     self.assertEqual(3, len(result.AttribQuery))
     self.assertEqual(('layer', '==', '0'), tuple(result.AttribQuery))
Esempio n. 18
0
 def test_attribute_name_with_underscore(self):
     result = EntityQueryParser.parseString('HATCH[solid_fill==0]',
                                            parseAll=True)
     assert "HATCH" == result.EntityQuery[0]
     assert ('solid_fill', '==', 0) == tuple(result.AttribQuery)
Esempio n. 19
0
 def test_not_regex_match(self):
     result = EntityQueryParser.parseString('*[layer!?"0"]', parseAll=True)
     self.assertEqual(('layer', '!?', '0'), tuple(result.AttribQuery))
Esempio n. 20
0
 def test_star_with_one_attribute(self):
     result = EntityQueryParser.parseString('*[layer=="0"]', parseAll=True)
     assert "*" == result.EntityQuery[0]
     assert 3 == len(result.AttribQuery)
     assert ('layer', '==', '0') == tuple(result.AttribQuery)
Esempio n. 21
0
 def test_star_with_one_attribute(self):
     result = EntityQueryParser.parseString('*[layer=="0"]', parseAll=True)
     self.assertEqual("*", result.EntityQuery[0])
     self.assertEqual(3, len(result.AttribQuery))
     self.assertEqual(('layer', '==', '0'), tuple(result.AttribQuery))
Esempio n. 22
0
 def test_relation_ge(self):
     result = EntityQueryParser.parseString('*[layer>="0"]', parseAll=True)
     assert ('layer', '>=', '0') == tuple(result.AttribQuery)
Esempio n. 23
0
 def test_not_regex_match(self):
     result = EntityQueryParser.parseString('*[layer!?"0"]', parseAll=True)
     self.assertEqual(('layer', '!?', '0'), tuple(result.AttribQuery))
Esempio n. 24
0
 def test_without_wildcards(self):
     result = EntityQueryParser.parseString("LINE", parseAll=True)
     name = result.EntityQuery[0]
     self.assertEqual("LINE", name)
Esempio n. 25
0
 def test_without_wildcards(self):
     result = EntityQueryParser.parseString("LINE", parseAll=True)
     name = result.EntityQuery[0]
     self.assertEqual("LINE", name)
Esempio n. 26
0
 def test_two_entity_names(self):
     result = EntityQueryParser.parseString("LINE CIRCLE", parseAll=True)
     self.assertEqual("LINE", result.EntityQuery[0])
     self.assertEqual("CIRCLE", result.EntityQuery[1])
Esempio n. 27
0
 def test_two_entity_names(self):
     result = EntityQueryParser.parseString("LINE CIRCLE", parseAll=True)
     self.assertEqual("LINE", result.EntityQuery[0])
     self.assertEqual("CIRCLE", result.EntityQuery[1])
Esempio n. 28
0
 def test_star_wildcard(self):
     result = EntityQueryParser.parseString("*", parseAll=True)
     name = result.EntityQuery[0]
     self.assertEqual("*", name)
Esempio n. 29
0
 def test_wrong_star_wildcard_3(self):
     with self.assertRaises(ParseException):
         EntityQueryParser.parseString("LINE *[]", parseAll=True)
Esempio n. 30
0
 def test_wrong_star_wildcard_3(self):
     with self.assertRaises(ParseException):
         EntityQueryParser.parseString("LINE *[]", parseAll=True)
Esempio n. 31
0
 def test_one_attribute(self):
     result = EntityQueryParser.parseString('LINE[layer=="0"]', parseAll=True)
     self.assertEqual("LINE", result.EntityQuery[0])
     self.assertEqual(('layer', '==', '0'), tuple(result.AttribQuery))
Esempio n. 32
0
 def test_empty_attribute_list_not_allowed(self):
     with self.assertRaises(ParseException):
         EntityQueryParser.parseString("LINE[]", parseAll=True)
Esempio n. 33
0
 def test_attribute_name_with_underscore(self):
     result = EntityQueryParser.parseString('HATCH[solid_fill==0]', parseAll=True)
     self.assertEqual("HATCH", result.EntityQuery[0])
     self.assertEqual(('solid_fill', '==', 0), tuple(result.AttribQuery))
Esempio n. 34
0
 def test_not_regex_match(self):
     result = EntityQueryParser.parseString('*[layer!?"0"]', parseAll=True)
     assert ("layer", "!?", "0") == tuple(result.AttribQuery)
Esempio n. 35
0
 def test_relation_gt(self):
     result = EntityQueryParser.parseString('*[layer>="0"]', parseAll=True)
     self.assertEqual(('layer', '>=', '0'), tuple(result.AttribQuery))
Esempio n. 36
0
 def test_attribute_name_with_underscore(self):
     result = EntityQueryParser.parseString('HATCH[solid_fill==0]', parseAll=True)
     self.assertEqual("HATCH", result.EntityQuery[0])
     self.assertEqual(('solid_fill', '==', 0), tuple(result.AttribQuery))
Esempio n. 37
0
 def test_one_attribute(self):
     result = EntityQueryParser.parseString('LINE[layer=="0"]', parseAll=True)
     self.assertEqual("LINE", result.EntityQuery[0])
     self.assertEqual(('layer', '==', '0'), tuple(result.AttribQuery))
Esempio n. 38
0
 def test_double_quoted_attributes(self):
     result = EntityQueryParser.parseString(
         'LINE[layer=="0"]', parseAll=True
     )
     assert "LINE" == result.EntityQuery[0]
     assert ("layer", "==", "0") == tuple(result.AttribQuery)