本文整理汇总了Python中compressor.filters.css_default.CssAbsoluteFilter类的典型用法代码示例。如果您正苦于以下问题:Python CssAbsoluteFilter类的具体用法?Python CssAbsoluteFilter怎么用?Python CssAbsoluteFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CssAbsoluteFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_guess_filename
def test_guess_filename(self):
for base_url in ('/media/', 'http://media.example.com/'):
settings.COMPRESS_URL = base_url
url = '%s/img/python.png' % settings.COMPRESS_URL.rstrip('/')
path = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
content = "p { background: url('%s') }" % url
filter = CssAbsoluteFilter(content)
self.assertEqual(path, filter.guess_filename(url))
示例2: test_css_absolute_filter_only_url_fragment
def test_css_absolute_filter_only_url_fragment(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
content = "p { background: url('#foo') }"
filter = CssAbsoluteFilter(content)
self.assertEqual(content, filter.input(filename=filename, basename='css/url/test.css'))
with self.settings(COMPRESS_URL='http://media.example.com/'):
filter = CssAbsoluteFilter(content)
self.assertEqual(content, filter.input(filename=filename, basename='css/url/test.css'))
示例3: test_css_absolute_filter_relative_path
def test_css_absolute_filter_relative_path(self):
from compressor.filters.css_default import CssAbsoluteFilter
filename = os.path.join(django_settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css')
content = "p { background: url('../../images/image.gif') }"
output = "p { background: url('%simages/image.gif?%s') }" % (settings.MEDIA_URL, get_hashed_mtime(filename))
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename))
settings.MEDIA_URL = 'https://media.example.com/'
output = "p { background: url('%simages/image.gif?%s') }" % (settings.MEDIA_URL, get_hashed_mtime(filename))
self.assertEqual(output, filter.input(filename=filename))
示例4: test_css_absolute_filter_relative_path
def test_css_absolute_filter_relative_path(self):
filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
filter = CssAbsoluteFilter(self.content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = 'https://media.example.com/'
filter = CssAbsoluteFilter(self.content)
output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例5: test_css_absolute_filter_https
def test_css_absolute_filter_https(self):
from compressor.filters.css_default import CssAbsoluteFilter
filename = os.path.join(settings.MEDIA_ROOT, 'css/url/test.css')
content = "p { background: url('../../images/image.gif') }"
output = "p { background: url('%simages/image.gif') }" % settings.MEDIA_URL
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename))
settings.MEDIA_URL = 'https://media.example.com/'
filename = os.path.join(settings.MEDIA_ROOT, 'css/url/test.css')
output = "p { background: url('%simages/image.gif') }" % settings.MEDIA_URL
self.assertEqual(output, filter.input(filename=filename))
示例6: test_guess_filename
def test_guess_filename(self):
import urllib
from compressor.filters.css_default import CssAbsoluteFilter
for base_url in ("/media/", "http://media.example.com/"):
settings.COMPRESS_URL = base_url
url = "%s/img/python.png" % settings.COMPRESS_URL.rstrip("/")
path = os.path.join(settings.COMPRESS_ROOT, "img/python.png")
content = "p { background: url('%s') }" % url
filter = CssAbsoluteFilter(content)
self.assertEqual(path, filter.guess_filename(url))
示例7: test_css_absolute_filter
def test_css_absolute_filter(self):
from compressor.filters.css_default import CssAbsoluteFilter
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
content = "p { background: url('../../images/image.gif') }"
output = "p { background: url('%simages/image.gif?%s') }" % (settings.COMPRESS_URL, get_hashed_mtime(filename))
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = 'http://media.example.com/'
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
output = "p { background: url('%simages/image.gif?%s') }" % (settings.COMPRESS_URL, get_hashed_mtime(filename))
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例8: test_css_absolute_filter_relative_path
def test_css_absolute_filter_relative_path(self):
from compressor.filters.css_default import CssAbsoluteFilter
filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
content = "p { background: url('../../img/python.png') }"
output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.suffix_method(imagefilename))
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = 'https://media.example.com/'
filter = CssAbsoluteFilter(content)
output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.suffix_method(imagefilename))
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例9: test_css_absolute_filter_filename_outside_compress_root
def test_css_absolute_filter_filename_outside_compress_root(self):
filename = '/foo/bar/baz/test.css'
content = self.template % blankdict(url='../qux/')
params = blankdict({
'url': settings.COMPRESS_URL + 'bar/qux/',
})
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='bar/baz/test.css'))
settings.COMPRESS_URL = 'https://static.example.com/'
params['url'] = settings.COMPRESS_URL + 'bar/qux/'
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='bar/baz/test.css'))
示例10: test_css_no_hash
def test_css_no_hash(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
content = self.template % blankdict(url='../../')
params = blankdict({
'url': settings.COMPRESS_URL,
})
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
with self.settings(COMPRESS_URL='http://static.example.com/'):
params['url'] = settings.COMPRESS_URL
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例11: test_css_absolute_filter_relative_path
def test_css_absolute_filter_relative_path(self):
filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
params = {
'url': settings.COMPRESS_URL,
'hash': self.hashing_func(imagefilename),
}
output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
"p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
filter = CssAbsoluteFilter(self.content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = params['url'] = 'https://media.example.com/'
filter = CssAbsoluteFilter(self.content)
output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
"p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例12: test_css_absolute_filter_relative_path
def test_css_absolute_filter_relative_path(self):
filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'static', 'whatever/../css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
content = self.template % blankdict(url='../../')
params = blankdict({
'url': settings.COMPRESS_URL,
'hash': '?' + self.hashing_func(imagefilename),
})
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = params['url'] = 'https://static.example.com/'
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例13: test_css_absolute_filter_querystring
def test_css_absolute_filter_querystring(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
params = {
'url': settings.COMPRESS_URL,
'hash': self.hashing_func(imagefilename),
}
content = "p { background: url('../../img/python.png?foo') }"
output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
filter = CssAbsoluteFilter(content)
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例14: test_css_absolute_filter_querystring
def test_css_absolute_filter_querystring(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
content = self.template % blankdict(url='../../', query='?foo')
params = blankdict({
'url': settings.COMPRESS_URL,
'query': '?foo',
'hash': '&' + self.hashing_func(imagefilename),
})
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
示例15: test_css_absolute_filter_url_fragment
def test_css_absolute_filter_url_fragment(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
content = self.template % blankdict(url='../../', frag='#foo')
params = blankdict({
'url': settings.COMPRESS_URL,
'hash': '?' + self.hashing_func(imagefilename),
'frag': '#foo',
})
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
with self.settings(COMPRESS_URL='http://media.example.com/'):
params['url'] = settings.COMPRESS_URL
output = self.template % params
filter = CssAbsoluteFilter(content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))