Ok, that worked!

I just changed the view like this:

from jinja2 import Template, Environment, PackageLoader
from webob import Response

def my_view(context, request):
    env = Environment(loader=PackageLoader('myproject', 'templates'))
    template = env.get_template('mytemplate.jinja2')
    result = template.render({'project':'MyProject', 'request':request})
    response = Response(result)
    return response


Seems that the biggest problem is that the project can't be created with
jython's paster, I created the project with CPython and then used it on
paster.


On Mon, Jan 4, 2010 at 4:37 PM, Chris McDonough <chr...@plope.com> wrote:

> It looks like Jinja2 has an optional "speedups" module that Jython is
> choking on:
>
> http://bitbucket.org/mitsuhiko/jinja2-main/src/tip/setup.py
>
> You might try checking Jinja2 out from bitbucket, commenting out the
> "features" stanza in its setup.py and installing it into your virtualenv (if
> you're using one; otherwise just globally) by hand (jython setup.py install
> I guess) before trying to install repoze.bfg.jinja2.  I suspect it might
> work after that.
>
> Yes, the "parser" module is related to the "ast" module (doesn't seem to be
> supported on non-CPython platforms).
>
> - C
>
>
> Diaz, Eduardo wrote:
>
>> Ok, I'm going to give it a try in a while for now, this is the problem
>> with jinja2, it needs to compile something
>>
>> easy_install -i http://dist.repoze.org/bfg/1.1/simple/ repoze.bfg.jinja2
>> Searching for repoze.bfg.jinja2
>> Best match: repoze.bfg.jinja2 0.5
>> Processing repoze.bfg.jinja2-0.5-py2.5.egg
>> repoze.bfg.jinja2 0.5 is already the active version in easy-install.pth
>>
>> Using
>> /home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg.jinja2-0.5-py2.5.egg
>> Processing dependencies for repoze.bfg.jinja2
>> Searching for Jinja2
>> Reading http://dist.repoze.org/bfg/1.1/simple/Jinja2/
>> Best match: Jinja2 2.1.1
>> Downloading http://dist.repoze.org/bfg/1.1/Jinja2-2.1.1.tar.gz
>> Processing Jinja2-2.1.1.tar.gz
>> Running Jinja2-2.1.1/setup.py -q bdist_egg --dist-dir
>> /tmp/easy_install-wxGcPq/Jinja2-2.1.1/egg-dist-tmp-eTzSIB
>> warning: no files found matching 'Makefile'
>> warning: no files found matching 'ez_setup.py'
>> warning: no previously-included files matching '*' found under directory
>> 'docs/_build/doctrees'
>> error: Setup script exited with error: Compiling extensions is not
>> supported on Jython
>>
>> The problem with chameleon is that jython doesn't have the parser module.
>>
>> Going to keep checking with other templating engines.
>>
>> On Mon, Jan 4, 2010 at 4:10 PM, Chris McDonough <chr...@plope.com<mailto:
>> chr...@plope.com>> wrote:
>>
>>    Diaz, Eduardo wrote:
>>
>>        That helps with the zcml problem but now, there is a problem
>>        with chameleon, is there another template language I can use?
>>
>>        This is the stack trace:
>>
>>        paster serve MyProject.ini Starting server in PID 8071.
>>        serving on 0.0.0.0:6543 <http://0.0.0.0:6543>
>>        <http://0.0.0.0:6543> view at http://127.0.0.1:6543
>>
>>        ----------------------------------------
>>        Exception happened during processing of request from
>>        (u'127.0.0.1', 53678)
>>        Traceback (most recent call last):
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/Paste-1.7.2-py2.5.egg/paste/httpserver.py",
>>        line 1062, in process_request_in_thread
>>           self.finish_request(request, client_address)
>>         File "/home/iamedu/Tools/jython2.5.1/Lib/SocketServer.py", line
>>        254, in finish_request
>>           self.RequestHandlerClass(request, client_address, self)
>>         File "/home/iamedu/Tools/jython2.5.1/Lib/SocketServer.py", line
>>        522, in __init__
>>           self.handle()
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/Paste-1.7.2-py2.5.egg/paste/httpserver.py",
>>        line 436, in handle
>>           BaseHTTPRequestHandler.handle(self)
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/Paste-1.7.2-py2.5.egg/paste/httpserver.py",
>>        line 436, in handle
>>           BaseHTTPRequestHandler.handle(self)
>>         File "/home/iamedu/Tools/jython2.5.1/Lib/BaseHTTPServer.py",
>>        line 316, in handle
>>           self.handle_one_request()
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/Paste-1.7.2-py2.5.egg/paste/httpserver.py",
>>        line 431, in handle_one_request
>>           self.wsgi_execute()
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/Paste-1.7.2-py2.5.egg/paste/httpserver.py",
>>        line 286, in wsgi_execute
>>           result = self.server.wsgi_application(self.wsgi_environ,
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/router.py",
>>        line 127, in __call__
>>           response = view_callable(context, request)
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/router.py",
>>        line 127, in __call__
>>           response = view_callable(context, request)
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/configuration.py",
>>        line 1656, in _bfg_requestonly_view
>>           response = rendered_response(renderer,
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/configuration.py",
>>        line 1533, in rendered_response
>>           result = renderer(response, {'view':view,
>>        'renderer_name':renderer_name,
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/chameleon_zpt.py",
>>        line 43, in __call__
>>           result = self.template(**system)
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/decorator.py",
>>        line 13, in __get__
>>           val = self.wrapped(inst)
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/chameleon_zpt.py",
>>        line 33, in template
>>           return PageTemplateFile(self.path, auto_reload=auto_reload)
>>         File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/chameleon_zpt.py",
>>        line 11, in __init__
>>           raise ImportError(why[0])
>>        ImportError: No module named parser
>>        ----------------------------------------
>>
>>        The source code where this happens says:
>>
>>        try:
>>           from chameleon.zpt.template import PageTemplateFile
>>        except ImportError, why: # pragma: no cover
>>           # Chameleon doesn't work on non-CPython platforms
>>           class PageTemplateFile(object):
>>               def __init__(self, *arg, **kw):
>>                   raise ImportError(why[0])
>>
>>        So I'm guessing that something needs to be compile with C, I
>>        tried jinja2 but I cannot even install it.
>>
>>
>>    It's not actually a compilation requirement problem; Chameleon has
>>    no dependencies that have (non-optional) C code.
>>
>>    The information in this traceback is obscured by the fact that bfg
>>    tries hard to be at least importable on platforms that don't support
>>    Chameleon.  You might  try changing:
>>
>>
>>       try:
>>           from chameleon.zpt.template import PageTemplateFile
>>       except ImportError, why: # pragma: no cover
>>           # Chameleon doesn't work on non-CPython platforms
>>           class PageTemplateFile(object):
>>               def __init__(self, *arg, **kw):
>>                   raise ImportError(why[0])
>>
>>    to:
>>
>>
>>    from chameleon.zpt.template import PageTemplateFile
>>
>>    .. to prevent BFG from hiding traceback information from you here.
>>
>>    I suspect the root cause may be due to the fact that Chameleon
>>    generates Python code using the "ast" module, which seems to
>>    typically only available in CPython.  Chameleon doesn't work on GAE
>>    for the same reason.  But the only way to know for sure is to see
>>    the "real" traceback.
>>
>>    I was going to suggest repoze.bfg.jinja2, but you say you can't even
>>    get Jinja2 to install.  You might just try using a templating system
>>    that's known to work on Jython.  I don't know one that is, because
>>    I've never used Jython, but you could try Genshi, Mako, or Cheetah.
>>     Then just use its API to generate strings to use in responses from
>>    within BFG, e.g. (assuming Mako works):
>>
>>      from mako.template import Template
>>      from webob import Response
>>
>>      def mako_view(request):
>>          template = Template(filename='/templates/template.mak')
>>          result = template.render(name=request.params['name'])
>>          response = Response(result)
>>          return response
>>
>>
>>    Instructions for creating a more tight binding between BFG and
>>    arbitrary templating languages (in the form of a "renderer", which
>>    can be used within view configuration) exists here:
>>
>> http://docs.repoze.org/bfg/1.2/narr/views.html#adding-and-overriding-renderers
>>
>>
>>        I'm going to see if I can do anything with the zcml problem
>>        meanwhile, it seems to me to be a problem with the jython's xml
>>        parsing.
>>
>>        Thanks a lot for your help, and if you have any suggestions I'll
>>        be glad to read them.
>>
>>
>>    Please let me know about how the above turns out, I'm interested in
>>    making this stuff work as widely as possible.
>>
>>    Thanks!
>>
>>    - C
>>
>>
>>
>>        On Mon, Jan 4, 2010 at 10:51 AM, Chris McDonough
>>        <chr...@plope.com <mailto:chr...@plope.com>
>>        <mailto:chr...@plope.com <mailto:chr...@plope.com>>> wrote:
>>
>>           OK... its possible that zope.configuration doesn't work for some
>>           reason under Jython; I don't know that anyone has tried it
>>        recently.
>>            I may give it a shot myself over the next week or so out of
>>        curiosity.
>>
>>           In the meantime, however, you can disuse "declarative" (ZCML)
>>        style
>>           configuration, which will subvert zope.configuration
>>        entirely.  To
>>           do so, change the body of the "app" function in run.py of the
>>           generated sample app from this:
>>
>>              def app(global_config, **settings):
>>                  """ This function returns a ``repoze.bfg`` application
>>           object.  It
>>                  is usually called by the PasteDeploy framework during
>>        ``paster
>>                  serve``"""
>>                  zcml_file = settings.get('configure_zcml',
>>        'configure.zcml')
>>                  config = Configurator(root_factory=get_root,
>>        settings=settings)
>>                  config.begin()
>>
>>                  config.load_zcml(zcml_file)
>>                  config.end()
>>                  return config.make_wsgi_app()
>>
>>           to:
>>
>>              def app(global_config, **settings):
>>                  """ This function returns a ``repoze.bfg`` application
>>           object.  It
>>                  is usually called by the PasteDeploy framework during
>>        ``paster
>>                  serve``"""
>>                  zcml_file = settings.get('configure_zcml',
>>        'configure.zcml')
>>                  config = Configurator(root_factory=get_root,
>>        settings=settings)
>>                  config.begin()
>>                  config.add_view(context=MyModel, view=my_view,
>>                                       renderer='templates/mytemplate.pt
>>        <http://mytemplate.pt>
>>           <http://mytemplate.pt>')
>>
>>                  config.add_static_view(name='static',
>>        path='templates/static')
>>                  config.end()
>>                  return config.make_wsgi_app()
>>
>>           Diaz, Eduardo wrote:
>>
>>               Yes, it does
>>
>>               :P
>>
>>
>>               On Mon, Jan 4, 2010 at 10:42 AM, Chris McDonough
>>               <chr...@plope.com <mailto:chr...@plope.com>
>>        <mailto:chr...@plope.com <mailto:chr...@plope.com>>
>>               <mailto:chr...@plope.com <mailto:chr...@plope.com>
>>        <mailto:chr...@plope.com <mailto:chr...@plope.com>>>> wrote:
>>
>>                  Diaz, Eduardo wrote:
>>
>>                      Ok, I think I know why this is happening,
>>
>>                      the exception raises in the _validate method of
>>        the Orderable
>>                      class, this is where it happends:
>>
>>                      if self.max is not None and value > self.max:
>>                         raise TooBig(value, self.max)
>>
>>                      Here, max is a ValidatedProperty it has a __set___
>>        method
>>               which
>>                      gives it a value, the problem with jython seems to
>>        be that it
>>                      isn't getting the value from the instance
>>        dictionary, so
>>               I came
>>                      up a workaround,
>>
>>                      I define the __get__ method in the
>>        ValidatedPropertyClass
>>               like this:
>>
>>
>>                      def __get__(self, inst, owner):
>>                         name, check = self._info
>>                         return inst.__dict__[name]
>>
>>                      And now the tests run ok:
>>
>>                      jython setup.py test -q
>>
>>                      running test
>>                      running egg_info
>>                      writing MyProject.egg-info/PKG-INFO
>>                      writing entry points to
>>        MyProject.egg-info/entry_points.txt
>>                      writing requirements to
>>        MyProject.egg-info/requires.txt
>>                      writing top-level names to
>>        MyProject.egg-info/top_level.txt
>>                      writing dependency_links to
>>               MyProject.egg-info/dependency_links.txt
>>                      reading manifest file
>> 'MyProject.egg-info/SOURCES.txt'
>>                      writing manifest file
>> 'MyProject.egg-info/SOURCES.txt'
>>                      running build_ext
>>                      .
>>
>>  ----------------------------------------------------------------------
>>                      Ran 1 test in 0.005s
>>
>>                      OK
>>
>>                      I know it is not elegant, and I'll submit a bug to
>>        the jython
>>                      developers... but for now, I want to go on and
>> there's
>>               another
>>                      problem with running the project, and here it is:
>>
>>                      paster serve MyProject.ini
>>                      Traceback (most recent call last):
>>                       File "/home/iamedu/Tests/jython/sys/bin/paster",
>>        line 7, in
>>                      <module>
>>                         sys.exit(
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteScript-1.7.3-py2.5.egg/paste/script/command.py",
>>                      line 84, in run
>>                         invoke(command, command_name, options, args[1:])
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteScript-1.7.3-py2.5.egg/paste/script/command.py",
>>                      line 123, in invoke
>>                         exit_code = runner.run(args)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteScript-1.7.3-py2.5.egg/paste/script/command.py",
>>                      line 123, in invoke
>>                         exit_code = runner.run(args)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteScript-1.7.3-py2.5.egg/paste/script/command.py",
>>                      line 218, in run
>>                         result = self.command()
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteScript-1.7.3-py2.5.egg/paste/script/serve.py",
>>                      line 275, in command
>>                         app = self.loadapp(app_spec, name=app_name,
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteScript-1.7.3-py2.5.egg/paste/script/serve.py",
>>                      line 311, in loadapp
>>                         return loadapp(
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteDeploy-1.3.3-py2.5.egg/paste/deploy/loadwsgi.py",
>>                      line 204, in loadapp
>>                         return loadobj(APP, uri, name=name, **kw)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteDeploy-1.3.3-py2.5.egg/paste/deploy/loadwsgi.py",
>>                      line 225, in loadobj
>>                         return context.create()
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteDeploy-1.3.3-py2.5.egg/paste/deploy/loadwsgi.py",
>>                      line 625, in create
>>                         return self.object_type.invoke(self)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteDeploy-1.3.3-py2.5.egg/paste/deploy/loadwsgi.py",
>>                      line 110, in invoke
>>                         return fix_call(context.object,
>>        context.global_conf,
>>                      **context.local_conf)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteDeploy-1.3.3-py2.5.egg/paste/deploy/util/fixtypeerror.py",
>>                      line 57, in fix_call
>>                         val = callable(*args, **kw)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/PasteDeploy-1.3.3-py2.5.egg/paste/deploy/util/fixtypeerror.py",
>>                      line 57, in fix_call
>>                         val = callable(*args, **kw)
>>                       File
>>        "/home/iamedu/Tests/jython/MyProject/myproject/run.py",
>>                      line 11, in app
>>                         config.load_zcml(zcml_file)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/repoze.bfg-1.2a10-py2.5.egg/repoze/bfg/configuration.py",
>>                      line 424, in load_zcml
>>                         xmlconfig.file(filename, package, execute=True)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/xmlconfig.py",
>>                      line 647, in file
>>                         include(context, name, package)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/xmlconfig.py",
>>                      line 546, in include
>>                         processxmlfile(f, context)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/xmlconfig.py",
>>                      line 378, in processxmlfile
>>                         parser.parse(src)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/xmlconfig.py",
>>                      line 378, in processxmlfile
>>                         parser.parse(src)
>>                       File
>>
>>  "/home/iamedu/Tools/jython2.5.1/Lib/xml/sax/drivers2/drv_javasax.py",
>>                      line 141, in parse
>>                         self._parser.parse(JyInputSourceWrapper(source))
>>                       File
>>
>>  "/home/iamedu/Tools/jython2.5.1/Lib/xml/sax/drivers2/drv_javasax.py",
>>                      line 178, in startElement
>>                         self._cont_handler.startElementNS((uri or None,
>>               lname), qname,
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/xmlconfig.py",
>>                      line 230, in startElementNS
>>                         self.context.begin(name, data, info)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/config.py",
>>                      line 534, in begin
>>
>> self.stack.append(self.stack[-1].contained(__name, __data,
>>                      __info))
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/config.py",
>>                      line 835, in contained
>>                         return RootStackItem.contained(self, name,
>>        data, info)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/config.py",
>>                      line 703, in contained
>>                         factory = self.context.factory(self.context, name)
>>                       File
>>
>>  
>> "/home/iamedu/Tests/jython/sys/Lib/site-packages/zope.configuration-3.6.0-py2.5.egg/zope/configuration/config.py",
>>                      line 480, in factory
>>                         raise ConfigurationError("Unknown directive",
>>        ns, n)
>>
>>  zope.configuration.xmlconfig.ZopeXMLConfigurationError: File
>>
>>  "file:///home/iamedu/Tests/jython/MyProject/myproject/configure.zcml",
>>                      line 10.8
>>                         ConfigurationError: ('Unknown directive',
>>                      u'http://namespaces.repoze.org/bfg', u'view')
>>
>>
>>                  An obvious thing to check first.. does:
>>
>>                  <include package="repoze.bfg.includes"/>
>>
>>                  Come after the first <configure> tag but before any other
>>               directive
>>                  in myproject/configure.zcml?  Is this the bare
>>        configure.zcml
>>               file
>>                  generated by the paster template or have you made
>> changes?
>>
>>                  - C
>>
>>
>>
>>
>>
>>
>>
>
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to