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
c676eeb1
Commit
c676eeb1
authored
Oct 02, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/rebase-20140926: Repaired faulty keygen logic
parent
896c0d5f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
1 deletions
+56
-1
common/djangoapps/util/request.py
+56
-1
No files found.
common/djangoapps/util/request.py
View file @
c676eeb1
""" Utility functions related to HTTP requests """
""" Utility functions related to HTTP requests """
from
django.core.handlers.base
import
BaseHandler
from
django.test
import
RequestFactory
import
re
import
re
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
from
microsite_configuration
import
microsite
from
microsite_configuration
import
microsite
from
opaque_keys
import
InvalidKeyError
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.keys
import
CourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
log
=
logging
.
getLogger
(
__name__
)
COURSE_REGEX
=
re
.
compile
(
r'^.*?/courses/{}'
.
format
(
settings
.
COURSE_ID_PATTERN
))
COURSE_REGEX
=
re
.
compile
(
r'^.*?/courses/{}'
.
format
(
settings
.
COURSE_ID_PATTERN
))
...
@@ -33,6 +38,17 @@ def course_id_from_url(url):
...
@@ -33,6 +38,17 @@ def course_id_from_url(url):
if
not
url
:
if
not
url
:
return
None
return
None
deprecated
=
False
if
'/'
in
url
:
deprecated
=
True
if
deprecated
:
COURSE_REGEX
=
re
.
compile
(
r'^.*/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)'
)
key_generator
=
SlashSeparatedCourseKey
.
from_deprecated_string
else
:
COURSE_REGEX
=
re
.
compile
(
r'^.*?/courses/(?P<course_id>[a-zA-Z0-9_+\/:]+)'
)
key_generator
=
CourseKey
.
from_string
match
=
COURSE_REGEX
.
match
(
url
)
match
=
COURSE_REGEX
.
match
(
url
)
if
match
is
None
:
if
match
is
None
:
...
@@ -44,6 +60,45 @@ def course_id_from_url(url):
...
@@ -44,6 +60,45 @@ def course_id_from_url(url):
return
None
return
None
try
:
try
:
return
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
course_key
=
key_generator
(
course_id
)
except
InvalidKeyError
:
except
InvalidKeyError
:
log
.
warning
(
'unable to parse course_id "{}"'
.
format
(
course_id
),
exc_info
=
True
)
return
None
return
None
return
course_key
class
RequestMock
(
RequestFactory
):
"""
RequestMock is used to create generic/dummy request objects in
scenarios where a regular request might not be available for use
"""
def
request
(
self
,
**
request
):
"Construct a generic request object."
request
=
RequestFactory
.
request
(
self
,
**
request
)
handler
=
BaseHandler
()
handler
.
load_middleware
()
for
middleware_method
in
handler
.
_request_middleware
:
if
middleware_method
(
request
):
raise
Exception
(
"Couldn't create request mock object - "
"request middleware returned a response"
)
return
request
class
RequestMockWithoutMiddleware
(
RequestMock
):
"""
RequestMockWithoutMiddleware is used to create generic/dummy request
objects in scenarios where a regular request might not be available for use.
It's similiar to its parent except for the fact that it skips the loading
of middleware.
"""
def
request
(
self
,
**
request
):
"Construct a generic request object."
request
=
RequestFactory
.
request
(
self
,
**
request
)
if
not
hasattr
(
request
,
'session'
):
request
.
session
=
{}
return
request
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