Update after review.
This commit is contained in:
parent
f11e9e6ece
commit
e82ca278c4
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,4 +9,3 @@ dist
|
|||||||
MANIFEST
|
MANIFEST
|
||||||
.tox
|
.tox
|
||||||
.venv*
|
.venv*
|
||||||
*.egg-info/
|
|
||||||
|
@ -77,23 +77,32 @@ class LessParser(object):
|
|||||||
self.result = None
|
self.result = None
|
||||||
self.target = None
|
self.target = None
|
||||||
|
|
||||||
def parse(self, filename='', filestream=None, debuglevel=0):
|
def parse(self, filename=None, file=None, debuglevel=0):
|
||||||
""" Parse file.
|
""" Parse file.
|
||||||
kwargs:
|
kwargs:
|
||||||
filename (str): File to parse
|
filename (str): File to parse
|
||||||
debuglevel (int): Parser debuglevel
|
debuglevel (int): Parser debuglevel
|
||||||
"""
|
"""
|
||||||
|
self.scope.push()
|
||||||
|
|
||||||
|
if not file:
|
||||||
|
# We use a path.
|
||||||
|
file = filename
|
||||||
|
else:
|
||||||
|
# We use a stream and try to extract the name from the stream.
|
||||||
|
if hasattr(file, 'name'):
|
||||||
|
if filename is not None:
|
||||||
|
raise AssertionError(
|
||||||
|
'names of file and filename are in conflict')
|
||||||
|
filename = file.name()
|
||||||
|
else:
|
||||||
|
filename = '(stream)'
|
||||||
|
|
||||||
|
self.target = filename
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print('Compiling target: %s' % filename, file=sys.stderr)
|
print('Compiling target: %s' % filename, file=sys.stderr)
|
||||||
self.scope.push()
|
|
||||||
self.target = filename
|
|
||||||
if filestream:
|
|
||||||
content = filestream
|
|
||||||
else:
|
|
||||||
content = filename
|
|
||||||
|
|
||||||
self.result = self.parser.parse(
|
self.result = self.parser.parse(
|
||||||
content, lexer=self.lex, debug=debuglevel)
|
file, lexer=self.lex, debug=debuglevel)
|
||||||
|
|
||||||
self.post_parse()
|
self.post_parse()
|
||||||
|
|
||||||
|
@ -24,10 +24,12 @@ class TestLessParser(unittest.TestCase):
|
|||||||
@nice-blue: #5B83AD;
|
@nice-blue: #5B83AD;
|
||||||
""")
|
""")
|
||||||
|
|
||||||
self.parser.parse(filestream=stream)
|
self.parser.parse(file=stream)
|
||||||
|
|
||||||
# A single object is parser which is the expected variable.
|
# A single object is parser which is the expected variable.
|
||||||
self.assertEqual(1, len(self.parser.result))
|
self.assertEqual(1, len(self.parser.result))
|
||||||
|
# This is a stream without a name so it sets default name.
|
||||||
|
self.assertEqual('(stream)', self.parser.target)
|
||||||
variable = self.parser.result[0]
|
variable = self.parser.result[0]
|
||||||
self.assertEqual('@nice-blue', variable.name)
|
self.assertEqual('@nice-blue', variable.name)
|
||||||
self.assertEqual(['#5b83ad'], variable.value)
|
self.assertEqual(['#5b83ad'], variable.value)
|
||||||
|
Loading…
Reference in New Issue
Block a user