how to import a python module in a jython script

958 views
Skip to first unread message

Marianne

unread,
Apr 4, 2013, 1:43:07 AM4/4/13
to redbo...@googlegroups.com
Hi All,

I want to do some cleaning of user input so I can be confident in displaying some of the input text as HTML. I know of a python module which will let me easily do this - bleach (http://bleach.readthedocs.org/en/latest/clean.html). I would like to use bleach.clean() in my details.py Jython script. Obviously I need to install bleach, and its dependency html5lib, somewhere that is findable by Jython for the import bleach statement to work.  What do I need to do? Pointers to websites/docs welcome.

Thanks!

Marianne




Mike Jones

unread,
Apr 4, 2013, 2:02:48 AM4/4/13
to redbo...@googlegroups.com

Hi Marianne,

 

I’m not a python expert, but at a guess I’d say you need to include the directories that contain the python libraries on your Python Path.

 

Have a look at these web pages for more info:

http://www.jython.org/archive/22/userfaq.html#my-modules-can-not-be-found-when-imported-from-an-embedded-application

http://stefaanlippens.net/jython_and_pythonpath

 

I hope that helps,

Mike

 

 

--
You received this message because you are subscribed to the Google Groups "ReDBox Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbox-dev+...@googlegroups.com.
To post to this group, send an email to redbo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/redbox-dev/-/-LwRMFZUT5oJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Marianne Brown

unread,
Apr 4, 2013, 2:25:33 AM4/4/13
to redbo...@googlegroups.com
I guess I was wondering if there was a right way to do this for the ReDBox application. 
  • Is there a config file with a python path property already set? Have looked in tf_env.sh and it isn't set there. I've printed out the sys.path and seen what it is set to and it is all local to the $PROJECT_HOME area as expected.
  • Is there a right place to install the python modules? (e.g. I was thinking server/lib as it contains all the jar files but is there a "best practice" way to do this - ? a python folder inside the server/lib )
Obviously I'll have to fiddle with our deployment script so that anything I manually do now on my local dev instance will be reproduced when installing on the test server and the production server. 

I have only been fiddling round the edges of ReDBox so far - velocity templates etc. Haven't delved into all the config files etc yet.

--
Marianne Brown
marianne...@gmail.com
Mobile: 0403 889 478

Duncan Dickinson

unread,
Apr 4, 2013, 5:00:14 AM4/4/13
to ReDBox Developer List
Hi Marianne,

I created home/lib to store libraries for the alerts work: https://github.com/redbox-mint/redbox/tree/master/config/src/main/config/home/lib


You should be able to add to home/lib/jython in your local build and have it deploy. Don't forget that we're running jython so you'll be a little limited in terms of python coding and libs - I think our Jython jar supports Python 2.5. 

It can be handy to setup some testing scripts to save time - checkout my dodgy doco that details how I did this: https://github.com/redbox-mint/redbox/tree/master/config/src/main/config/home/lib/jython/alertlib/test

I hope that ramble's of some use.

Cheers,

Duncan
--
Cheers,


Duncan


Duncan Dickinson
QCIF Project Manager 
Central Queensland University

Contact me:
monday to thursday
ph: 07 3138 2084
m: 0432 402 511
skype: de.dickinson

website | calendar | LinkedIn

Marianne Brown

unread,
Apr 4, 2013, 5:16:06 AM4/4/13
to redbo...@googlegroups.com
Thanks Duncan! Think that covers everything I was looking for :)

Marianne

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages