Problem with Zipimport

751 views
Skip to first unread message

Arun Shanker Prasad

unread,
Apr 7, 2009, 2:04:03 AM4/7/09
to Pisa XHTML2PDF Support
Hi,

I have a requirement to generate dynamic PDFs from HTML source. I
included the Pisa, html5lib and the reportlab packages for this.
Everything works fine in the local environment as long I keep all the
packages in the initial source ie I do not zip it.

Keeping the whole ReportLab package (204 files) might take me way
close to the allowed file limit, since I host this is Google App
Engine and they have a file limit of up to 1000 files. I tried to
convert the ReportLab
package into a zip and use zipimport to use it. This causes the
following error,

AttributeError: 'HardenedModulesHook' object has no attribute '_files'

My source where the imports are called,
import sys
sys.path.insert(0, 'ho.zip')
sys.path.insert(0, 'html5lib.zip')
sys.path.insert(0, 'sx.zip')
sys.path.insert(0, 'reportlab.zip')
import ho.pisa as pisa

Can anyone help me get around this problem? I have seen many use
reportlab in Google App Engine how do you guys get around this issue??

Any help will be greatly appreciated.

Thanks,
Arun Shanker Prasad.

Dirk Holtwick

unread,
May 4, 2009, 5:10:50 AM5/4/09
to xhtm...@googlegroups.com
Hi,

the Pisa demo itself is also hosted on Google AppEngine:

http://www.xhtml2pdf.com/demo

Make sure you just copy the folder 'reportlab' into your project. All
the binary stuff etc. is not needed. Also make sure to not copy not
needed files. Here is my app.yaml generated by the 'Pyxer Framework':

-----------------8<---------------[cut here]
application: xhtmltopdf
version: 1
runtime: python
api_version: 1

handlers:
- url: /tiny_mce/.*
script: $PYTHON_LIB/google/appengine/ext/zipserve
- url: .*
script: paste-deploy.py

skip_files: |
^(.*/)?(
(.*\.exe)|
(.*\.bat)|
(.*\.pyd)|
(.*\.bak)|
(app\.yaml)|
(app\.yml)|
(index\.yaml)|
(index\.yml)|
(#.*#)|
(.*~)|
(.*\.py[co])|
(.*/RCS/.*)|
(Scripts/.*)|
(bin/.*)|
([Ll]ib/encodings/.*)|
(Lib/[^/]+\.py)|
([Ll]ib/.+?/[Ww]eb[Oo]b-.+?\.egg/.*)|
(cache/.*)|
(tests/.*)|
(include/.*)|
(\..*)|
)$
-----------------8<---------------[cut here]

Dirk


Arun Shanker Prasad schrieb:

Arun Shanker Prasad

unread,
May 4, 2009, 5:24:52 AM5/4/09
to xhtm...@googlegroups.com
Hi Dirk,

Thanks for the reply. I was able to get Pisa to work in Google App Engine, when I uploaded all the source files separately. As you might know there is a limitation to the number of files that can be uploaded to App Engine, so I tried to reduce the number of files by zipping up the source for PIsa, ReportLab and other dependencies. I think this will cause problems as we have to add the path of the zipped source to the sys path before importing them,

sys.path.insert(0, 'reportlab.zip')

I think this is what is causing the problem. I have currently uploaded my application with all the source files separate, and its working fine, my only worry was when the project grows, so will the number of files :)

Thanks,
Arun Shanker Prasad.

Dirk Holtwick

unread,
May 4, 2009, 5:50:39 AM5/4/09
to xhtm...@googlegroups.com
Arun Shanker Prasad schrieb:

> Hi Dirk,
>
> Thanks for the reply. I was able to get Pisa to work in Google App
> Engine, when I uploaded all the source files separately. As you might
> know there is a limitation to the number of files that can be uploaded
> to App Engine, so I tried to reduce the number of files by zipping up
> the source for PIsa, ReportLab and other dependencies. I think this will
> cause problems as we have to add the path of the zipped source to the
> sys path before importing them,
>
> sys.path.insert(0, 'reportlab.zip')
>
> I think this is what is causing the problem. I have currently uploaded
> my application with all the source files separate, and its working fine,
> my only worry was when the project grows, so will the number of files :)

You are right. But I think this question should go to the Reportlab
list, since it is a problem inside of their package AFAIK.

But the limit will change anyways! Look here:
http://code.google.com/appengine/docs/quotas.html

Dirk

Arun Shanker Prasad

unread,
May 4, 2009, 5:55:19 AM5/4/09
to xhtm...@googlegroups.com
Hi,

Some one already posted a modified version of the reportlab,
Sample hosted in GAE, also contains the source :-
http://ruudhelderman.appspot.com/testpdf
Explanation in issue tracker :-    http://code.google.com/p/googleappengine/issues/detail?id=1085

But all the other dependencies will have to be modified. So I think its a no go..

Thanks,
Arun Shanker Prasad.

Dirk Holtwick

unread,
May 4, 2009, 6:05:12 AM5/4/09
to xhtm...@googlegroups.com
Thanks for letting us know. That really helps a lot.

Dirk

Arun Shanker Prasad schrieb:
Reply all
Reply to author
Forward
0 new messages