Consistent whitespace across source files according to PEP 8
(mostly automated by using autopep8, fixes #69)
This commit is contained in:
parent
943319b710
commit
0f1974c1e2
8 changed files with 4787 additions and 4276 deletions
|
|
@ -1,19 +1,19 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
##
|
#
|
||||||
## Copyright (C) 2010 Jeff Schiller, 2010 Louis Simard, 2013-2015 Tavendo GmbH
|
# Copyright (C) 2010 Jeff Schiller, 2010 Louis Simard, 2013-2015 Tavendo GmbH
|
||||||
##
|
#
|
||||||
## Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
## you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
## You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
##
|
#
|
||||||
## http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
##
|
#
|
||||||
## Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
## See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
## limitations under the License.
|
# limitations under the License.
|
||||||
##
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
__version__ = u'0.35'
|
__version__ = u'0.35'
|
||||||
|
|
|
||||||
6191
scour/scour.py
6191
scour/scour.py
File diff suppressed because it is too large
Load diff
|
|
@ -48,7 +48,10 @@ from decimal import *
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
# Sentinel.
|
# Sentinel.
|
||||||
|
|
||||||
|
|
||||||
class _EOF(object):
|
class _EOF(object):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'EOF'
|
return 'EOF'
|
||||||
EOF = _EOF()
|
EOF = _EOF()
|
||||||
|
|
@ -70,6 +73,7 @@ class Lexer(object):
|
||||||
|
|
||||||
http://www.gooli.org/blog/a-simple-lexer-in-python/
|
http://www.gooli.org/blog/a-simple-lexer-in-python/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, lexicon):
|
def __init__(self, lexicon):
|
||||||
self.lexicon = lexicon
|
self.lexicon = lexicon
|
||||||
parts = []
|
parts = []
|
||||||
|
|
@ -270,7 +274,6 @@ class SVGPathParser(object):
|
||||||
token = next_val_fn()
|
token = next_val_fn()
|
||||||
return x, token
|
return x, token
|
||||||
|
|
||||||
|
|
||||||
def rule_coordinate_pair(self, next_val_fn, token):
|
def rule_coordinate_pair(self, next_val_fn, token):
|
||||||
# Inline these since this rule is so common.
|
# Inline these since this rule is so common.
|
||||||
if token[0] not in self.number_tokens:
|
if token[0] not in self.number_tokens:
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ from functools import partial
|
||||||
|
|
||||||
# Sentinel.
|
# Sentinel.
|
||||||
class _EOF(object):
|
class _EOF(object):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'EOF'
|
return 'EOF'
|
||||||
EOF = _EOF()
|
EOF = _EOF()
|
||||||
|
|
@ -89,6 +90,7 @@ class Lexer(object):
|
||||||
|
|
||||||
http://www.gooli.org/blog/a-simple-lexer-in-python/
|
http://www.gooli.org/blog/a-simple-lexer-in-python/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, lexicon):
|
def __init__(self, lexicon):
|
||||||
self.lexicon = lexicon
|
self.lexicon = lexicon
|
||||||
parts = []
|
parts = []
|
||||||
|
|
@ -154,8 +156,8 @@ class SVGTransformationParser(object):
|
||||||
commands = []
|
commands = []
|
||||||
token = next_val_fn()
|
token = next_val_fn()
|
||||||
while token[0] is not EOF:
|
while token[0] is not EOF:
|
||||||
command, token = self.rule_svg_transform(next_val_fn, token)
|
command, token = self.rule_svg_transform(next_val_fn, token)
|
||||||
commands.append(command)
|
commands.append(command)
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
def rule_svg_transform(self, next_val_fn, token):
|
def rule_svg_transform(self, next_val_fn, token):
|
||||||
|
|
|
||||||
|
|
@ -48,25 +48,29 @@
|
||||||
# | DASHMATCH | FUNCTION S* any* ')'
|
# | DASHMATCH | FUNCTION S* any* ')'
|
||||||
# | '(' S* any* ')' | '[' S* any* ']' ] S*;
|
# | '(' S* any* ')' | '[' S* any* ']' ] S*;
|
||||||
|
|
||||||
|
|
||||||
def parseCssString(str):
|
def parseCssString(str):
|
||||||
rules = []
|
rules = []
|
||||||
# first, split on } to get the rule chunks
|
# first, split on } to get the rule chunks
|
||||||
chunks = str.split('}')
|
chunks = str.split('}')
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
# second, split on { to get the selector and the list of properties
|
# second, split on { to get the selector and the list of properties
|
||||||
bits = chunk.split('{')
|
bits = chunk.split('{')
|
||||||
if len(bits) != 2: continue
|
if len(bits) != 2:
|
||||||
rule = {}
|
continue
|
||||||
rule['selector'] = bits[0].strip()
|
rule = {}
|
||||||
# third, split on ; to get the property declarations
|
rule['selector'] = bits[0].strip()
|
||||||
bites = bits[1].strip().split(';')
|
# third, split on ; to get the property declarations
|
||||||
if len(bites) < 1: continue
|
bites = bits[1].strip().split(';')
|
||||||
props = {}
|
if len(bites) < 1:
|
||||||
for bite in bites:
|
continue
|
||||||
# fourth, split on : to get the property name and value
|
props = {}
|
||||||
nibbles = bite.strip().split(':')
|
for bite in bites:
|
||||||
if len(nibbles) != 2: continue
|
# fourth, split on : to get the property name and value
|
||||||
props[nibbles[0].strip()] = nibbles[1].strip()
|
nibbles = bite.strip().split(':')
|
||||||
rule['properties'] = props
|
if len(nibbles) != 2:
|
||||||
rules.append(rule)
|
continue
|
||||||
return rules
|
props[nibbles[0].strip()] = nibbles[1].strip()
|
||||||
|
rule['properties'] = props
|
||||||
|
rules.append(rule)
|
||||||
|
return rules
|
||||||
|
|
|
||||||
92
setup.py
92
setup.py
|
|
@ -1,19 +1,19 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
##
|
#
|
||||||
## Copyright (C) 2013-2014 Tavendo GmbH
|
# Copyright (C) 2013-2014 Tavendo GmbH
|
||||||
##
|
#
|
||||||
## Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
## you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
## You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
##
|
#
|
||||||
## http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
##
|
#
|
||||||
## Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
## See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
## limitations under the License.
|
# limitations under the License.
|
||||||
##
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
@ -42,35 +42,35 @@ else:
|
||||||
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
|
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
|
||||||
|
|
||||||
|
|
||||||
setup (
|
setup(
|
||||||
name = 'scour',
|
name='scour',
|
||||||
version = verstr,
|
version=verstr,
|
||||||
description = 'Scour SVG Optimizer',
|
description='Scour SVG Optimizer',
|
||||||
# long_description = open("README.md").read(),
|
# long_description = open("README.md").read(),
|
||||||
long_description = LONGDESC,
|
long_description=LONGDESC,
|
||||||
license = 'Apache License 2.0',
|
license='Apache License 2.0',
|
||||||
author = 'Jeff Schiller',
|
author='Jeff Schiller',
|
||||||
author_email = 'codedread@gmail.com',
|
author_email='codedread@gmail.com',
|
||||||
url = 'https://github.com/codedread/scour',
|
url='https://github.com/codedread/scour',
|
||||||
platforms = ('Any'),
|
platforms=('Any'),
|
||||||
install_requires = ['six>=1.9.0'],
|
install_requires=['six>=1.9.0'],
|
||||||
packages = find_packages(),
|
packages=find_packages(),
|
||||||
zip_safe = True,
|
zip_safe=True,
|
||||||
entry_points = {
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'scour = scour.scour:run'
|
'scour = scour.scour:run'
|
||||||
]},
|
]},
|
||||||
classifiers = ["License :: OSI Approved :: Apache Software License",
|
classifiers=["License :: OSI Approved :: Apache Software License",
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 5 - Production/Stable",
|
||||||
"Environment :: Console",
|
"Environment :: Console",
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"Intended Audience :: System Administrators",
|
"Intended Audience :: System Administrators",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
"Programming Language :: Python",
|
"Programming Language :: Python",
|
||||||
"Topic :: Internet",
|
"Topic :: Internet",
|
||||||
"Topic :: Software Development :: Build Tools",
|
"Topic :: Software Development :: Build Tools",
|
||||||
"Topic :: Software Development :: Pre-processors",
|
"Topic :: Software Development :: Pre-processors",
|
||||||
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
||||||
"Topic :: Utilities"],
|
"Topic :: Utilities"],
|
||||||
keywords = 'svg optimizer'
|
keywords='svg optimizer'
|
||||||
)
|
)
|
||||||
|
|
|
||||||
35
testcss.py
35
testcss.py
|
|
@ -27,25 +27,30 @@ from scour.yocto_css import parseCssString
|
||||||
|
|
||||||
|
|
||||||
class Blank(unittest.TestCase):
|
class Blank(unittest.TestCase):
|
||||||
def runTest(self):
|
|
||||||
r = parseCssString('')
|
def runTest(self):
|
||||||
self.assertEqual( len(r), 0, 'Blank string returned non-empty list')
|
r = parseCssString('')
|
||||||
self.assertEqual( type(r), type([]), 'Blank string returned non list')
|
self.assertEqual(len(r), 0, 'Blank string returned non-empty list')
|
||||||
|
self.assertEqual(type(r), type([]), 'Blank string returned non list')
|
||||||
|
|
||||||
|
|
||||||
class ElementSelector(unittest.TestCase):
|
class ElementSelector(unittest.TestCase):
|
||||||
def runTest(self):
|
|
||||||
r = parseCssString('foo {}')
|
def runTest(self):
|
||||||
self.assertEqual( len(r), 1, 'Element selector not returned')
|
r = parseCssString('foo {}')
|
||||||
self.assertEqual( r[0]['selector'], 'foo', 'Selector for foo not returned')
|
self.assertEqual(len(r), 1, 'Element selector not returned')
|
||||||
self.assertEqual( len(r[0]['properties']), 0, 'Property list for foo not empty')
|
self.assertEqual(r[0]['selector'], 'foo', 'Selector for foo not returned')
|
||||||
|
self.assertEqual(len(r[0]['properties']), 0, 'Property list for foo not empty')
|
||||||
|
|
||||||
|
|
||||||
class ElementSelectorWithProperty(unittest.TestCase):
|
class ElementSelectorWithProperty(unittest.TestCase):
|
||||||
def runTest(self):
|
|
||||||
r = parseCssString('foo { bar: baz}')
|
def runTest(self):
|
||||||
self.assertEqual( len(r), 1, 'Element selector not returned')
|
r = parseCssString('foo { bar: baz}')
|
||||||
self.assertEqual( r[0]['selector'], 'foo', 'Selector for foo not returned')
|
self.assertEqual(len(r), 1, 'Element selector not returned')
|
||||||
self.assertEqual( len(r[0]['properties']), 1, 'Property list for foo did not have 1')
|
self.assertEqual(r[0]['selector'], 'foo', 'Selector for foo not returned')
|
||||||
self.assertEqual( r[0]['properties']['bar'], 'baz', 'Property bar did not have baz value')
|
self.assertEqual(len(r[0]['properties']), 1, 'Property list for foo did not have 1')
|
||||||
|
self.assertEqual(r[0]['properties']['bar'], 'baz', 'Property bar did not have baz value')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
2658
testscour.py
2658
testscour.py
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue