pypedia
TRANSCRIPT
From:
http://wiki.python.org/moin/SandboxedPython
Hmm.. nice idea.
Fortunately, there is a Sandboxed Python: googleappengine
..and an advanced, highly extendable wiki engine: Mediawiki
The combination of all these is… PyPedia
This presentation takes a tour to the core functionality of www.pypedia.com
• Sign in www.pypedia.com . Suppose that your username is “JohnDoe”. (In the rest of this presentation replace “JohnDoe” with your username)
• Create an article with title: Foo_user_JohnDoe
• Save the article with the prefilled text unchanged.
• Edit the “code” section and add the code of the method.
• Tip: Click three times in the code text area for code friendly formatting.
• Save the edit.
• Done! You have a script of your own published in PyPedia.
• In the article, press the “Execute on browser” button ( )
• The function’s output and returned value appear in an area under the button:
• Then edit the parameters section:
• This is what you see:
• Inside the <inputs> tags add the text:<param name="arg_1" type="data" value="default_input" label="Enter value for argument 1:"/><param name="arg_2" type="eval" value=”4" label="Enter value for argument 2:"/>
• What are all these??
Ignore this partAutomatically generated(Edits here will be removed)
The name of the argument
• If type=“data” then the input is treated as string
• If type=“eval” then the input is treated as python expression (i.e. [3,4,5])
Default values
Text to display in the form
Add this part
• Click save. The parameters section of the article should look like this:
• Fill the parameters and press the “Execute on browser” button. This should appear:
Play with the arguments. A complete online script has been created!
Cool, but I want to call the function from my local computer..
• Install the PyPedia python library:git clone git://github.com/kantale/pypedia.git
• Load the function in python:>>> import pypedia
>>> from pypedia import Foo_user_JohnDoe
>>> print foo_user_JohnDoe(“test”, [1,2,3])
function foo
Arguments: test [1,2,3]
42
>>>
• You can call the method of any user and your method can be called by anyone
Some tips of the python library:
• pypedia.before_timestamp = “20120416000000”
– Import the most recent revision of functions and classes that are older than 16/4/2012 (something like method permalinks..)
• pypedia.enable_cache = True
– Suppress method download if method already exists
• pypedia.debug = True
– For debug info
• pypedia.warnings = False
– Suppress warnings
• Save and press the button “Execute on browser”
• A method can call any other method without importing.
• All PyPedia articles belong to the same namespace (as with any wiki).
• Same behavior exists for classes.
• In the Goo_user_JohnDoe article press the “Download code” button.
• The file Goo_user_JohnDoe.py is downloaded.• Open this file with a text editor:
• It contains all the code required for executing the method (including the user parameters).
• Executing locally the method is as simple as:#> python Goo_user_JohnDoe.py
• Now edit the code of the method (edit the code section) so that it will not return 42, but something else. Upon saving, this pops up:
• With unitests you can guarantee a certain behavior of your methods.
• As with any wiki, in PyPedia a method can have more than one name:
• Create the page: Hoo_user_JohnDoe
• Replace all the prefilled text with:
#REDIRECT [[Foo_user_JohnDoe]]
• Save the page
• In the front page run:
Hoo_user_JohnDoe("test", [1,2,3])
• The result is exactly the same as running the function: Foo_user_JohnDoe
Executing a method in a remote computer:• Edit your user page and add an “ssh” section:
• Substitute the above values with real ones for a computer that you have remote access (the username doesn’t have to be the same as your PyPedia username).
==ssh==host=www.example.comusername=JohnDoepath=/home/JohnDoe/runPyPedia
• Save the page.
• This content is NOT shown to anyone and there isn’t anyway to retrieve it (to change just make another “ssh” section).
• Login and cd to the path that you declared of your remote computer.
• Install there:
– The PyPedia python library:git clone git://github.com/kantale/pypedia.git
– The utility ssh_wpl_client:wgethttps://raw.github.com/kantale/PyPedia_server/master/utils/ssh_wpl_client.py
• On the article Foo_user_JohnDoe press the “Execute on remote computer” button.
• Enter the password of your remote computer and press GO!
• A new tab opens with the following content:
PyPedia’s REST api:
• http://www.pypedia.com/index.php?get_code=Goo_user_JohnDoe(1,2)– Fetch the constraint-free version necessary to run the
command Goo_user_JohnDoe(1,2)
– Use wget or curl to save the content in a file
• http://www.pypedia.com/index.php?b_timestamp=20120418000000&get_code=Goo_user_JohnDoe(1,2)– Fetch the most recent revision of the constraint-free
version of the code as it was before 18/4/2012
• By sharing these links we can archive and reproduce our analysis.
Who can edit my article?
• By default only you (and the admins) can edit any part of the article.
• Edit the Permissions subsections and add any users (coma separated) that you want to allow editing.
• Special user names:
– SIGNED: Any signed user can edit this section
– ALL: Any user can edit this section
• On the top of each article there is a button:
• With this you can create a personalized version of the article that only you can edit.
• For example if you fork the article: Foo_user_Someonethen the article Foo_user_JohnDoewill be created with the same content but with different user privileges.
• This is similar to the Github’s “fork” feature.
What is the “Development Code” section ?
• ANY user (yes any) can edit this section. The code is not parsed, not downloaded and not run at all.
• Users (that are not allowed to edit) should use this section to make suggestions for code corrections.
• Alternatively they can use the Talk pages for comments regarding any part of the article.
• The Documentation, Return and See alsosubsections allow any kind of content.
• Use wiki text formatting in these sections to document your method and help other people to use it.
• All content is under the Simplified BSD License
• Articles that are well written and documented with thorough unitests and parameters may be copied to the main namespace by the admins
• I.e. if the method Foo_user_JohnDoe is good enough, the admins can create the article Foowith the same content
• Only the admins can edit the main namespace
How safe are the contents of PyPedia ??
• Run “User” methods only if you trust the code or the user (or if you are running in a sandbox).
• The admins can delete methods with misleading and/or malicious content.
• Methods in the main namespace should be considered safe.
• As with any open content no guarantee is given for the security or efficiency of the code.
Thanks for reading!
• Contact: [email protected]
• Join us in google groups:
http://groups.google.com/group/pypedia
• Twitter: @PyPedia
• PyPedia’s source code:– Mediawiki extension:
https://github.com/kantale/PyPedia_server
– Python library:
https://github.com/kantale/pypedia