Codebase list python-csscompressor / 999ba57
Merge tag '0.9.5' into debian/victoria v0.9.5 Thomas Goirand 3 years ago
5 changed file(s) with 33 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
33 - linux
44
55 python:
6 - 2.6
76 - 2.7
87 - 3.3
98 - 3.4
109 - 3.5
10 - 3.6
1111
1212 script:
1313 - py.test
2828 Compatibility
2929 =============
3030
31 Tested under Python 2.6, 2.7 and 3.3
31 Tested under Python 2.7 and 3.3+
3232
3333
3434 Installation
112112 max_idx = len(css) - 1
113113 append_idx = 0
114114 sb = []
115 nest_term = None
115116
116117 for match in regexp.finditer(css):
117118 name = match.group(1)
120121 term = match.group(2) if match.lastindex > 1 else None
121122 if not term:
122123 term = ')'
124 nest_term = '('
123125
124126 found_term = False
125127 end_idx = match.end(0) - 1
128 nest_idx = end_idx if nest_term else 0
129 nested = False
126130 while not found_term and (end_idx + 1) <= max_idx:
131 if nest_term:
132 nest_idx = css.find(nest_term, nest_idx + 1)
127133 end_idx = css.find(term, end_idx + 1)
128134
129135 if end_idx > 0:
136 if nest_idx > 0 and nest_idx < end_idx and \
137 css[nest_idx - 1] != '\\':
138 nested = True
139
130140 if css[end_idx - 1] != '\\':
131 found_term = True
132 if term != ')':
133 end_idx = css.find(')', end_idx)
141 if nested:
142 nested = False
143 else:
144 found_term = True
145 if term != ')':
146 end_idx = css.find(')', end_idx)
134147 else:
135148 raise ValueError('malformed css')
136149
138151
139152 assert found_term
140153
141 token = css[start_idx:end_idx]
154 token = css[start_idx:end_idx].strip()
142155
143156 if remove_ws:
144157 token = _ws_re.sub('', token)
5151 a {content: calc(10px-10%}
5252 '''
5353 self.assertRaises(ValueError, compress, input)
54
55 def test_nested_1(self):
56 input = '''
57 a { width: calc( (10vh - 100px) / 4 + 30px ) }
58 '''
59 output = compress(input)
60 assert output == "a{width:calc((10vh - 100px) / 4 + 30px)}"
61
62 def test_nested_2(self):
63 input = '''
64 a { width: calc( ((10vh - 100px) / 4 + 30px ) }
65 '''
66 self.assertRaises(ValueError, compress, input)
1717
1818 setup(
1919 name='csscompressor',
20 version='0.9.4',
20 version='0.9.5',
2121 url='http://github.com/sprymix/csscompressor',
2222 license='BSD',
2323 author='Yury Selivanov',