Giter VIP home page Giter VIP logo

nevow's Introduction

Divmod Nevow

Divmod Nevow is a web application construction kit written in Python. It is designed to allow the programmer to express as much of the view logic as desired in Python, and includes a pure Python XML expression syntax named stan to facilitate this. However it also provides rich support for designer-edited templates, using a very small XML attribute language to provide bi-directional template manipulation capability.

Nevow also includes Divmod Athena, a "two way web" or "COMET" implementation, providing a two-way bridge between Python code on the server and JavaScript code on the client. Modular portions of a page, known as "athena fragments" in the server python and "athena widgets" in the client javascript, can be individually developed and placed on any Nevow-rendered page with a small template renderer. Athena abstracts the intricacies of HTTP communication, session security, and browser-specific bugs behind a simple remote-method-call interface, where individual widgets or fragments can call remote methods on their client or server peer with one method: "callRemote".

Installation

Before installing Nevow, you should install Twisted, unless you are going to write very simple CGI applications. Nevow integrates fully with the twisted.web server providing easy deployment.

Nevow uses the standard distutils method of installation:

python setup.py install

If you do not have Twisted installed, you can run a subset of the tests using the test.py script. If you have twisted installed, the test.py script will issue the following trial command:

trial -v nevow.test formless.test

Documentation

More detailed introductory documentation is available in the doc/ directory, along with the beginnings of a reference manual. A large number of examples are available in the examples/ directory. These examples require Twisted to run. A tac file (twisted application configuration) can be started by invoking twistd, the twisted daemon:

twistd -noy foo.tac

More Information

Information about Nevow commits is available on GitHub. The Nevow git repository can be checked out using:

git clone https://github.com/twisted/nevow.git

Discussion of Nevow occurs on the twisted.web mailing list. The Nevow developers are also often available for real-time help on the #twisted.web channel on irc.freenode.net.

nevow's People

Contributors

exarkun avatar glyph avatar hawkowl avatar jonathanj avatar mithrandi avatar multani avatar wthie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nevow's Issues

`import nevow` prints a UserWarning

.../zope/interface/interface.py:548: UserWarning: Hashing uninitialized InterfaceClass instance
  warnings.warn('Hashing uninitialized InterfaceClass instance')

This happens because importing nevow imports formless, and formless constructs its own InterfaceClass instances, and then uses them as keys in a dictionary, and doesn't give them __name__ and __module__ attributes.

_athenaDetachClient detaches only every other client

The code in Athena/init.js at line 1130 detaches only every other client

for (var i = 0; i < self.childWidgets.length; ++i) {
self.childWidgets[i]._athenaDetachClient();

Possible fix by creating a copy of the widgets list could be:

    var childWidgets = self.childWidgets.slice();   //copy self.childWidgets, it will be modified by removeChildWidget

    for (var i = 0; i < self.childWidgets.length; ++i)  {
        childWidgets[i] = self.childWidgets[i];
    }
    for (var i = 0; i < childWidgets.length; ++i)  {
        childWidgets[i]._athenaDetachClient();

This is a bug for which I submitted the above fix and necessary test when divmod.org was still active
How do I proceed?

Thxs, Werner


Imported from Launchpad using lp2gh.

`connectionMade` is sometimes called too late

If the initial transport request contains messages (eg. remote calls), these will be processed before connectionMade is invoke, resulting in inconsistent ordering of events (you might have an exposed method called before any initialization in connectionMade has happened).

Divmod.Class.methods() requires defining methods in a way that leaks global names in IE

Currently the suggested way of defining methods is:

Divmod.Class.subclass(Some.Namespace, 'ClassName').methods(
  function setAttribute(self, some, arguments) {
    // Do some work.
  }
);

Unfortunately earlier versions of Internet Explorer's JScript implementation have the annoying property of leaking named function expressions into the enclosing scope, which in this case happens to be the global one. See http://kangax.github.io/nfe/#jscript-bugs for more horrors.

This became apparent after a long debugging session where the Nevow browser platform implementations define a setAttribute method which leaks into the global namespace becoming window.setAttribute and in turn interfering with the operation of some modern Javascript libraries.

A solution we used in a private fork was introducing an API like:

Divmod.Class.subclass(Some.Namespace, 'ClassName').namedMethods({
  setAttribute: function(self, some, arguments) {
    // Do some work.
  }
});

Use python-versioneer for version number management

python-versioneer removes the need to import version information in setup.py from the python package being packaged (something which fails in many contemporary build/install environments). It also avoids the need to specify the version information in more than one place.

launchpad project should link to the code

Clicking "Code" and then on the only available source link, there's a page which says "import invalid" and "This branch is an import of the Subversion branch from http://divmod.org/svn/Divmod/trunk/Nevow." - but that link is a 404.

There is a copy of the source at https://pypi.python.org/pypi/Nevow , but it lacks revision control history.


Imported from Launchpad using lp2gh.

deprecation warning in appserver.NevowRequest

When I enable deprecation warnings in my tests (Tahoe-LAFS, using Nevow-0.11.1 and Twisted > 13.2), I get a warning from nevow:

.../Nevow-0.11.1-py2.7.egg/nevow/appserver.py:129: DeprecationWarning: twisted.web.http.Request.received_headers was deprecated in Twisted 13.2.0: Please use twisted.web.http.Request.requestHeaders instead.

It looks like nevow.appserver.NevowRequest.process is doing:

    self.fields = cgi.FieldStorage(self.content, self.received_headers,
                                   environ={'REQUEST_METHOD': 'POST'})

and Twisted doesn't like that anymore. received_headers provided a dict, which was lossy but convenient for cgi.FieldStorage. requestHeaders is not a dict, and will probably need some new code to transform it into a form that cgi.FieldStorage likes.

deprecation warning in addSlash redirects

While investigating https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2312 , I found that Nevow-0.11.1 plus Twisted-13.0.0 plus python-2.6 can provoke an annoying DeprecationWarning, if you use a nevow.rend.Page with addSlash = True and then render the page in a way that forces a redirect to self-plus-slash.

It looks like twisted.web.http.Request.setHeader() used to accept anything string-able, but now insists upon actual "bytes" objects (probably to avoid confusing unicode errors), and emits a DeprecationWarning if it gets otherwise. We had one place in Tahoe where we used req.setHeader("content-length", len(body)), which ran afoul of this.

But there's another one in nevow itself, in nevow.rend.Page._renderHTTP, where the addSlash behavior is implemented with:

request.redirect(request.URLPath().child(''))

That passes a URL object into setHeader("location", url), which triggers the same warning. I haven't tried making a short proof-of-concept, or tried running Nevow's tests against py2.6.

We don't see this when testing under python2.7, probably because 2.7 does something foolish like disabling all DeprecationWarnings. I haven't done exhaustive testing, but if that's really true, I suspect it'll be a big problem for libraries that want to signal their own deprecations to higher-layer apps (Twisted uses DeprecationWarnings extensively).

I think the fix will be to replace that code in _renderHTTP with something like:

request.redirect(str(request.URLPath().child('')))

Test actual package installation continuously

The current travis-ci configuration does pip install --editable ....

This means nothing is really installed. It's just a trick with a pth file or something.

We want Nevow to actually be installable. Probably from an sdist or a wheel. Build these and install them and run the tests against the result. On travis.

nevow cannot be installed with pip into a clean virtualenv

The problem is that Nevow imports nevow._version in setup.py which imports twisted. In the setuptools world Nevow should put "twisted" in setup_requires, but setup_requires doesn't actually work with pip because the first thing pip does on downloading is run setup.py egg_info which doesn't work if Twisted is not installed...


Imported from Launchpad using lp2gh.

easy_install will install a package that is already there

Binary package hint: python-setuptools

This bug in Debian sid:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=475440

Has now been added to Ubuntu, in Hardy. I confirmed that the bug stops happening when you uninstall the python-setuptools package that comes with Ubuntu Hardy and install the same version of python-setuptools from upstream then the problem does not happen.


Imported from Launchpad using lp2gh.

Expose browser-generated events to Athena event handlers

There is currently no way to access the event object from an Athena event handler. Quirksmode has a lot of information [1] that can be useful for implementing this in the "inline event handler" model that Athena currently employs.

It would be worth wrapping the event objects to expose a useful subset of functionality in a cross-browser way.

[1] http://www.quirksmode.org/js/events_access.html#link6


Imported from Launchpad using lp2gh.

Athena transport duplicate message

What information is this logged message supposed to convey?

Looking at the code it seems like there are some cases where an old message is trying to be retransmitted but I don't fully understand why this would occur. Is this just normal operation or is it an issue that should be resolved?

Either way, currently our logs are absolutely flooded with this message and it doesn't provide any benefit. Can it be removed or resolved, if it is in fact a bug?

Nevow should handle interrupted HTTP responses

(This is copied from the mailing list. I enclose a patch, which includes a unit test.)

J.P's excellent article http://jcalderone.livejournal.com/50890.html
explains how to avoid calling Request.finish() on a request after its
connection was lost, because that now raises an exception. The code in
the article is able to avoid calling finish() because it handles the
rendering itself. The call to finish() is right there in _delayedRender.
But I'm using Nevow (because it's awesome) and all that stuff is done
behind the scenes, where I can't get to it.

My application has a form, which uses the Post/Redirect/Get pattern
(http://en.wikipedia.org/wiki/Post/Redirect/Get) to avoid
double-posting. Because processing is not instant, the browser receives
the HTTP header telling it to redirect before the processing has
finished. When the processing finishes, the Deferred embedded in the web
page fires with a value, Stan finishes flattening the page, and Nevow
calls Request.finish(). By then the browser has closed the connection
and sent in the GET request. So I get an error every single time.
Any page that uses Deferreds and redirects will do as well.

This is a completely self-contained example, to be run with twistd:

from nevow import tags, inevow, loaders, appserver
from nevow.rend import Page
from nevow.url import URL
from twisted.internet.task import deferLater
from twisted.internet import reactor
from twisted.application import service
from twisted.application.internet import TCPServer
from twisted.web import http

class Redirector(Page):

count = 0
message = 0

def _increment(self):
    self.count += 1
    return self.count

def slow_operation(self):
    return deferLater(reactor, 3, self._increment)

def beforeRender(self, ctx):
    req = inevow.IRequest(ctx)
    if req.method == 'POST':
        oldurl = URL.fromContext(ctx)
        newurl = oldurl.remove('cmd')
        req.setResponseCode(http.SEE_OTHER)
        req.setHeader("Location", newurl)
        self.message = self.slow_operation()

def render_message(self, ctx, data):
    return self.message

docFactory = loaders.stan(
    tags.html[
        tags.head[tags.title['Slow page']],
        tags.body[
            tags.h1['Problem with interrupted connections'],
            tags.form(method='post', action='')[
                tags.button(type='submit', name='cmd',
                value='click')[
                    'Click'
                    ]
                ],
            tags.p(render=tags.directive('message'))
            ]
        ]
    )

application = service.Application('Demo')

site = appserver.NevowSite(Redirector())
webservice = TCPServer(8123, site)
webservice.setName('WUI')
webservice.setServiceParent(application)


Imported from Launchpad using lp2gh.

Remove htmlfile/htmlstr

These were deprecated in 0.8, which was a long long time ago; also, they're really horrible, and nobody should use them ever. I think it's time to finally remove them.


Imported from Launchpad using lp2gh.

nevow.test.test_appserver.Logging.test_oldStyle fails

Against Twisted 14.0.0:

Traceback (most recent call last):
  File "/home/travis/build/twisted/nevow/nevow/test/test_appserver.py", line 187, in test_oldStyle
    proto = self.renderResource('/foo')
  File "/home/travis/build/twisted/nevow/nevow/test/test_appserver.py", line 170, in renderResource
    assert proto.transport.disconnecting
exceptions.AssertionError: 

`undefined` should probably be handled in the same way as `null` by the JSON parser

In Javascript the natural return value of a function is undefined but the Nevow JSON parser does not understand undefined and often this comes up as an issue where a remote call chain ends without needing to specify a return value.

It's not terribly convenient to add return null everywhere to begin with but causing a server-side error, which is then sent to the client and subsequently disconnects them with a rather obscure traceback, is not terribly useful behaviour.

The JSON parser might as well treat undefined the same way as null.

Put nevow.taglibrary.tabbedPane back

This was accidentally removed along with livepage, but it's really an Athena thing, not a livepage thing, and Mantissa actually uses it. We can deprecate it, though.

Remove `nevow.livepage`

nevow.livepage is documented as "Previous generation Nevow Comet support. Do not use this module.". It has seen no significant maintenance since 2006. It is redundant with nevow.athena at least. It may be broken (#48) and misleading to potential users.

It hasn't actually be deprecated in the sense that it emits a deprecation warning if you use it. I think the warning in the module docstring and the narrow audience of Nevow may mean it's okay to just remove it.

Unable to get property 'length' of undefined or null reference

When the Athena message transport is stopped self.requests is set to null which causes breakage in several places expecting to be able to iterate it. The reason these iterations are happening is usually because the transport changed state half way through the processing of a request.

why does Nevow depend on Twisted >= 13.0?

Dear folks:

According to

nevow/setup.py

Line 90 in 4643891

install_requires=[
, Nevow requires Twisted >= 13.0. Here's the patch that added the declaration of dependency on Twisted: 0eb20bb

Do you know if there's any reason it wouldn't work for us to use Nevow 0.11.1 with Twisted == 11.0.0, == 11.1.0, == 12.0.0, == 12.1.0? Those are versions of Twisted that our users are currently able to install on Windows: tahoe-lafs/tahoe-lafs@d888b28 (due to https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2028 (Twisted endpoints introduce a dependency on pywin32) and http://twistedmatrix.com/trac/ticket/6032 (make twisted.internet.endpoints importable on Windows when pywin32 is not installed)).

The requirement Nevow imposes for Twisted >= 13.0 is also causing a different install problem for a user on Mac OS X: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2249# OSX: Installed distribution Twisted 12.2.0 conflicts with requirement twisted>=13.0

Installing python-nevow breaks twisted trial

After installing python-nevow, the "trial" test utility provided by python-twisted-core fails with the following error message:

Traceback (most recent call last):
File "/usr/bin/trial", line 23, in
from twisted.scripts.trial import run
ImportError: No module named scripts.trial

Investigation reveals that the culprit is an empty "init.py" file generated by the nevow installation. This file is placed in /var/lib/python-support/python2.5/twisted/plugins. The existence of that file breaks twisted's plugin finding approach and causes it to fail to find the twisted.scripts package, which is actually located at /usr/share/pyshared/twisted/scripts.

I can't see how this file gets generated

Source package: nevow
Ubuntu release: Ubuntu 8.04.3 LTS
Package versions: python-nevow: 0.9.26-1, python-twisted-core: 2.5.0-2build2, python2.5: 2.5.2-2ubuntu6


Imported from Launchpad using lp2gh.

nevow.json serializes some line terminators such that Athena cannot deserialize them in the browser

JSON encoded bytes may include literal (that is, UTF-8 encoded) U+2028 or U+2029. However, JavaScript string literals may not. See http://timelessrepo.com/json-isnt-a-javascript-subset for any more detail that may be interesting.

Athena's JavaScript parser (browser-side JavaScript eval) cannot parse these literals. If we emit escaped versions of the line terminators, the parser won't need to change.


Imported from Launchpad using lp2gh.

Get rid of nevow.json

There are plenty of json libraries around now. Most of them even support customization for encoding arbitrary objects (such as Nevow's Elements).

Nevow doesn't need to supply its own anymore.

liveglue.js need to cut out anchors too

Hi!

I am using Nevow and it's pretty cool. But I encountered a bug with liveglue.js

I am using '#' in hrefs for dynamic contents, so it makes urls like http://host/path#
That is ok, but if user reloads page, liveglue reinitializes and makes all live requests URIs like http://host/path#/livepage_client/... which is completely broken.

Simply added this code to liveglue.js

var anchorIndex = base_url.indexOf('#');
if (anchorIndex != -1) {
base_url = base_url.substring(0, anchorIndex);
}

and everything works.


Imported from Launchpad using lp2gh.

IE11triggers Netscape runtime selection due to false UA string

IE11 identifies itself as

'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'

which leads subsequently to the wrong assumption of the DivMod UA detection code, that the browser runtime should be set to Firefox with XPath capabilities being present. The error manifests itself by IE11 stating, that XPathResult is undefined.

A possible fix is expanding the test for IE to test for 'Netscape' and no XPathNamespace defined, while the actual 'Netscape' type browser Firefox would then have XPathNamespace defined.

For an explanation of the UA strings used by IE11, please see:
http://blogs.msdn.com/b/ieinternals/archive/2013/09/21/internet-explorer-11-user-agent-string-ua-string-sniffing-compatibility-with-gecko-webkit.aspx


Imported from Launchpad using lp2gh.

Test failure on Twisted 13.2 (and probably earlier)

PR #30 changed the log message format in nevow.test.test_appserver.Logging.test_oldStyle to match the format in Twisted 14.0. Unfortunately, this does not match the format used in earlier versions of Twisted, leading to this test failure:

[FAIL]
Traceback (most recent call last):
  File "/«PKGBUILDDIR»/debian/python-nevow/usr/lib/python2.7/site-packages/nevow/test/test_appserver.py", line 193, in test_oldStyle
    ['"fakeaddress2" - - faketime "GET /foo HTTP/1.0" 200 6 '
  File "/usr/lib/python2.7/dist-packages/twisted/trial/_synctest.py", line 356, in assertEqual
    % (msg, pformat(first), pformat(second)))
twisted.trial.unittest.FailTest: not equal:
a = ['fakeaddress2 - - faketime "GET /foo HTTP/1.0" 200 6 "fakerefer" "fakeagent"']
b = ['"fakeaddress2" - - faketime "GET /foo HTTP/1.0" 200 6 "fakerefer" "fakeagent"']


nevow.test.test_appserver.Logging.test_oldStyle

Release 0.11

Apart from having moved to Github and the various changes this has entailed (changing how the version number is managed, setting up continuous integration, fixing the test suite against recent Twisted versions), there are also a bunch of fixes made since 0.10 which was almost five years ago. It's time!

Some tests are dependant on Python's hashing randomization

The problem basically is:

gourami:~/.../nevow$ trial nevow.test.test_flatsax.Basic.test_otherns                
nevow.test.test_flatsax
  Basic
    test_otherns ...                                                       [OK]

-------------------------------------------------------------------------------
Ran 1 tests in 0.017s

PASSED (successes=1)


gourami:~/.../nevow$ PYTHONHASHSEED=42 trial nevow.test.test_flatsax.Basic.test_otherns
nevow.test.test_flatsax
  Basic
    test_otherns ...                                                     [FAIL]

===============================================================================
[FAIL]
Traceback (most recent call last):
  File ".../nevow/nevow/test/test_flatsax.py", line 184, in test_otherns
    self.failUnlessEqual(xml, flatten(parseString(xml)))
  File "/usr/lib/python2.7/dist-packages/twisted/trial/_synctest.py", line 356, in assertEqual
    % (msg, pformat(first), pformat(second)))
twisted.trial.unittest.FailTest: not equal:
a = '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"><p>in default namespace</p><xf:input><xf:label>in another namespace</xf:label></xf:input></html>'
b = '<html xmlns:xf="http://www.w3.org/2002/xforms" xmlns="http://www.w3.org/1999/xhtml"><p>in default namespace</p><xf:input><xf:label>in another namespace</xf:label></xf:input></html>'


nevow.test.test_flatsax.Basic.test_otherns
-------------------------------------------------------------------------------
Ran 1 tests in 0.017s

FAILED (failures=1)

This means that some tests will break some because they depend on some ordering which is not stable . This currently blocks #47 since Tox sets a different hash seed for each run and the probability of getting the "right" seed is probably very low.

I would propose to hunt down the places where such ordering is not guaranteed and use sorted() or something appropriate to fix the problem. (The fix for this test case is too wrap this iteritems() into sorted()). This will make the output more predictable obviously, ease the tests as the tester can expect to have a reliable output, but it has a slight cost performance though.

Other possibilities that I can think of:

  • change the tests so they are smarter: instead of doing a basic string equality (or a assert expected in result as I saw in other failing tests where expected content is not in the same order as the one in result), parse the result (they are XML-like strings each times) and assert that the structure is properly formed.
  • find the right hash :) (and set it somewhere once and for all, like this for Tox.

evalAfterDone arg from nevow_closeLive does not run

Hi,

Nevow is used in the eXeLearning project; I've been working on upgrading it from the ancient version it used before. I think there is a mistake in how the nevow_closeLive function is written:

The function takes an arg by the name of evalAfterDone - which looking at the implementation of nevow_clientToServerEvent is a javascript function that runs after the clientToServerEvent is done, regardless of the result and is not passed to the server.

But in the implementation of nevow_closeLive evalAfterDone is the third parameter, not the second. This results in the evalAfterDone argument being passed to the server as an argument and not treated as evalAfterDone by the nevow_clientToServerEvent function. As far as I can see:

nevow_clientToServerEvent('close', '', evalAfterDone)

Should actually be:

nevow_clientToServerEvent('close', evalAfterDone, '')
or just:
nevow_clientToServerEvent('close', evalAfterDone)

Perhaps I have missed something about how the close event is supposed to be handled... but it seems strange that this argument would be called the same thing in both functions and then switch around.

Will look forward to finding out if this is the case or if I have after reading the docs in livepage misunderstood how close is supposed to work.

Thanks,

-Mike

AttributeError: 'MetaTypedInterface' object has no attribute '__name__'

This is with Nevow 0.10.0 and zope.interface 3.6.4. David-Sarah Hopwood and Drew Perttula each independently reported this error. (I haven't seen it personally, I'm just reporting what they posted.) Drew included a patch to zope.interface work-around it:

http://drewp.quickwitretort.com/2011/07/08/0

http://codepad.org/wd1UUnhh


Imported from Launchpad using lp2gh.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.