Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
4f665e0a
Commit
4f665e0a
authored
Aug 22, 2018
by
Roman Yurchak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate package URI
parent
f5027533
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
src/pyodide.js
src/pyodide.js
+30
-5
test/conftest.py
test/conftest.py
+5
-3
No files found.
src/pyodide.js
View file @
4f665e0a
...
...
@@ -2,6 +2,13 @@
* The main bootstrap script for loading pyodide.
*/
// Regexp for validating package name and URI
var
package_name_regexp
=
'
[a-zA-Z0-9_
\
-]+
'
var
package_uri_regexp
=
new
RegExp
(
'
^(?:https?|file)://.*?(
'
+
package_name_regexp
+
'
).js$
'
);
var
package_name_regexp
=
new
RegExp
(
'
^
'
+
package_name_regexp
+
'
$
'
);
var
languagePluginLoader
=
new
Promise
((
resolve
,
reject
)
=>
{
// This is filled in by the Makefile to be either a local file or the
// deployed location. TODO: This should be done in a less hacky
...
...
@@ -13,20 +20,38 @@ var languagePluginLoader = new Promise((resolve, reject) => {
var
packages
=
undefined
;
let
loadedPackages
=
new
Set
();
let
_uri_to_package_name
=
(
package_uri
)
=>
{
// Generate a unique package name from URI
if
(
package_name_regexp
.
test
(
package_uri
))
{
return
package_uri
;
}
else
if
(
package_uri_regexp
.
test
(
package_uri
))
{
var
match
=
package_uri_regexp
.
exec
(
package_uri
);
// Get the regexp group corresponding to the package name
return
match
[
1
];
}
else
{
return
null
;
}
};
let
loadPackage
=
(
names
)
=>
{
// DFS to find all dependencies of the requested packages
let
packages
=
window
.
pyodide
.
packages
.
dependencies
;
let
queue
=
new
Array
(
names
);
let
toLoad
=
new
Set
();
while
(
queue
.
length
)
{
const
package
=
queue
.
pop
();
var
valid_package_name_regexp
=
new
RegExp
(
'
^[a-zA-Z0-9_
\
-]+$
'
);
console
.
log
(
package
+
valid_package_name_regexp
.
test
(
package
));
if
(
!
valid_package_name_regexp
.
test
(
package
))
{
console
.
log
(
`Invalid package name '
${
package
}
'`
);
const
package_uri
=
queue
.
pop
();
const
package
=
_uri_to_package_name
(
package_uri
);
if
(
package
==
null
)
{
console
.
log
(
`Invalid package name or URI '
${
package_uri
}
'`
);
break
;
}
console
.
log
(
`Loading
${
package
}
from
${
package_uri
}
`
);
if
(
!
loadedPackages
.
has
(
package
))
{
toLoad
.
add
(
package
);
if
(
packages
.
hasOwnProperty
(
package
))
{
...
...
test/conftest.py
View file @
4f665e0a
...
...
@@ -53,6 +53,9 @@ class SeleniumWrapper:
logs
=
self
.
driver
.
execute_script
(
"return window.logs"
)
return
'
\
n
'
.
join
(
str
(
x
)
for
x
in
logs
)
def
clean_logs
(
self
):
self
.
driver
.
execute_script
(
"window.logs = []"
)
def
run
(
self
,
code
):
return
self
.
run_js
(
'return pyodide.runPython({!r})'
.
format
(
code
))
...
...
@@ -145,11 +148,10 @@ if pytest is not None:
def
selenium
(
_selenium_cached
):
# selenium instance cached at the module level
try
:
# clean selenium logs for each test run
_selenium_cached
.
driver
.
execute_script
(
"window.logs = []"
)
_selenium_cached
.
clean_logs
()
yield
_selenium_cached
finally
:
print
(
'
\
n
'
.
join
(
str
(
x
)
for
x
in
_selenium_cached
.
logs
)
)
print
(
_selenium_cached
.
logs
)
PORT
=
0
...
...
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