Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
de5b3a2a
Commit
de5b3a2a
authored
Feb 12, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1483 from MITx/feature/victor/raw-static-files
Feature/victor/raw static files
parents
f18618e3
3ccb33c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
7 deletions
+51
-7
common/djangoapps/static_replace/__init__.py
+15
-5
common/djangoapps/static_replace/test/test_static_replace.py
+36
-2
No files found.
common/djangoapps/static_replace/__init__.py
View file @
de5b3a2a
...
...
@@ -13,12 +13,18 @@ log = logging.getLogger(__name__)
def
_url_replace_regex
(
prefix
):
"""
Match static urls in quotes that don't end in '?raw'.
To anyone contemplating making this more complicated:
http://xkcd.com/1171/
"""
return
r"""
(?x) # flags=re.VERBOSE
(?P<quote>\\?['"]) # the opening quotes
(?P<prefix>{prefix})
# thee
prefix
(?P<rest>.*?) # everything else in the url
(?P=quote) # the first matching closing quote
(?x)
# flags=re.VERBOSE
(?P<quote>\\?['"])
# the opening quotes
(?P<prefix>{prefix})
# the
prefix
(?P<rest>.*?)
# everything else in the url
(?P=quote)
# the first matching closing quote
"""
.
format
(
prefix
=
prefix
)
...
...
@@ -74,6 +80,10 @@ def replace_static_urls(text, data_directory, course_namespace=None):
quote
=
match
.
group
(
'quote'
)
rest
=
match
.
group
(
'rest'
)
# Don't mess with things that end in '?raw'
if
rest
.
endswith
(
'?raw'
):
return
original
# course_namespace is not None, then use studio style urls
if
course_namespace
is
not
None
and
not
isinstance
(
modulestore
(),
XMLModuleStore
):
url
=
StaticContent
.
convert_legacy_static_url
(
rest
,
course_namespace
)
...
...
common/djangoapps/static_replace/test/test_static_replace.py
View file @
de5b3a2a
from
nose.tools
import
assert_equals
from
static_replace
import
replace_static_urls
,
replace_course_urls
import
re
from
nose.tools
import
assert_equals
,
assert_true
,
assert_false
from
static_replace
import
(
replace_static_urls
,
replace_course_urls
,
_url_replace_regex
)
from
mock
import
patch
,
Mock
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.mongo
import
MongoModuleStore
...
...
@@ -75,3 +78,34 @@ def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings):
mock_storage
.
exists
.
return_value
=
False
assert_equals
(
'"/static/data_dir/file.png"'
,
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
))
def
test_raw_static_check
():
"""
Make sure replace_static_urls leaves alone things that end in '.raw'
"""
path
=
'"/static/foo.png?raw"'
assert_equals
(
path
,
replace_static_urls
(
path
,
DATA_DIRECTORY
))
text
=
'text <tag a="/static/js/capa/protex/protex.nocache.js?raw"/><div class="'
assert_equals
(
path
,
replace_static_urls
(
path
,
text
))
def
test_regex
():
yes
=
(
'"/static/foo.png"'
,
'"/static/foo.png"'
,
"'/static/foo.png'"
)
no
=
(
'"/not-static/foo.png"'
,
'"/static/foo'
,
# no matching quote
)
regex
=
_url_replace_regex
(
'/static/'
)
for
s
in
yes
:
print
'Should match: {0!r}'
.
format
(
s
)
assert_true
(
re
.
match
(
regex
,
s
))
for
s
in
no
:
print
'Should not match: {0!r}'
.
format
(
s
)
assert_false
(
re
.
match
(
regex
,
s
))
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