More flaking.
This commit is contained in:
@@ -2,11 +2,11 @@ from django.utils.functional import LazyObject
|
|||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
|
|
||||||
# support legacy parser module usage
|
# support legacy parser module usage
|
||||||
from compressor.parser.base import ParserBase
|
from compressor.parser.base import ParserBase # noqa
|
||||||
from compressor.parser.lxml import LxmlParser
|
from compressor.parser.lxml import LxmlParser
|
||||||
from compressor.parser.default_htmlparser import DefaultHtmlParser as HtmlParser
|
from compressor.parser.default_htmlparser import DefaultHtmlParser as HtmlParser
|
||||||
from compressor.parser.beautifulsoup import BeautifulSoupParser
|
from compressor.parser.beautifulsoup import BeautifulSoupParser # noqa
|
||||||
from compressor.parser.html5lib import Html5LibParser
|
from compressor.parser.html5lib import Html5LibParser # noqa
|
||||||
|
|
||||||
|
|
||||||
class AutoSelectParser(LazyObject):
|
class AutoSelectParser(LazyObject):
|
||||||
@@ -14,6 +14,7 @@ class AutoSelectParser(LazyObject):
|
|||||||
('lxml.html', LxmlParser), # lxml, extremely fast
|
('lxml.html', LxmlParser), # lxml, extremely fast
|
||||||
('HTMLParser', HtmlParser), # fast and part of the Python stdlib
|
('HTMLParser', HtmlParser), # fast and part of the Python stdlib
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
self._wrapped = None
|
self._wrapped = None
|
||||||
self._setup(content)
|
self._setup(content)
|
||||||
|
@@ -3,6 +3,7 @@ from django.utils.encoding import smart_unicode
|
|||||||
from compressor.exceptions import ParserError
|
from compressor.exceptions import ParserError
|
||||||
from compressor.parser import ParserBase
|
from compressor.parser import ParserBase
|
||||||
|
|
||||||
|
|
||||||
class DefaultHtmlParser(ParserBase, HTMLParser):
|
class DefaultHtmlParser(ParserBase, HTMLParser):
|
||||||
|
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
|
@@ -109,7 +109,7 @@ class CompressorMixin(object):
|
|||||||
if cache_key:
|
if cache_key:
|
||||||
cache_set(cache_key, rendered_output)
|
cache_set(cache_key, rendered_output)
|
||||||
return rendered_output
|
return rendered_output
|
||||||
except Exception, e:
|
except Exception:
|
||||||
if settings.DEBUG or forced:
|
if settings.DEBUG or forced:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ from __future__ import with_statement
|
|||||||
import optparse
|
import optparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
p = optparse.OptionParser()
|
p = optparse.OptionParser()
|
||||||
p.add_option('-f', '--file', action="store",
|
p.add_option('-f', '--file', action="store",
|
||||||
|
@@ -168,7 +168,7 @@ class CssMediaTestCase(TestCase):
|
|||||||
<link rel="stylesheet" href="/media/css/two.css" type="text/css" media="screen">
|
<link rel="stylesheet" href="/media/css/two.css" type="text/css" media="screen">
|
||||||
<style type="text/foobar" media="screen">h1 { border:5px solid green;}</style>"""
|
<style type="text/foobar" media="screen">h1 { border:5px solid green;}</style>"""
|
||||||
css_node = CssCompressor(css)
|
css_node = CssCompressor(css)
|
||||||
output = BeautifulSoup(css_node.output()).findAll(['link','style'])
|
output = BeautifulSoup(css_node.output()).findAll(['link', 'style'])
|
||||||
self.assertEqual([u'/media/css/one.css', u'/media/css/two.css', None],
|
self.assertEqual([u'/media/css/one.css', u'/media/css/two.css', None],
|
||||||
[l.get('href', None) for l in output])
|
[l.get('href', None) for l in output])
|
||||||
self.assertEqual([u'screen', u'screen', u'screen'],
|
self.assertEqual([u'screen', u'screen', u'screen'],
|
||||||
|
@@ -117,7 +117,8 @@ class OfflineGenerationStaticTemplateTagTestCase(OfflineTestCaseMixin, TestCase)
|
|||||||
expected_hash = "dfa2bb387fa8"
|
expected_hash = "dfa2bb387fa8"
|
||||||
# This test uses {% static %} which was introduced in django 1.4
|
# This test uses {% static %} which was introduced in django 1.4
|
||||||
OfflineGenerationStaticTemplateTagTestCase = skipIf(
|
OfflineGenerationStaticTemplateTagTestCase = skipIf(
|
||||||
django.VERSION[1] < 4, 'Django 1.4 not found') (OfflineGenerationStaticTemplateTagTestCase)
|
django.VERSION[1] < 4, 'Django 1.4 not found'
|
||||||
|
)(OfflineGenerationStaticTemplateTagTestCase)
|
||||||
|
|
||||||
|
|
||||||
class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase):
|
class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase):
|
||||||
|
@@ -84,4 +84,3 @@ BeautifulSoupParserTests = skipIf(
|
|||||||
|
|
||||||
class HtmlParserTests(ParserTestCase, CompressorTestCase):
|
class HtmlParserTests(ParserTestCase, CompressorTestCase):
|
||||||
parser_cls = 'compressor.parser.HtmlParser'
|
parser_cls = 'compressor.parser.HtmlParser'
|
||||||
|
|
||||||
|
@@ -59,6 +59,7 @@ class PostCompressSignalTestCase(TestCase):
|
|||||||
<style type="text/css" media="print">p { border:5px solid green;}</style>
|
<style type="text/css" media="print">p { border:5px solid green;}</style>
|
||||||
<link rel="stylesheet" href="/media/css/two.css" type="text/css" />"""
|
<link rel="stylesheet" href="/media/css/two.css" type="text/css" />"""
|
||||||
css_node = CssCompressor(css)
|
css_node = CssCompressor(css)
|
||||||
|
|
||||||
def listener(sender, **kwargs):
|
def listener(sender, **kwargs):
|
||||||
pass
|
pass
|
||||||
callback = Mock(wraps=listener)
|
callback = Mock(wraps=listener)
|
||||||
|
@@ -106,8 +106,10 @@ class TemplatetagTestCase(TestCase):
|
|||||||
<script type="text/javascript">obj.value = "value";</script>
|
<script type="text/javascript">obj.value = "value";</script>
|
||||||
{% endcompress %}
|
{% endcompress %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class MockDebugRequest(object):
|
class MockDebugRequest(object):
|
||||||
GET = {settings.COMPRESS_DEBUG_TOGGLE: 'true'}
|
GET = {settings.COMPRESS_DEBUG_TOGGLE: 'true'}
|
||||||
|
|
||||||
context = dict(self.context, request=MockDebugRequest())
|
context = dict(self.context, request=MockDebugRequest())
|
||||||
out = u"""<script src="/media/js/one.js" type="text/javascript"></script>
|
out = u"""<script src="/media/js/one.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">obj.value = "value";</script>"""
|
<script type="text/javascript">obj.value = "value";</script>"""
|
||||||
@@ -118,6 +120,7 @@ class TemplatetagTestCase(TestCase):
|
|||||||
<script type="text/javascript">obj.value = "value";</script>
|
<script type="text/javascript">obj.value = "value";</script>
|
||||||
{% endcompress %}
|
{% endcompress %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def listener(sender, **kwargs):
|
def listener(sender, **kwargs):
|
||||||
pass
|
pass
|
||||||
callback = Mock(wraps=listener)
|
callback = Mock(wraps=listener)
|
||||||
@@ -219,7 +222,7 @@ class PrecompilerTemplatetagTestCase(TestCase):
|
|||||||
out = '\n'.join([
|
out = '\n'.join([
|
||||||
script(src="/media/CACHE/js/one.95cfb869eead.js"),
|
script(src="/media/CACHE/js/one.95cfb869eead.js"),
|
||||||
script(scripttype="", src="/media/js/one.js"),
|
script(scripttype="", src="/media/js/one.js"),
|
||||||
script(src="/media/CACHE/js/one.81a2cd965815.js"),])
|
script(src="/media/CACHE/js/one.81a2cd965815.js")])
|
||||||
|
|
||||||
self.assertEqual(out, render(template, self.context))
|
self.assertEqual(out, render(template, self.context))
|
||||||
finally:
|
finally:
|
||||||
@@ -264,6 +267,7 @@ class PrecompilerTemplatetagTestCase(TestCase):
|
|||||||
finally:
|
finally:
|
||||||
settings.COMPRESS_ENABLED = self.old_enabled
|
settings.COMPRESS_ENABLED = self.old_enabled
|
||||||
|
|
||||||
|
|
||||||
def script(content="", src="", scripttype="text/javascript"):
|
def script(content="", src="", scripttype="text/javascript"):
|
||||||
"""
|
"""
|
||||||
returns a unicode text html script element.
|
returns a unicode text html script element.
|
||||||
|
@@ -70,6 +70,7 @@ def get_pathext(default_pathext=None):
|
|||||||
default_pathext = os.pathsep.join(['.COM', '.EXE', '.BAT', '.CMD'])
|
default_pathext = os.pathsep.join(['.COM', '.EXE', '.BAT', '.CMD'])
|
||||||
return os.environ.get('PATHEXT', default_pathext)
|
return os.environ.get('PATHEXT', default_pathext)
|
||||||
|
|
||||||
|
|
||||||
def find_command(cmd, paths=None, pathext=None):
|
def find_command(cmd, paths=None, pathext=None):
|
||||||
"""
|
"""
|
||||||
Searches the PATH for the given command and returns its path
|
Searches the PATH for the given command and returns its path
|
||||||
|
@@ -12,7 +12,7 @@ if INSTALLED:
|
|||||||
from django.contrib.staticfiles import finders
|
from django.contrib.staticfiles import finders
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from staticfiles import finders
|
from staticfiles import finders # noqa
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Old (pre 1.0) and incompatible version of staticfiles
|
# Old (pre 1.0) and incompatible version of staticfiles
|
||||||
INSTALLED = False
|
INSTALLED = False
|
||||||
@@ -24,4 +24,4 @@ if INSTALLED:
|
|||||||
"please add 'compressor.finders.CompressorFinder' to the "
|
"please add 'compressor.finders.CompressorFinder' to the "
|
||||||
"STATICFILES_FINDERS setting.")
|
"STATICFILES_FINDERS setting.")
|
||||||
else:
|
else:
|
||||||
finders = None
|
finders = None # noqa
|
||||||
|
@@ -8,17 +8,6 @@ Author: Florent Xicluna
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
if hasattr(str, 'partition'):
|
|
||||||
def partition(s, sep):
|
|
||||||
return s.partition(sep)
|
|
||||||
else: # Python 2.4
|
|
||||||
def partition(s, sep):
|
|
||||||
try:
|
|
||||||
left, right = s.split(sep, 1)
|
|
||||||
except ValueError:
|
|
||||||
return s, '', ''
|
|
||||||
return left, sep, right
|
|
||||||
|
|
||||||
_format_str_re = re.compile(
|
_format_str_re = re.compile(
|
||||||
r'((?<!{)(?:{{)+' # '{{'
|
r'((?<!{)(?:{{)+' # '{{'
|
||||||
r'|(?:}})+(?!})' # '}}
|
r'|(?:}})+(?!})' # '}}
|
||||||
@@ -190,8 +179,8 @@ class FormattableString(object):
|
|||||||
assert part == part[0] * len(part)
|
assert part == part[0] * len(part)
|
||||||
return part[:len(part) // 2]
|
return part[:len(part) // 2]
|
||||||
repl = part[1:-1]
|
repl = part[1:-1]
|
||||||
field, _, format_spec = partition(repl, ':')
|
field, _, format_spec = repl.partition(':')
|
||||||
literal, sep, conversion = partition(field, '!')
|
literal, sep, conversion = field.partition('!')
|
||||||
if sep and not conversion:
|
if sep and not conversion:
|
||||||
raise ValueError("end of format while looking for "
|
raise ValueError("end of format while looking for "
|
||||||
"conversion specifier")
|
"conversion specifier")
|
||||||
|
Reference in New Issue
Block a user