本文整理汇总了Python中cssypy.parsers.Parser.selector方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.selector方法的具体用法?Python Parser.selector怎么用?Python Parser.selector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cssypy.parsers.Parser
的用法示例。
在下文中一共展示了Parser.selector方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unnested_combine_ancestor_selector
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_unnested_combine_ancestor_selector(self):
src = u'a &'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
with self.assertRaises(errors.CSSSyntaxError) as cm:
parser.selector()
self.assertEqual("The '&' selector is only allowed within nested ruleset scopes.",
cm.exception.msg)
示例2: test_class_selector
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_class_selector(self):
src = u'.myclass'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
sel = parser.selector()
expected = \
Selector(
children=[
SimpleSelectorSequence(
head=None,
tail=[ClassSelector(name=u'myclass')]
),
]
)
self.assertEqual(dump(expected), dump(sel))
示例3: test_type_selector
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_type_selector(self):
src = u'div'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
sel = parser.selector()
expected = \
Selector(
children=[
SimpleSelectorSequence(
head=TypeSelector(name=u'div'),
tail=[]
),
]
)
self.assertEqual(dump(expected), dump(sel))
示例4: test_negation_selector
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_negation_selector(self):
src = u'a:not( #myid )'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
sel = parser.selector()
expected = \
Selector(
children=[
SimpleSelectorSequence(
head=TypeSelector(name=u'a'),
tail=[
NegationSelector(
arg=IdSelector(name=u'myid')
),
]
)
]
)
self.assertEqual(dump(expected), dump(sel))
示例5: test_pseudo_element_selector2
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_pseudo_element_selector2(self):
src = u'a::foo'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
sel = parser.selector()
expected = \
Selector(
children=[
SimpleSelectorSequence(
head=TypeSelector(name=u'a'),
tail=[
PseudoElementSelector(
node=Ident(name=u'foo')
),
]
)
]
)
self.assertEqual(dump(expected), dump(sel))
示例6: test_child_combinator
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_child_combinator(self):
src = u'a > b'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
sel = parser.selector()
expected = \
Selector(
children=[
SimpleSelectorSequence(
head=TypeSelector(name=u'a'),
tail=[]
),
ChildCombinator(),
SimpleSelectorSequence(
head=TypeSelector(name=u'b'),
tail=[]
),
]
)
self.assertEqual(dump(expected), dump(sel))
示例7: test_whitespace_combinator2
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_whitespace_combinator2(self):
src = u'a.myclass b#myid'
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
sel = parser.selector()
expected = \
Selector(
children=[
SimpleSelectorSequence(
head=TypeSelector(name=u'a'),
tail=[ClassSelector(name=u'myclass')]
),
DescendantCombinator(),
SimpleSelectorSequence(
head=TypeSelector(name=u'b'),
tail=[IdSelector(name=u'myid')]
),
]
)
self.assertEqual(dump(expected), dump(sel))
示例8: test_bad_class_selector
# 需要导入模块: from cssypy.parsers import Parser [as 别名]
# 或者: from cssypy.parsers.Parser import selector [as 别名]
def test_bad_class_selector(self):
src = u'."this is a string" '
parser = Parser(src)
self.assertTrue(parser.match(tokens.START))
with self.assertRaises(errors.CSSSyntaxError):
parser.selector()