Re: [Zope] Passing Parameters to External Methods

2005-11-17 Thread Asad Habib
Actually, I not receiving an error anymore but a pdf is not being 
generated either. When I test my External Method directly through the 
ZMI the only thing that is returned is the following line:


__builtin__.html2pdf instance at 0x4a1e8f0

I have tried passing in the parameters using the request object as well as 
hard-coding them in but in both cases a pdf is not generated and there is 
no traceback. The code for my External Method is as follows:


# Added by Asad Habib to allow use as an External Method from Zope
def createHtmlToPdf(self):
   return 
html2pdf('/Applications/Plone2/Library/Software/Zope270/Zope/error.html', 
'orbweaver.engin.umich.edu', 
'/Applications/Plone2/Library/Software/Zope270/Zope/error.pdf')


# This is based on a php script (c) Jason Rust [EMAIL PROTECTED]
# See that script for licensing
# Convert an HTML file to a PDF file using html2ps and ps2pdf

from tempfile import gettempdir, mkstemp
import os
import re
from re import IGNORECASE, DOTALL
from copy import copy

class html2pdf:
  def __init__(self, in_htmlFile, in_domain, in_pdfFile = None):
Constructor

in_htmlFile The full path to the html file to convert
in_domain The default domain name for images that have a relative path
in_pdfFile (optional) The full path to the pdf file to output. If not 
given then we create a temporary name.



self.htmlFile = '' #The full path to the file we are parsing
self.pdfFile = '' #The full path to the output file
self.tmpDir = gettempdir() #The temporary directory to save 
intermediate files

self.debug = False #Whether or not we are in debug mode
self.htmlErrors = False #Whether we output html errors
self.defaultDomain = '' #The default domain for relative images
self.html2psPath = '/usr/bin/html2ps' #The path to the html2ps 
executable

self.ps2pdfPath = '/usr/bin/ps2pdf' #The path to the ps2pdf executable
self.getUrlPath = '/usr/bin/curl -i' #The path to your get URL 
program, including options to get headers
self.useCSS = True #Whether or not to try and parse the CSS in the 
html file and use it in creating the pdf

self.additionalCSS = '' #Other styles to use when parsing the page
self.pageInColor = True #Show the page in color?
self.grayScale = False #Show the images be in grayscale?
self.scaleFactor = 1 #Scale factore for the page
self.underlineLinks = None #Whether to underline links or not
self.headers ={} #The header information  # self.headers was 
array('left' = '$T', 'right' = '$[author]')
self.footers ={} #The footer information  #self.footers was 
array('center' = '- $N -')

self.html2psrc = 
option:
  titlepage: 0; /* do not generate a title page */
  toc: 0;   /* no table of contents */
  colour: %pageInColor%; /* create the page in color */
  underline: %underlineLinks%; /* underline links */
  grayscale: %grayScale%; /* Make images grayscale? */
  scaledoc: %scaleFactor%; /* Scale the document */
}
package:
  geturl: %getUrlPath%; /* path to the geturl */
}
showurl: 0; /* do not show the url next to links */
 #Default html2ps configuration that we use (is parsed before being 
used, though)

self.makeAbsoluteImageUrls = True
Whether HTML_ToPDF should replace all relative image paths in the
  input HTML document with the default domain or not. Switch this to
  false if you want to convert a HTML file which is located locally in 
the

  file system and is not reachable via HTTP but all the images used
  in the HTML file are located correctly according to their relative
  paths.
self.ps2pdfIncludePath = '' #Include path for ps2pdf (-I option), for 
example to specify where to search for font files, etc.
self._htmlString = ''; #We use this to store the html file to a string 
for manipulation


self.htmlFile = in_htmlFile
self.defaultDomain = in_domain

if in_pdfFile is None:
  tempFile = mkstemp(prefix = 'PDF-', dir = self.tmpDir)
  os.close(tempFile[0]) #close the file handle which is opened by 
mkstemp

  self.pdfFile = tempFile[1]
else:
  self.pdfFile = in_pdfFile


#==
  def addHtml2PsSettings(self, in_settings):
Adds on more html2ps settings to the end of the default set of 
settings.

self.html2psrc += \n + in_settings


#==
  def setDebug(self, in_debug):
Sets the debug variable: true (debugging on) or false (debugging 
off).

self.debug = in_debug


#==
  def setHeader(self, in_attribute, in_value):
Sets a header.

@param string $in_attribute One of the header attributes that html2ps 
accepts.  Most
 

Re: [Zope] Passing Parameters to External Methods

2005-11-17 Thread Paul Winkler
On Thu, Nov 17, 2005 at 10:02:12AM -0500, Asad Habib wrote:
 Actually, I not receiving an error anymore but a pdf is not being 
 generated either. When I test my External Method directly through the 
 ZMI the only thing that is returned is the following line:
 
 __builtin__.html2pdf instance at 0x4a1e8f0

Well, that's not unexpected :)  Your external method returns
an html2pdf instance, and that's exactly what you see here
- as a string.

If you want this method to return an actual viewable PDF,
you need to find some method of getting the actual PDF data
out of the object, and return *that*.

Or better, if the PDF is large, hopefully html2pdf has
some way to read data from it in chunks. Then you can do
something vaguely like (subsituting appropriate method calls):

response = REQUEST.RESPONSE
response.setHeader('Content-Length', your_pdf_object.get_size())
response.setHeader('Content-Type', 'application/pdf')
for data in your_pdf_object.read_data_by_chunks():
response.write(data)

This will get data to the client faster, and maybe save memory
on the server depending on how html2pdf works.

-- 

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Passing Parameters to External Methods

2005-11-16 Thread Asad Habib
Hello. I am trying to use the Python version of the PHP script written by 
Jason Rust called 'HTML_ToPDF.php'. I have represented this script using 
an External Method since it uses functions, such as open, which cannot be 
used in Zope Python scripts for security reasons. The python code for the 
script consists of a class definition and so I have had to create a python 
function which instantiates an object of this class. However, I am having 
toruble passing parameters to this function which are needed by the 
class constructor to instantiate an object of this class. Can parameters 
be passed to external methods? Whenever I try to pass parameters to 
function 'createHtmlToPdf', Zope returns an error stating that no such 
function exists. Other on the hand, if I pass no parameters this call is 
successful but the init function fails complaining that three parameters 
are expected. I have provided a snippet of my code below. Any help would 
be greatly appreciated. Thanks.


- Asad



def createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile):
   return html2pdf(in_htmlFile, in_domain, in_pdfFile)

# This is based on a php script (c) Jason Rust [EMAIL PROTECTED]
# See that script for licensing
# Convert an HTML file to a PDF file using html2ps and ps2pdf

from tempfile import gettempdir, mkstemp
import os
import re
from re import IGNORECASE, DOTALL
from copy import copy

class html2pdf:
  def __init__(self, in_htmlFile, in_domain, in_pdfFile = None):
Constructor

in_htmlFile The full path to the html file to convert
in_domain The default domain name for images that have a relative path
in_pdfFile (optional) The full path to the pdf file to output. If not 
given then we create a temporary name.


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Passing Parameters to External Methods

2005-11-16 Thread Paul Winkler
On Wed, Nov 16, 2005 at 09:30:22AM -0500, Asad Habib wrote:
 Can parameters 
 be passed to external methods? 

Certainly.

 Whenever I try to pass parameters to 
 function 'createHtmlToPdf', Zope returns an error stating that no such 
 function exists. 

Can you provide us with the complete traceback?

-- 

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Passing Parameters to External Methods

2005-11-16 Thread J Cameron Cooper

Asad Habib wrote:
Hello. I am trying to use the Python version of the PHP script written 
by Jason Rust called 'HTML_ToPDF.php'. I have represented this script 
using an External Method since it uses functions, such as open, which 
cannot be used in Zope Python scripts for security reasons. The python 
code for the script consists of a class definition and so I have had to 
create a python function which instantiates an object of this class. 
However, I am having toruble passing parameters to this function which 
are needed by the class constructor to instantiate an object of this 
class. Can parameters be passed to external methods? Whenever I try to 
pass parameters to function 'createHtmlToPdf', Zope returns an error 
stating that no such function exists. Other on the hand, if I pass no 
parameters this call is successful but the init function fails 
complaining that three parameters are expected. I have provided a 
snippet of my code below. Any help would be greatly appreciated. Thanks.


 def createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile):
return html2pdf(in_htmlFile, in_domain, in_pdfFile)

Functions in external methods generally start with the 'self' parameter. 
Your description of the error messages doesn't entirely support my 
supposition, but you could try it.


--jcc
--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Passing Parameters to External Methods

2005-11-16 Thread Asad Habib

Hi Cameron. You are right but the self parameter is implicitly passed.

- Asad


On Wed, 16 Nov 2005, J Cameron Cooper wrote:


Asad Habib wrote:
Hello. I am trying to use the Python version of the PHP script written by 
Jason Rust called 'HTML_ToPDF.php'. I have represented this script using an 
External Method since it uses functions, such as open, which cannot be used 
in Zope Python scripts for security reasons. The python code for the script 
consists of a class definition and so I have had to create a python 
function which instantiates an object of this class. However, I am having 
toruble passing parameters to this function which are needed by the class 
constructor to instantiate an object of this class. Can parameters be 
passed to external methods? Whenever I try to pass parameters to function 
'createHtmlToPdf', Zope returns an error stating that no such function 
exists. Other on the hand, if I pass no parameters this call is successful 
but the init function fails complaining that three parameters are expected. 
I have provided a snippet of my code below. Any help would be greatly 
appreciated. Thanks.



def createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile):
   return html2pdf(in_htmlFile, in_domain, in_pdfFile)


Functions in external methods generally start with the 'self' parameter. Your 
description of the error messages doesn't entirely support my supposition, 
but you could try it.


--jcc
--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Passing Parameters to External Methods

2005-11-16 Thread J Cameron Cooper

Asad Habib wrote:

Hi Cameron. You are right but the self parameter is implicitly passed.


It is implicitly passed, but must be explicitly defined::

 def createHtmlToPdf(self, in_htmlFile, in_domain, in_pdfFile):
return html2pdf(in_htmlFile, in_domain, in_pdfFile)

When you say::

   context.createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile)

Python ends up calling this method/function something like::

   createHtmlToPdf(context, in_htmlFile, in_domain, in_pdfFile)

Your message signature must agree.

--jcc


On Wed, 16 Nov 2005, J Cameron Cooper wrote:


Asad Habib wrote:

Hello. I am trying to use the Python version of the PHP script 
written by Jason Rust called 'HTML_ToPDF.php'. I have represented 
this script using an External Method since it uses functions, such as 
open, which cannot be used in Zope Python scripts for security 
reasons. The python code for the script consists of a class 
definition and so I have had to create a python function which 
instantiates an object of this class. However, I am having toruble 
passing parameters to this function which are needed by the class 
constructor to instantiate an object of this class. Can parameters be 
passed to external methods? Whenever I try to pass parameters to 
function 'createHtmlToPdf', Zope returns an error stating that no 
such function exists. Other on the hand, if I pass no parameters this 
call is successful but the init function fails complaining that three 
parameters are expected. I have provided a snippet of my code below. 
Any help would be greatly appreciated. Thanks.




def createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile):
   return html2pdf(in_htmlFile, in_domain, in_pdfFile)



Functions in external methods generally start with the 'self' 
parameter. Your description of the error messages doesn't entirely 
support my supposition, but you could try it.


--jcc
--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )







--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Passing Parameters to External Methods

2005-11-16 Thread Paul Winkler
On Wed, Nov 16, 2005 at 11:26:10AM -0600, J Cameron Cooper wrote:
 Asad Habib wrote:
 Hi Cameron. You are right but the self parameter is implicitly passed.
 
 It is implicitly passed, but must be explicitly defined::
 
  def createHtmlToPdf(self, in_htmlFile, in_domain, in_pdfFile):
 return html2pdf(in_htmlFile, in_domain, in_pdfFile)
 
 When you say::
 
context.createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile)
 
 Python ends up calling this method/function something like::
 
createHtmlToPdf(context, in_htmlFile, in_domain, in_pdfFile)
 
 Your message signature must agree.

No, it's optional.  If you don't inlude self in the signature,
it's not passed.  You can see this in the source of ExternalMethod.py:

if ((self._v_func_code.co_argcount-
 len(self._v_func_defaults or ()) - 1 == len(args))
and self._v_func_code.co_varnames[0]=='self'):
return f(self.aq_parent.this(), *args, **kw)


I think the problem lies elsewhere. Traceback?

-- 

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Passing Parameters to External Methods

2005-11-16 Thread J Cameron Cooper

Paul Winkler wrote:

On Wed, Nov 16, 2005 at 11:26:10AM -0600, J Cameron Cooper wrote:


Asad Habib wrote:


Hi Cameron. You are right but the self parameter is implicitly passed.


It is implicitly passed, but must be explicitly defined::

def createHtmlToPdf(self, in_htmlFile, in_domain, in_pdfFile):
   return html2pdf(in_htmlFile, in_domain, in_pdfFile)

When you say::

  context.createHtmlToPdf(in_htmlFile, in_domain, in_pdfFile)

Python ends up calling this method/function something like::

  createHtmlToPdf(context, in_htmlFile, in_domain, in_pdfFile)

Your message signature must agree.



No, it's optional.  If you don't inlude self in the signature,
it's not passed.  You can see this in the source of ExternalMethod.py:

if ((self._v_func_code.co_argcount-
 len(self._v_func_defaults or ()) - 1 == len(args))
and self._v_func_code.co_varnames[0]=='self'):
return f(self.aq_parent.this(), *args, **kw)


I think the problem lies elsewhere. Traceback?


I thought I'd seen that work before, but didn't want to dip into asides.

Oh well. There goes my guess.

--jcc
--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Passing parameters to external methods is broken...

2000-09-14 Thread Chris Withers

Andreas Pauley wrote:
 I have an external method that looks (somewhat) like this:
 
 def extAccess(self, accttype_cde):
 return accttype_cde

 dtml-if "extAccess(accttype_cde='COM')"
   bThe external method returned true/b
 /dtml-if
 
 I get the following error for the above statement:
 Error Type: TypeError
 Error Value: not enough arguments; expected 2, got 0

Yup, been there, done that, the thread's in the zope-dev archive if
you're interested...

The way external methods handle parameters is 'interesting' to say the
least.
Your safest bet is just to use the REQUEST variable to pass stuff, as
someone else suggested.

cheers,

Chris

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




[Zope] Passing parameters to external methods

2000-09-13 Thread Andreas Pauley

Hi,
I need to pass some parameters to my external methods.

I have an external method that looks (somewhat) like this:

def extAccess(self, accttype_cde):
return accttype_cde

In the following dtml code, the following statement (with the SQL
method) works fine:

dtml-if "sqlAccess(accttype_cde='COM')"
 bsqlAccess returned something/b
/dtml-if

This statement, referencing my external method but using the same syntax
as with the sql method, gives lots of headaches:

dtml-if "extAccess(accttype_cde='COM')"
  bThe external method returned true/b
/dtml-if


I get the following error for the above statement:
Error Type: TypeError
Error Value: not enough arguments; expected 2, got 0


Anybody any ideas?

Thanks,
Andreas.

-- 
In a world without fences, who needs gates?


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Passing parameters to external methods

2000-09-13 Thread Andy McKay

Ive always sent through the REQUEST with no problem, dtml-var
"externalmethod(REQUEST)" if you can do that.

- Original Message -
From: "Andreas Pauley" [EMAIL PROTECTED]
To: "Zope" [EMAIL PROTECTED]
Sent: Wednesday, September 13, 2000 2:49 PM
Subject: [Zope] Passing parameters to external methods


 Hi,
 I need to pass some parameters to my external methods.

 I have an external method that looks (somewhat) like this:

 def extAccess(self, accttype_cde):
 return accttype_cde

 In the following dtml code, the following statement (with the SQL
 method) works fine:

 dtml-if "sqlAccess(accttype_cde='COM')"
  bsqlAccess returned something/b
 /dtml-if

 This statement, referencing my external method but using the same syntax
 as with the sql method, gives lots of headaches:

 dtml-if "extAccess(accttype_cde='COM')"
   bThe external method returned true/b
 /dtml-if


 I get the following error for the above statement:
 Error Type: TypeError
 Error Value: not enough arguments; expected 2, got 0


 Anybody any ideas?

 Thanks,
 Andreas.

 --
 In a world without fences, who needs gates?


 ___
 Zope maillist  -  [EMAIL PROTECTED]
 http://lists.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists -
  http://lists.zope.org/mailman/listinfo/zope-announce
  http://lists.zope.org/mailman/listinfo/zope-dev )



___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )