Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
76c3060c
Commit
76c3060c
authored
Nov 29, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish compat with python2.x and python3.x
parent
49d651b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
pipeline/compressors/__init__.py
+12
-8
tests/tests/test_compressor.py
+1
-1
tests/tests/test_storage.py
+2
-6
No files found.
pipeline/compressors/__init__.py
View file @
76c3060c
...
@@ -85,9 +85,9 @@ class Compressor(object):
...
@@ -85,9 +85,9 @@ class Compressor(object):
namespace
=
settings
.
PIPELINE_TEMPLATE_NAMESPACE
namespace
=
settings
.
PIPELINE_TEMPLATE_NAMESPACE
base_path
=
self
.
base_path
(
paths
)
base_path
=
self
.
base_path
(
paths
)
for
path
in
paths
:
for
path
in
paths
:
contents
=
self
.
read_
file
(
path
)
contents
=
self
.
read_
text
(
path
)
contents
=
re
.
sub
(
b
"
\r
?
\n
"
,
b
"
\\\\
n"
,
contents
)
contents
=
re
.
sub
(
"
\r
?
\n
"
,
"
\\\\
n"
,
contents
)
contents
=
re
.
sub
(
b
"'"
,
b
"
\\
'"
,
contents
)
contents
=
re
.
sub
(
"'"
,
"
\\
'"
,
contents
)
name
=
self
.
template_name
(
path
,
base_path
)
name
=
self
.
template_name
(
path
,
base_path
)
compiled
+=
"
%
s['
%
s'] =
%
s('
%
s');
\n
"
%
(
compiled
+=
"
%
s['
%
s'] =
%
s('
%
s');
\n
"
%
(
namespace
,
namespace
,
...
@@ -130,15 +130,15 @@ class Compressor(object):
...
@@ -130,15 +130,15 @@ class Compressor(object):
asset_url
=
self
.
construct_asset_path
(
asset_path
,
path
,
asset_url
=
self
.
construct_asset_path
(
asset_path
,
path
,
output_filename
,
variant
)
output_filename
,
variant
)
return
"url(
%
s)"
%
asset_url
return
"url(
%
s)"
%
asset_url
content
=
self
.
read_
file
(
path
)
content
=
self
.
read_
text
(
path
)
# content needs to be unicode to avoid explosions with non-ascii chars
# content needs to be unicode to avoid explosions with non-ascii chars
content
=
re
.
sub
(
URL_DETECTOR
,
reconstruct
,
force_text
(
content
)
)
content
=
re
.
sub
(
URL_DETECTOR
,
reconstruct
,
content
)
stylesheets
.
append
(
content
)
stylesheets
.
append
(
content
)
return
'
\n
'
.
join
(
stylesheets
)
return
'
\n
'
.
join
(
stylesheets
)
def
concatenate
(
self
,
paths
):
def
concatenate
(
self
,
paths
):
"""Concatenate together a list of files"""
"""Concatenate together a list of files"""
return
b
"
\n
"
.
join
([
self
.
read_file
(
path
)
for
path
in
paths
])
return
"
\n
"
.
join
([
self
.
read_text
(
path
)
for
path
in
paths
])
def
construct_asset_path
(
self
,
asset_path
,
css_path
,
output_filename
,
variant
=
None
):
def
construct_asset_path
(
self
,
asset_path
,
css_path
,
output_filename
,
variant
=
None
):
"""Return a rewritten asset URL for a stylesheet"""
"""Return a rewritten asset URL for a stylesheet"""
...
@@ -175,7 +175,7 @@ class Compressor(object):
...
@@ -175,7 +175,7 @@ class Compressor(object):
"""Return the base64 encoded contents"""
"""Return the base64 encoded contents"""
if
path
in
self
.
__class__
.
asset_contents
:
if
path
in
self
.
__class__
.
asset_contents
:
return
self
.
__class__
.
asset_contents
[
path
]
return
self
.
__class__
.
asset_contents
[
path
]
data
=
self
.
read_
file
(
path
)
data
=
self
.
read_
bytes
(
path
)
self
.
__class__
.
asset_contents
[
path
]
=
base64
.
b64encode
(
data
)
self
.
__class__
.
asset_contents
[
path
]
=
base64
.
b64encode
(
data
)
return
self
.
__class__
.
asset_contents
[
path
]
return
self
.
__class__
.
asset_contents
[
path
]
...
@@ -201,13 +201,17 @@ class Compressor(object):
...
@@ -201,13 +201,17 @@ class Compressor(object):
output_path
=
posixpath
.
join
(
settings
.
PIPELINE_ROOT
,
posixpath
.
dirname
(
output_filename
))
output_path
=
posixpath
.
join
(
settings
.
PIPELINE_ROOT
,
posixpath
.
dirname
(
output_filename
))
return
relpath
(
absolute_path
,
output_path
)
return
relpath
(
absolute_path
,
output_path
)
def
read_
file
(
self
,
path
):
def
read_
bytes
(
self
,
path
):
"""Read file content in binary mode"""
"""Read file content in binary mode"""
file
=
default_storage
.
open
(
path
)
file
=
default_storage
.
open
(
path
)
content
=
file
.
read
()
content
=
file
.
read
()
file
.
close
()
file
.
close
()
return
content
return
content
def
read_text
(
self
,
path
):
content
=
self
.
read_bytes
(
path
)
return
force_text
(
content
)
class
CompressorBase
(
object
):
class
CompressorBase
(
object
):
def
__init__
(
self
,
verbose
):
def
__init__
(
self
,
verbose
):
...
...
tests/tests/test_compressor.py
View file @
76c3060c
...
@@ -39,7 +39,7 @@ class CompressorTest(TestCase):
...
@@ -39,7 +39,7 @@ class CompressorTest(TestCase):
_
(
'pipeline/js/first.js'
),
_
(
'pipeline/js/first.js'
),
_
(
'pipeline/js/second.js'
)
_
(
'pipeline/js/second.js'
)
])
])
self
.
assertEquals
(
b
"""function concat() {
\n
console.log(arguments);
\n
}
\n\n
function cat() {
\n
console.log("hello world");
\n
}
\n
"""
,
js
)
self
.
assertEquals
(
"""function concat() {
\n
console.log(arguments);
\n
}
\n\n
function cat() {
\n
console.log("hello world");
\n
}
\n
"""
,
js
)
@patch.object
(
base64
,
'b64encode'
)
@patch.object
(
base64
,
'b64encode'
)
def
test_encoded_content
(
self
,
mock
):
def
test_encoded_content
(
self
,
mock
):
...
...
tests/tests/test_storage.py
View file @
76c3060c
...
@@ -34,12 +34,8 @@ class StorageTest(TestCase):
...
@@ -34,12 +34,8 @@ class StorageTest(TestCase):
'css/first.css'
:
(
self
.
storage
,
'css/first.css'
),
'css/first.css'
:
(
self
.
storage
,
'css/first.css'
),
'images/arrow.png'
:
(
self
.
storage
,
'images/arrow.png'
)
'images/arrow.png'
:
(
self
.
storage
,
'images/arrow.png'
)
}))
}))
self
.
assertEqual
(
processed_files
,
[
self
.
assertTrue
((
'css/first.css'
,
'css/first.css'
,
True
)
in
processed_files
)
(
'css/first.css'
,
'css/first.css'
,
True
),
self
.
assertTrue
((
'images/arrow.png'
,
'images/arrow.png'
,
True
)
in
processed_files
)
(
'images/arrow.png'
,
'images/arrow.png'
,
True
),
(
'testing.css'
,
'testing.css'
,
True
),
(
'scripts.css'
,
'scripts.css'
,
True
)
])
def
tearDown
(
self
):
def
tearDown
(
self
):
settings
.
PIPELINE_CSS
=
{}
settings
.
PIPELINE_CSS
=
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment