Merge pull request #113 from Ede123/pep8

Reformat code according to PEP 8
This commit is contained in:
Eduard Braun 2016-09-15 23:05:10 +02:00 committed by GitHub
commit fb9ffb3dbd
9 changed files with 5040 additions and 4443 deletions

View file

@ -23,3 +23,6 @@ test_error_on_flowtext:
PYTHONPATH=. scour --error-on-flowtext unittests/flowtext-less.svg /dev/null PYTHONPATH=. scour --error-on-flowtext unittests/flowtext-less.svg /dev/null
# .. and this should bail out! # .. and this should bail out!
PYTHONPATH=. scour --error-on-flowtext unittests/flowtext.svg /dev/null PYTHONPATH=. scour --error-on-flowtext unittests/flowtext.svg /dev/null
flake8:
flake8 --max-line-length=119

View file

@ -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'

File diff suppressed because it is too large Load diff

View file

@ -44,11 +44,15 @@ Out[5]: [('M', [(100.0, -200.0)])]
from __future__ import absolute_import from __future__ import absolute_import
import re import re
from decimal import * from decimal import Decimal, getcontext
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 +74,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 +275,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:

View file

@ -59,13 +59,15 @@ Out[12]: [('translate', [30.0, -30.0]), ('rotate', [36.0])]
from __future__ import absolute_import from __future__ import absolute_import
import re import re
from decimal import * from decimal import Decimal
from six.moves import range
from functools import partial from functools import partial
from six.moves import range
# Sentinel. # Sentinel.
class _EOF(object): class _EOF(object):
def __repr__(self): def __repr__(self):
return 'EOF' return 'EOF'
EOF = _EOF() EOF = _EOF()
@ -89,6 +91,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 = []

View file

@ -48,6 +48,7 @@
# | 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
@ -55,17 +56,20 @@ def parseCssString(str):
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:
continue
rule = {} rule = {}
rule['selector'] = bits[0].strip() rule['selector'] = bits[0].strip()
# third, split on ; to get the property declarations # third, split on ; to get the property declarations
bites = bits[1].strip().split(';') bites = bits[1].strip().split(';')
if len(bites) < 1: continue if len(bites) < 1:
continue
props = {} props = {}
for bite in bites: for bite in bites:
# fourth, split on : to get the property name and value # fourth, split on : to get the property name and value
nibbles = bite.strip().split(':') nibbles = bite.strip().split(':')
if len(nibbles) != 2: continue if len(nibbles) != 2:
continue
props[nibbles[0].strip()] = nibbles[1].strip() props[nibbles[0].strip()] = nibbles[1].strip()
rule['properties'] = props rule['properties'] = props
rules.append(rule) rules.append(rule)

View file

@ -1,24 +1,25 @@
############################################################################### ###############################################################################
## #
## 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
import re import re
from setuptools import setup, find_packages
from setuptools import find_packages, setup
LONGDESC = """ LONGDESC = """
Scour is a SVG optimizer/sanitizer that can be used to produce SVGs for Web deployment. Scour is a SVG optimizer/sanitizer that can be used to produce SVGs for Web deployment.

View file

@ -27,19 +27,24 @@ from scour.yocto_css import parseCssString
class Blank(unittest.TestCase): class Blank(unittest.TestCase):
def runTest(self): def runTest(self):
r = parseCssString('') r = parseCssString('')
self.assertEqual(len(r), 0, 'Blank string returned non-empty list') self.assertEqual(len(r), 0, 'Blank string returned non-empty list')
self.assertEqual(type(r), type([]), 'Blank string returned non list') self.assertEqual(type(r), type([]), 'Blank string returned non list')
class ElementSelector(unittest.TestCase): class ElementSelector(unittest.TestCase):
def runTest(self): def runTest(self):
r = parseCssString('foo {}') r = parseCssString('foo {}')
self.assertEqual(len(r), 1, 'Element selector not returned') self.assertEqual(len(r), 1, 'Element selector not returned')
self.assertEqual(r[0]['selector'], 'foo', 'Selector for foo not returned') self.assertEqual(r[0]['selector'], 'foo', 'Selector for foo not returned')
self.assertEqual(len(r[0]['properties']), 0, 'Property list for foo not empty') self.assertEqual(len(r[0]['properties']), 0, 'Property list for foo not empty')
class ElementSelectorWithProperty(unittest.TestCase): class ElementSelectorWithProperty(unittest.TestCase):
def runTest(self): def runTest(self):
r = parseCssString('foo { bar: baz}') r = parseCssString('foo { bar: baz}')
self.assertEqual(len(r), 1, 'Element selector not returned') self.assertEqual(len(r), 1, 'Element selector not returned')

File diff suppressed because it is too large Load diff