[Zope3-Users] How do I get the value of security proxied attributes from a view template
Hi, list, I am just trying to migrate a existing application from Zope2 to Zope3, and had to feel around for my ways to do things correctly. I have following view.pt snippet: Item Name specification: Price: The template is registered like this: What I get is output looking this: 卡朗妮专供出口环保型虹吸式连体座便器(坑距300mm) specification: 720x370x630mm Price: What does the last line mean? How can I get the numeric value for the item's price? I defined the three attributes of the item identically, why only the price is security proxied? Following is the interface definition: class IItem(ISQLAlchemyObjectContained): """Information about an item""" item_name = zope.schema.TextLine( title=_(u'Item Name'), description=_(u'Name of the item'), required=True) specification = zope.schema.TextLine( title=_(u'Item Specification'), description=_(u'Specification of the item'), required=True) sales_price = zope.schema.Float( title=_(u'Sales Price'), description=_(u'Sales price of the item'), required=True) For your information, I am using z3c.zalchemy to retrieve the item object from RDB. Has it anything to do with the security proxy? Best Regards, -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Database authentication service
Hi, everyone, This must be novice question: Is there a package providing relational database based authentication service for zope 3 already lying around somewhere or do I have write one? And how does one connect a login form with the authentication service? In Zope 2 one can have lots products to choose from, like exUserFolder and CookieCrumbler etc. How does one do this with Zope 3? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] How do I get the value of security proxied attributes from a view template
On 8/24/07, Andreas Reuleaux <[EMAIL PROTECTED]> wrote: > from zope.security.proxy import removeSecurityProxy > > price=removeSecurityProxy(proxiedPrice) > > Yes, it works fine. Thanks. However it would mean that I have to add a view class to all my objects which contains a decimal attribute, and add removeSecurityProxy to all decimal attributes that I wish to present through the web? That would be too much unnecessary duplicate code, since I am trying to build a web shop with Zope3, in which the decimal type is almost everywhere. I read in several places that the Security Proxy is supposed only to wrap mutable objects. Integer and float for example shall not to be proxied. But a decimal.Decimal is also immutable, why is it wrapped then? Is there an easier way to go around this, like to tell security proxy not to wrap all decimal objects? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How
Hi, everyone: In my page template, I would like to show one message if the request is authenticated, and other if the user has not logged in. Is there a simple test I can use in the template file like? Please Log In Hello Mr. XXX Similiar thing used to work with Zope2. But with Zope3, request only has an attribute 'principal', which will return a object. I have seen code doing verification in the view class like this: if (not IUnauthenticatedPrincipal.providedBy(request.principal): ... But surely there will be a much simpler way to do this? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How is ++debug++tal supposed to work?
Hi, everyone In the book "Web Component Development with Zope 3", it is mentioned that one can use the URL adapter ++debug++tal to show the tal tags besides the rendered page, provided the devmod is turned on. But how is this working exactly? For I can not see the URL adapter taking any effects. I have for example a simple test page test.html: And I am accessing it like this: http://localhost:9673/++debug+tal/test.html. But the result is the exactly the same as when I access http://localhost:9673/test.html. The same goes with ++debug++source. I wonder whether I have misunderstood the function of these two URL adapters? Best Regards -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How to assign a role or permission to users programatically?
Dear list, I have written a custom authenticator plugin to authenticate users against a Postgres database. The question is, once a user is authenticated, what role or permission does she/he get? If I would like to give the permission 'site.MemberPermission' to all users when they log in. I don't want to store the permission a a persistent folder like object, but just assign them on the fly when the log in. what shall I do? Thanks for helping. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Problem with z3c.form security when rendering error
HI, list: I am new to z3c.form. In my first AddForm, I encountered the following problem: When the form is submitted which contains some input error, like missing required fields, the rendering of the error message causes an system error. The traceback: ... File "/usr/lib/python2.5/site-packages/zope.app.pagetemplate-3.4.0b1dev_r75616-py2.5.egg/zope/app/pagetemplate/engine.py", line 68, in __call__ request=request) File "/usr/lib/python2.5/site-packages/zope.traversing-3.5.0a1.dev_r78730-py2.5.egg/zope/traversing/adapters.py", line 164, in traversePathElement return traversable.traverse(nm, further_path) - __traceback_info__: (, 'widget') File "/usr/lib/python2.5/site-packages/zope.traversing-3.5.0a1.dev_r78730-py2.5.egg/zope/traversing/adapters.py", line 52, in traverse raise TraversalError(subject, name) - __traceback_info__: (, 'widget', []) TraversalError: (, 'widget') After a little debugging, I was able to find that the chain leading to the error is as follows: 1. div-form.pt in the z3c.formui package contains the following error presentation: : Error Type error/widget is accessed here, with error being an ErrorViewSnippet object. 2. The ErrorViewSnipped is created in field.py using: view = zope.component.getMultiAdapter( (error, self.request, widget, widget.field, self.form, self.content), interfaces.IErrorViewSnippet) As in my application, self.content is a custom ISite folder, which is security proxied, the getMultiAdapter method returns a security proxied ErrorViewSnippet object. 3. Access to ErrorViewSnippet is defined in z3c.form/configure.zcml as: The IErrorViewSnippet interface contains only 3 attributes: error, update, render. Those are accessible to everyone. But there is no security declaration for the 'widget' attribute, so access to it is denied: (Pdb) snippet (Pdb) type(snippet) (Pdb) from zope.security.proxy import getChecker (Pdb) getChecker(snippet).get_permissions {'update': Global(CheckerPublic,zope.security.checker), 'render': Global(CheckerPublic,zope.security.checker), 'error': Global(CheckerPublic,zope.security.checker)} (Pdb) from zope.security import canAccess (Pdb) canAccess(snippet, 'widget') *** ForbiddenAttribute: ('widget', ) So it seems the default z3c.form security declaration only allows access to 'update', 'error' and 'render' attributes of an ErrorViewSnippet object. I tried to work this around the by adding the 'widget' attribute to the IErrorViewSnippet interface and the system error is no longer raised. However, this time, another exception is raised saying the 'label' property of the widget is not accessible. How can I setup my security properly to use z3c.form smoothly? Shouldn't 'widget' not be in IErrorViewSnippet since it is evidently externally used in the rendering template? Thanks for suggestions. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] zopeproject Exception debugging
Hello, In the 'Debugging' section of zopeproject's project page, the following is mentioned for the ajax based exception debugging: When you now repeat the steps that led to the exception, you will see the relevant traceback in your browser, along with the ability to view the corresponding source code and to issue Python commands for inspection. However, after an exception, I can only see the traceback and code segments displayed in the browser. How can I issue Python commands for further inspection? Thanks, -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Several points about z3c.form internationalization
Hi, list I stumbled upon several problems with i18n of z3c.form and z3c.formui and would like to have advice from the more experienced. 1. I have a schema field: gender = Choice( title=_(u'Gender'), values=(_(u'male'), _(u'female')), required=False) When rendered, the choice 'male' and 'female' are not translated though they are defined in the catalog. Why is that? 2. In the form heading there is a lengend for the required filed indicator: * - required The code in div-form.pt is not internationalized: * – required I tried a modification as this: * – required But it doesn't seem to work. Using ++lang++test, the string 'required' is not marked as translatable. Only after I specify the translation domain of my application did it show up as translatable: required Since in my main layout template I have already specified my translation domain, I expect it to be inherited in div-form.pt since this template doesn't sepcifiy it's own translation domain. How to mark this piece of text translatable? And in which domain shall I do the translation? Best Regards -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Does zope cache authentication?
Hi, I have written a custom authenticator in my application to authenticate a login against a PostgreSQL database. In the site I have configured a PAU with a session credentials plugin and my custom authenticator plugin. I found out that with configuration, EVERY browser request is triggering my custom authenticator, which means a query of the database. I'd rather expect only the first login will send a database request, and before one logs out, subsequent requests will no longer be authenticated. Does the PAU have a mechanism to cache the authentication before the user is logged out? Otherwise the authentication would be a highly inefficient process. Thanks, -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Does zope cache authentication?
Thanks for clarifying this. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How to register multiple view for the same content class
Hi, I thought this would be a simple case for Zope3, but after one whole day I am not able to find a clean solution. Must be missing something. Suppose I have a BookShelf which contains lots of Books. The view for BookShelf will show a list of Books contained in the shelf, and when the user click on a book, a detailed view for the Book will be opened. Of course the Book rendered in the shelf will be different from the same rendered in the book detail view. But how best to achieve this in zope3? The triditional solution (zope 2) I am familar with would be to use in the page template for the shelf like this: ... This however mixes the presentation of the shelf itself with the books on the shelf. If I want to change how books looks like on the shelf, I have to modify the shelf template, which doesn't seem to be a good separation of concerns. Is it possible to register two different views for the Book, one for display in shelf, another for the detailed view? The one for the detailed view is simply a BrowerPage, but how to do the book-in-shelf view? I'd like for my shelf template to look something like this: http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] How to register multiple view for the same content class
On 9/28/07, Frank Burkhardt <[EMAIL PROTECTED]> wrote: > > You just need another browser:page here. Name it 'in-shelf-view' and > use something like > > > > to embed it. > Thanks, that works. So all was missing is the '@@' notation to tell TALES to look up a view for Book. > Registering the view for different "shelves" is possible, too. But this not > a simple view anymore - it's a "Multiview". You need an adapter for > (book,shelve,request) to do that which means, a simple browser:page won't > work and you'll be not able to use the object/@@view notation for that. > If not object/@@view, what then? A custom traverse to lookup the Multiview maybe? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] How to register multiple view for the same content class
On 9/28/07, Frank Burkhardt <[EMAIL PROTECTED]> wrote: > > You could use a view as dispatcher which then would be traversed like > object/@@view: > > class MyDispatcher(object): >def __call__(self): > > realview=zapi.getMultiAdapter((self.context,self.context.__parent__,self.request)) > return realview() > > class MyExampleView(object): >def __init__(context,parent,request): > self.context=context > self.parent=parent > self.request=request > >def __call__(self): > return "Book/shelf-specific html" > > *configure.zcml* > > ... /> > > > Got it. Thanks. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] ATDocument-like content component
Hi, Does there exists for Zope3 a content component for creating/editing HTML pages through the Web, preferably with the ability to upload images related to the HTML document? Something similiar to ATDocument for Plone/Zope2? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Remaking an 'instance' site with zopeproject
On 10/4/07, Philipp von Weitershausen <[EMAIL PROTECTED]> wrote: > > > __ > > ANOTHER PROBLEM: > > I don't get the access logs constantly running in Terminal that I was > > used to. > > How do I start these up? > > Ah, thanks for bringing this up. You can use a logging middleware, such > as Paste#translogger. Simply edit 'deploy.ini' and change it to read:: > > > [filter-app:main] > use = egg:Paste#translogger > next = zope > > [app:zope] > use = egg:HelloWorld > > [server:main] > use = egg:Paste#http > host = 127.0.0.1 > port = 8080 > Can I get logging in debug mode? In debug.ini, there is already a [filter-app:main] specification. What shall I put in this section to enable both debugging and logging? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] dynamicall javascript and css generation
Hi, How do I dynamically generate javascript and css files and how to register them? ZPT doesn't seem to be a viable solution for generating these. DTML as far as I know is no longer available. So I think I should write a browser view to generate it in python with string formatting. Then how do I registered them? Using browser:page directive just like for a normal HTML page? But that would send text/html as the content type I guess, not text/javascript. What's the zope3's way of dynamicall script and css generation? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How to get at the URL as entered in the browser?
Hi, list, Is it possible to retrieve the URL the user enters in the browser location box? The request's getURL method seems to return the traversed URL, including the default view name. In particular, I have a custom traverser for my object which extracts certain parameters from the URL path instead of the query string, like this: The url: http://myweb.com/myobject/param1/value1/param2/value2 The traverser registered for myobject parses the remainder of the URL and then set the traversal stack to be empty. However, in the view of myobject, I would like to get the exact URL as above. What request.getURL returns now is: http://myweb.com/myobject/index.html Also, in the generated HTML for myobject, the base is set automatically to this url. How can I get back the original url? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] How to get at the URL as entered in the browser?
On 10/24/07, Frank Burkhardt <[EMAIL PROTECTED]> wrote: > > The web server never gets the URL which as typed by the user. At least > the protocol (http vs. https), is lost. This is what you can do: > > url='http://' + request['HTTP_HOST'] + request['REQUEST_URI'] > Does this work for Zope3? I use zopeproject, and starting the server with bin/paster serve debug.ini It doesn't seem that the request has a key 'REQUEST_URI': (Pdb) request http://rhodium.homemaster.cn/products/101> (Pdb) request.keys() ['HTTP_MAX_FORWARDS', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD', 'PATH_INFO', 'SERVER_PROTOCOL', 'QUERY_STRING', 'paste.throw_errors', 'HTTP_X_FORWARDED_SERVER', 'CONTENT_LENGTH', 'HTTP_ACCEPT_CHARSET', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_NAME', 'REMOTE_ADDR', 'wsgi.url_scheme', 'SERVER_PORT', 'paste.evalexception', 'wsgi.input', 'HTTP_HOST', 'wsgi.handleErrors', 'wsgi.multithread', 'HTTP_ACCEPT', 'wsgi.version', 'wsgi.run_once', 'wsgi.errors', 'wsgi.multiprocess', 'HTTP_X_FORWARDED_HOST', u'page', 'HTTP_X_FORWARDED_FOR', 'CONTENT_TYPE', 'paste.httpserver.thread_pool', 'HTTP_ACCEPT_ENCODING'] (Pdb) request['REQUEST_URI'] *** KeyError: 'REQUEST_URI' -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Problem with interdependent utilities registration
Hi, If I have a utility component whose initializaiton depends on the availability of another utility, the initialization fails with a Component Lookup Error. It seems that in the ZCML file, the utility components are first created, and then at the end of the whole configuration, they are registered. So if in the initilization code of utility B I need to look up a utility A, the ZCML configuration will fail. As an example, I have a utility that reference a z3c.zalchemy engine. class MyUtility(object): implements(IMyUtility) def __init__(self): engine = getUtility(z3c.zalchemy.interfaces.IAlchemyEngineUtility, name=u'TheEngine').getEngine() And the configuration goes like this: http://namespaces.zalchemy.org/alchemy"; The problem is that although the z3c eninge object is created before the 'utility' directive is executed, it is not registered and therefore can not be looked up when the 'utility' directive tries to create the MyUtility object. How does one usually solve such interdependencies? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How can I register a simple content provider (i.e. not viewlet)
With which ZCML directive can I register a simple content provider, say for the main menu. The browser namespaces only has viewlet and viewletManager directives, which must be used together to provide the ability to include multiple viewlets in an area represented by viewlet manager. In some simple cases, we just know there can not be multiple elements to be included in the area, and want to simply register a content provider. How to do this in ZCML? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How to persist an attribute of list type
Hi, It seems that I can not get list attribute of an persistent object changed. I have the following class, which has a list as one of its attributes: class Cart(Persistent): items = [] amount = 0 In the debug console, I find that only with direct attribute assignment can I change the persisted attribute value. If I use items.append to modify the list, even after I set the _p_changed attribute of the cart object to True and commit, the persisted version won't change. I also tried to use PersistentList as the type of the 'items' attribute. It doesn't work either with append. What could be missing? I am using Zope 3.4. Below is the debug output: Welcome to the interactive debug prompt. The 'root' variable contains the ZODB root folder. The 'app' variable contains the Debugger, 'app.publish(path)' simulates a request. >>> from myproject.cart import Cart >>> cart = Cart() >>> cart.items=['Item1', 'Item2'] >>> root['mycart']=cart >>> import transaction >>> transaction.commit() After this I break out of the debug session and re-enter it: Welcome to the interactive debug prompt. The 'root' variable contains the ZODB root folder. The 'app' variable contains the Debugger, 'app.publish(path)' simulates a request. >>> cart=root['mycart'] >>> cart.items ['Item1', 'Item2'] >>> cart.items.append('Item3') >>> cart._p_changed = True >>> import transaction >>> transaction.commit() Break again: Welcome to the interactive debug prompt. The 'root' variable contains the ZODB root folder. The 'app' variable contains the Debugger, 'app.publish(path)' simulates a request. >>> cart=root['mycart'] >>> cart.items ['Item1', 'Item2'] So the list attribute is NOT changed. Does _p_changed no longer work with Zope 3.4? Looking for advices. Thanks. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] How to persist an attribute of list type
On Dec 1, 2007 10:49 AM, Paul Winkler <[EMAIL PROTECTED]> wrote: > On Sat, Dec 01, 2007 at 02:34:49AM +0800, Yuan HOng wrote: > > Hi, > > > > It seems that I can not get list attribute of an persistent object > > changed. I have the following class, which has a list as one of its > > attributes: > > > > class Cart(Persistent): > > items = [] > > amount = 0 > > I hope that's not your actual code. Note here that items is a mutable > class attribute, so if you do this: > > cart = Cart() > cart.items.append('foo') > > ... you've just mutated the default list for all instances. Is that > really what you want? ZODB persistence can only store instance > attributes, not class attributes. > > But that's irrelevant to the rest of your examples, because you > re-assigned cart.items, which should work. I don't know what's wrong > there. > I found out now that using PersistentList does solve the problem. I my previous try I overwrote the empty persistent list with a normal list, so the test failed. But using _p_changed on a normal list seems to no longer be useful. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] How can I register a simple content provider (i.e.not viewlet)
On Nov 29, 2007 1:07 PM, Roger Ineichen <[EMAIL PROTECTED]> wrote: > You can use the adapter directive for this. > > class IHeaderProvider(zope.contentprovider.interfaces.IContentProvider): > """Header provider.""" > > class HeaderProvider(object): > """Header content provider.""" > > zope.interface.implements(IHeaderProvider) > zope.component.adapts(zope.interface.Interface, IMySkinBrowserLayer, > zope.interface.Interface) > > name="IHeaderProvider" > factory=".header.HeaderProvider" > /> > Thanks. Now I understand. A simple content provider is nothing but a normal adapter which adapts to IContentProvider. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] z3c.json and datetime objects
The z3c.json write implementation uses str to convert any unrecognized data types json. But json only recogonizes basic data types, and strings must be enclosed in quotation marks, so the data representation given by z3c.json is often invalid. For example: >>> import zope.component >>> from z3c.json import interfaces >>> from z3c.json import testing >>> testing.setUpJSONConverter() >>> jsonWriter = zope.component.getUtility(interfaces.IJSONWriter) >>> from datetime import date >>> input = {u'date': date.today()} >>> jsonWrite.write(input) u'{"date":2008-01-31}' This string would be evaluate by most javascript implementations to give the result of {date: 1976}, since 2008-01-31 is not quoted and is regarded as an expression by javascript eval function. I think there is a bug in the minjson.py, which uses str function to convert an unrecognized type to json string but without quoting the return value: # if we are not baseobj, convert to it try: obj = str(obj) except Exception, exc: raise WriteException, 'Cannot write object (%s: %s)' % (exc.__class__, exc) self.stream.write(obj) Shouldn't the code read better as? # if we are not baseobj, convert to it try: obj = str(obj) except Exception, exc: raise WriteException, 'Cannot write object (%s: %s)' % (exc.__class__, exc) self.stream.write('"') self.stream.write(obj) self.stream.write('"') -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Stability problem of zope3
Hi, I have jsut moved a production site from Zope2 to Zope3. I used zopeproject to download the necessary eggs and started my site using paste serve deploy.ini. Under moderate traffic however, the site stops responding soon. I have to regularily restart the server. When the site stops responding, 'ps -Af | grep python2.5' shows hundreds of process of paster running. And the process number increases with time rapidly, like: root 20230 18557 0 11:16 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20231 18557 0 11:16 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20237 18557 0 11:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20248 18557 0 11:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20249 18557 0 11:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20250 18557 0 11:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20251 18557 0 11:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20252 18557 0 11:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 20284 18557 0 11:18 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini Looking into z3.log, I found lots of alarming error messages like: 2008-03-03T11:01:57 INFO paste.httpserver.ThreadPool No idle tasks, and only 0 busy tasks; adding 5 more workers -- 2008-03-03T11:01:58 CRITICAL ZODB.DB DB.open() has 253 open connections with a pool_size of 7 -- 2008-03-03T11:01:58 CRITICAL ZODB.DB DB.open() has 254 open connections with a pool_size of 7 -- 2008-03-03T11:01:59 CRITICAL ZODB.DB DB.open() has 255 open connections with a pool_size of 7 -- 2008-03-03T11:01:59 CRITICAL ZODB.DB DB.open() has 256 open connections with a pool_size of 7 -- 2008-03-03T11:01:59 CRITICAL ZODB.DB DB.open() has 257 open connections with a pool_size of 7 -- 2008-03-03T11:02:35 INFO paste.httpserver.ThreadPool No idle tasks, and only 0 busy tasks; adding 5 more workers -- 2008-03-03T11:02:36 CRITICAL ZODB.DB DB.open() has 258 open connections with a pool_size of 7 -- What's wrong with my installation? For your information, the following related components are installed: PasteDeploy-1.3.1 Paste-1.6 ZODB3-3.9.0_dev I am running these with Python2.5. The site uses ZAlchemy to connect to PostgreSQL database and uses ZODB for session variables. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Stability problem of zope3
On 3/3/08, Andreas Jung <[EMAIL PROTECTED]> wrote: > > The official Python version for Zope 3.3/3.4 is Python 2.4, not 2.5. > > Andreas > OK. I will try Python2.4 first, though in my development installation using also Python2.5 but will different versions of packages (because I ran zopeproject at an earlier time), there is no such problem as I have run 'ab' against it. Anyway, can someone tellme what the following error usually means? 2008-03-03T11:02:36 CRITICAL ZODB.DB DB.open() has 258 open connections with a pool_size of 7 Also, I hope there is a way for zopeproject to pull a known good set of component versions, so I can ran zopeproject multiple times to build the same version of production environment. I've heard of the KGS concetp but don't know how to apply it to zopeproject. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Stability problem of zope3
On Mon, Mar 3, 2008 at 10:08 PM, Jim Fulton <[EMAIL PROTECTED]> wrote: > > On Mar 3, 2008, at 4:00 AM, Jodok Batlogg wrote: > ... > > > paster opens a lot of threads. > > That's odd. That must depend on the server used. The zope.server > server factory uses 4 by default. The cherrypy server uses 10. > > > > > you should limit them... > > specify sth. like: > > > > [server:main] > > threadpool_workers = 4 > > threadpool_spawn_if_under = 0 > > threadpool_max_requests = 0 > > > This appears to be incomplete. You would need a use option to specify > which server to use and I'm wondering what server these options are > for and which zopeproject uses by default. > > > > Jim > > -- > Jim Fulton > Zope Corporation > > > I used zopeproject-0.4.1 to create the project directory. The deploy.ini created by default seems to use Paste#http since it looks like: [app:main] use = egg:homemaster [server:main] use = egg:Paste#http host = 127.0.0.1 port = 9673 So you mean I can also use the zope.server? Are there any preferred way to set up a production environment now? For the moment I switched back to the package versions used in my development environment, which is older, but doesn't give the above headache. However, I am interested in finding out what's wrong with my previous installation. Anyway, it is created by default by the most recent version of zopeprject under Python2.5. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Stability problem of zope3
I also noticed that on my production server, there are multiple process of zdaemon running, 3 exactly: root 23550 1 0 22:05 ?00:00:00 /usr/bin/python2.5 bin/homemaster-ctl -S /root/app/eggs/zdaemon-2.0.1-py2.5.egg/zdaemon/schema.xml -C zdaemon.conf bin/paster serve deploy.ini root 23551 23550 0 22:05 pts/51 00:00:00 /usr/bin/python2.5 bin/homemaster-ctl -S /root/app/eggs/zdaemon-2.0.1-py2.5.egg/zdaemon/schema.xml -C zdaemon.conf bin/paster serve deploy.ini root 23552 23551 0 22:05 pts/51 00:00:00 /usr/bin/python2.5 bin/homemaster-ctl -S /root/app/eggs/zdaemon-2.0.1-py2.5.egg/zdaemon/schema.xml -C zdaemon.conf bin/paster serve deploy.ini r root 26575 23550 0 22:17 ?00:00:08 /usr/bin/python2.5 bin/paster serve deploy.ini root 26711 26575 0 22:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 26712 26711 0 22:17 ?00:00:00 /usr/bin/python2.5 bin/paster serve deploy.ini root 26713 26711 0 22:17 ?00:00:06 /usr/bin/python2.5 bin/paster serve deploy.ini root 26714 26711 0 22:17 ?00:00:07 /usr/bin/python2.5 bin/paster serve deploy.ini root 26715 26711 0 22:17 ?00:00:07 /usr/bin/python2.5 bin/paster serve deploy.ini root 26716 26711 0 22:17 ?00:00:06 /usr/bin/python2.5 bin/paster serve deploy.ini root 26717 26711 0 22:17 ?00:00:07 /usr/bin/python2.5 bin/paster serve deploy.ini root 26718 26711 0 22:17 ?00:00:06 /usr/bin/python2.5 bin/paster serve deploy.ini root 26719 26711 0 22:17 ?00:00:07 /usr/bin/python2.5 bin/paster serve deploy.ini root 26720 26711 0 22:17 ?00:00:05 /usr/bin/python2.5 bin/paster serve deploy.ini root 26721 26711 0 22:17 ?00:00:06 /usr/bin/python2.5 bin/paster serve deploy.ini root 26722 26711 0 22:17 ?00:00:07 /usr/bin/python2.5 bin/paster serve deploy.ini While on my test server, there is only one: root 7722 1 0 21:24 ?00:00:00 /usr/bin/python2.5 bin/homemaster-ctl -S /root/workspace/eggs/zdaemon-2.0.1-py2.5.egg/zdaemon/schema.xml -C zdaemon.conf bin/paster serve deploy.ini root 7724 7722 2 21:24 ?00:01:09 /usr/bin/python2.5 bin/paster serve deploy.ini What is causing the difference? The two site are build from the same buildout.cfg, with their own egg directory created by buildout. All the configuration came from the same version control system, so I do know where does the difference come from. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Stability problem of zope3
Hi, Thanks for the various advises previously. I have experimented with different wsgi servers: zope.server#main Paste#http PasteScript#cherrypy PasteScript#twisted and put them under some load: ab -c 20 The zope.server seems to give the best result. It causes the least failed requests due to the Competing writes/reads conflict, like: 2008-03-11T22:56:16 WARNING ZopePublication Competing writes/reads at /prod/++vh++http:rhodium.homemaster.cn:80/++/products/bWc9MTAxJmI9NA==: database conflict error (oid 0x36, class BTrees.OOBTree.OOBTree, serial this txn started with 0x03745ce92aee00aa 2008-03-11 08:09:10.061648, serial currently committed 0x03745e800ade9cdd 2008-03-11 14:56:02.547558) With PasteScript#cherrypy my application fails when using JSON requests with the header Content-Type: application/json. It causes zope.publisher to throw a socket time out error and doesn't send back any results. I guess it can not handle my request header properly. The other servers are OK with the JSON request header. 2008-03-11T22:49:50 ERROR root /root/workspace/eggs/tmp_f2rNS/zope.publisher-3.4.2-py2.5.egg/zope/publisher/publish.py line 126 in publish => None ** : timed out /root/workspace/eggs/z3c.jsonrpc-0.5.1-py2.5.egg/z3c/jsonrpc/publisher.py line 114 in processInputs => 'incoming = stream.read(1000)' ** : timed out /root/workspace/eggs/tmp_f2rNS/zope.publisher-3.4.2-py2.5.egg/zope/publisher/http.py line 210 in read => None ** : timed out /usr/lib/python2.5/socket.py line 309 in read => 'data = self._sock.recv(recv_size)' ** : timed out I have one problem with zope.server though. It works fine with paste in the 3.5 version. But following the advise of Christophe, I added the following to my buildout.cfg extends = http://download.zope.org/zope3.4/versions.cfg It turns out however that zope.server-3.4.1 does not define entry_points and therefore can not be loaded by Paste, since Paste doesn't seem to be able to load from modules directly. How can I solve this problem? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] ZODB conflict for session data container
Hi, list I have newly migrated an Zope2 application to Zope3 and added session support to it. When I stress test the application with 'ab -c 20', I found lots of database conflict errors, like the following: 2008-03-20T13:44:24 WARNING ZopePublication Competing writes/reads at /prod/++vh++http:rhodium.homemaster.cn:80/++/products/bWc9MTAzJmI9NA==: database conflict error (oid 0x3e, class BTrees.OOBTree.OOBTree, serial this txn started with 0x03748ea6c0076ecc 2008-03-20 04:22:45.006805, serial currently committed 0x03748ef8667bc888 2008-03-20 05:44:24.019577) -- 2008-03-20T13:44:24 WARNING ZopePublication Competing writes/reads at /prod/++vh++http:rhodium.homemaster.cn:80/++/products/bWc9MTAzJmI9NA==: database conflict error (oid 0x3e, class BTrees.OOBTree.OOBTree, serial this txn started with 0x03748ea6c0076ecc 2008-03-20 04:22:45.006805, serial currently committed 0x03748ef8667bc888 2008-03-20 05:44:24.019577) -- 2008-03-20T13:44:25 WARNING ZopePublication Competing writes/reads at /prod/++vh++http:rhodium.homemaster.cn:80/++/products/bWc9MTAzJmI9NA==: database conflict error (oid 0x3e, class BTrees.OOBTree.OOBTree, serial this txn started with 0x03748ea6c0076ecc 2008-03-20 04:22:45.006805, serial currently committed 0x03748ef8667bc888 2008-03-20 05:44:24.019577) -- 2008-03-20T13:44:39 WARNING ZODB.DB DB.open() has 8 open connections with a pool_size of 7 -- 2008-03-20T13:44:45 WARNING ZopePublication Competing writes/reads at /prod/++vh++http:rhodium.homemaster.cn:80/++/products/bWc9MTAzJmI9NA==: database conflict error (oid 0x0dddaa, class BTrees.OOBTree.OOBucket, serial this txn started with 0x03748ef8b578d588 2008-03-20 05:44:42.532502, serial currently committed 0x03748ef8b90ef211 2008-03-20 05:44:43.373058) -- 2008-03-20T13:44:46 WARNING ZopePublication Competing writes/reads at /prod/++vh++http:rhodium.homemaster.cn:80/++/products/bWc9MTAzJmI9NA==: database conflict error (oid 0x0ddda9, class BTrees.OOBTree.OOBucket, serial this txn started with 0x03748ef89d390a55 2008-03-20 05:44:36.849097, serial currently committed 0x03748ef8c043debb 2008-03-20 05:44:45.062137) .. The more complex the test page, i.e. the longer time necessary to generate a response, the more conflicts appear. Looking into the ZODB, I found all conflicts appears at the OOBTree or OOBucket, and they all contain session data: >>> root._p_jar['\x00\x00\x00\x00\x00\x00\x00\x3e'] >>> root._p_jar['\x00\x00\x00\x00\x00\x0d\xdd\xaa'] BTrees.OOBTree.OOBucket([('Zjos3EZS4oOyLAUejl0Xq9RT7woV12BLc.C8dekKCAkDPcCMdqGwA8', ), ('aDS7b33CWWptgPYJCbCJlhcoQjkt--SmeM4pF2XiyDGvdc9C9diTcE', ), ('an5bfNkL6oO0oHb1K7oHMyrqhvoOzVNKP7UKKBSssZ8-CDRhRDiiig', ), ('bGG4E2jhbIQ6EYETT9JHa0.ZP4IjIQtJ1XNQK19ORKfb3ov5AHoasg', ), ('cfxKsIw58f.KqESglVi63G3YdLgGGsduMr9m1HEDAZZN7QXJQKqTT8', ), ('cuHZ4PyRSGi9WvaITuVo9.f5yYU3lrDS4Rw0VEI5MzL1KDzzIDg7cA', ), ('d4CDu80Z4PENLYqrwpYQcJrEHtI9SQkdxh7jOisN0ecEeyk78S-l-Y', ), ('d5h4xVFiTRWy.f9-fl9Phc6PeZs.m-XpPQnt9kfuzt6tRKzol-M8DM', ), ('ea88VW0qmh04ZCFJIrxRbkOBOssMBxm463xEDb43zjg-sgJTpkEoyo', ), ('eloivtXMl5DR9lb1pDGC5OvrN445kqNRndJb9BcqBEVajLF5SQIWg4', ), ('emx7d9RFeccvwmsym6NkajLvKxcNhp1xXmK09C-kZvYHO5ySZ1CniY', ), ('f4wqdTRhqcjjifYjSdKByOMad9M7taFSNMohD9xNUuP5PGBCBUo1Bg', ), ('g0i978GRti5oj70Mb9ks0nLEMHcj0iE0s3NCT2lpjfFBm73-Ta1ktM', ), ('hJYayepksKCz1xtg71S7bQ2z9MEYhaXLFNfgqNu590cpBW3dArz6sA', ), ('hW9EjQ9I7SqAAf3oG9zPHA2oFWA.pzJ.1bREzWycu9mM8P-RExT8W0', ), ('hWUnyqPLXYifg4-Ryo5i37-u3yoRte6Le6ryKq1saVQHFVfLl82tXY', ), ('iHGEuaZoRIh5raxPad2hbh91jkIQ2GYtl3-tuzmYaLiLbbXYJqLAIc', ), ('iqUTsBAdXWssU1hwqQ-BLrOoS-MbBtGqNzRI5wKGWfOAIVnVnhtxJo', ), ('jKGjdchCGugHfJwgsyDwqpQKLOgMx15hSs5u89kni01VlXmTY4B3S4', ), ('knbHBxhaT.6mhdf3HXSiZWuqdSMq.yjaXPt4KIi.J0JcPT1uf5uj9s', ), ('mXy-i3ucYsmTIDoD7d9Yfe3Ii90CjLvNEjJQx6aTbeTBfccm7m9lys', )]) So I guess the following is what happened: With -c 20, multiple simultaneous requests are trying to access their session. Since session object is created and stored into the PersistentSessionDataContainer upon first access, there are multiple thread trying to add new session data into the persistent session data container, which uses an OOBTree to store the session data. Now comes the part that I can not understand. This simultaneous adding to the BTree seem to cause the conflict error, since the BTree and Bucket are also persistent object themselves. This would mean that ZODB is not suitable for the cases of simultanous adding to a BTree by multiple threads, like in my case for session data. But since ZODB and zope.session are so widely used, I can not image that this could be the case, otherwise how can anyone be reliably using ZODB for session? So I must be missing some very important points. Please be so kind to tell me what I should do to make my application stable in regard of the above problem. I am using Zope 3.4 under Linux. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zo
Re: [Zope3-Users] ZODB conflict for session data container
Thanks Bernd for giving detailed answer and suggestions. > it is the case ... there are two workarounds imho > > 1. > don't write to the session if it does not change, so if you do an > apache bench without sending the client id cookie, a write is done on > each request > > additionally every anonymous visit writes to zodb, you should avoid > this by using default values if no session data is available > > in earlier versions of zope the __getitem__ method created a btree at > first access, but this should be fixed now, so it depends on the > version of zope u use, if you have an older version then you can't > even look if data is there without writing to zodb > Yes. I looked into the zope.session code. The __getitem__ method will create new session data if the session package key is not found. On the other hand, the get method does not create session data. So changing my code from ISession(request)['myapplication'] to ISession(request).get('myapplication') avoids the problem of new session data being created at each anonymous request. > 2. > my recommendation is to use memcached for session data ... take a look > at http://svn.zope.org/repos/main/lovely.memcached/trunk > Yes, I think this would be the more decent solution for server side session data storage for zope3. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] zope.app.wsgi doesn't register product configurations properly
Tyring out z3c.extfile, I added in zope.conf file the following product configuration section: storagedir var/filestorage This doesn't not work as expected when I am using Paste and wsgi. Looking into the code, I think the config function in zope.app.wsgi should be patched by adding: from zope.app.appsetup.product import setProductConfigurations def config(...) ... if options.product_config: setProductConfigurations(options.product_config) ... This is exactly what zope.app.server does when starting up the server. Or is product configuration explicitly not desired with zope.app.wsgi? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] retrieving zope.conf parameters and paths of buildout dirs
One caveat, I you are using product-config directive to specify your application directory, please note that it can not be retrieved by zope.app.appsetup.getProductConfig if you are using zope.app.wsgi to start your zope3 application. In stead, a patch to zope.app.wsgi is needed. See my mail 2 days ago. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Using z3c.extfile with ZEO
Hello, I am trying to use z3c.extfile on clients running ZEO. My zope.conf has the following configuration: server localhost:8101 storage 1 blob-dir var/blob cache-size 20MB Then I get the following error: 2008-04-20T23:13:54 ERROR ZODB.Connection Couldn't load state for 0x0de14f Traceback (most recent call last): File "/root/workspace/eggs/tmpZKaS-m/ZODB3-3.8.0-py2.5-linux-i686.egg/ZODB/Connection.py", line 804, in setstate File "/root/workspace/eggs/tmpZKaS-m/ZODB3-3.8.0-py2.5-linux-i686.egg/ZODB/Connection.py", line 869, in _setstate File "/root/workspace/eggs/ZODB3-3.8.0-py2.5-linux-i686.egg/ZEO/ClientStorage.py", line 1034, in loadBlob self._server.sendBlob(oid, serial) File "/root/workspace/eggs/tmpZKaS-m/ZODB3-3.8.0-py2.5-linux-i686.egg/ZEO/ServerStub.py", line 289, in sendBlob File "/root/workspace/eggs/tmpZKaS-m/ZODB3-3.8.0-py2.5-linux-i686.egg/ZEO/zrpc/connection.py", line 679, in call AttributeError: 'FileStorage' object has no attribute 'loadBlob' Does that mean the FileStroage on the ZEO server doesn't support Blob? How should I correctly configure zeo to be able to use z3c.extfile? Thanks. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] zope.app.wsgi doesn't register product configurations properly
On Mon, Apr 21, 2008 at 11:47 PM, Marius Gedminas <[EMAIL PROTECTED]> wrote: > > I think it's a simple bug. Would you mind adding it to the bug tracker? > https://launchpad.net/zope3/+bugs > Done. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] z3c.extfile bug: unicode path name
Hello, With z3c.extfile, if the path name of the HashDir utility is a unicode string, as configured by the directive in zcml, a unicode digest will be returned. However, loading the file with this digest raises a ValueError, since the getPath function only recognizes StringType as digest: >>> from z3c.extfile import hashdir >>> import tempfile, os >>> tmp = tempfile.mkdtemp() >>> hdPath = os.path.join(tmp, u'testhashdir') >>> hdPath u'/tmp/tmpapwlBZ/testhashdir' >>> hd = hashdir.HashDir(hdPath) >>> from z3c.extfile.property import ExtBytesProperty >>> from cStringIO import StringIO >>> class Foo(object): ... data = ExtBytesProperty('data') ... ... >>> foo = Foo() >>> from z3c.extfile.interfaces import IHashDir >>> from zope import component >>> component.provideUtility(hd, provides=IHashDir) >>> si = StringIO('hello world') >>> foo.data=si >>> foo.data >>> foo.data.digest u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' >>> [u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'] >>> hd.getPath(foo.data.digest) Traceback (most recent call last): File "", line 1, in File "/home/hong/workspace/eggs/z3c.extfile-0.2.0a2-py2.5.egg/z3c/extfile/hashdir.py", line 64, in getPath raise ValueError, repr(digest) ValueError: u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' Below is the patch that fixes this. I am not sure if this is the best, since it allows the file digest to be unicode. Can someone have a look? Index: hashdir.py === --- hashdir.py (revision 85015) +++ hashdir.py (working copy) @@ -3,7 +3,7 @@ import stat import tempfile import shutil -from types import StringType +from types import StringTypes import interfaces from zope import interface from persistent import Persistent @@ -60,7 +60,7 @@ return os.listdir(self.var) def getPath(self, digest): -if type(digest) != StringType or len(digest) != 40: +if isinstance(digest, StringTypes) or len(digest) != 40: raise ValueError, repr(digest) path = os.path.join(self.var, digest) if not os.path.isfile(path): By the way, do I also use https://launchpad.net/zope3/+bugs for tracking bugs in z3c projects? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Re: z3c.extfile bug: unicode path name
2008/4/23 Yuan HOng <[EMAIL PROTECTED]>: > > Below is the patch that fixes this. I am not sure if this is the best, > since it allows the file digest to be unicode. Can someone have a > look? > The alternative patch is simpler and doesn't allow digest to be unicode: Index: hashdir.py === --- hashdir.py (revision 85015) +++ hashdir.py (working copy) @@ -82,7 +82,7 @@ def __init__(self, name, bufsize=-1): self.name = name -self.digest = os.path.split(self.name)[1] +self.digest = str(os.path.split(self.name)[1]) self.bufsize=bufsize self._v_len = None self._v_file = None -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How do I find out references to objects in ZODB
Hi, Is it possible to find out what other objects are referencing a particular object in ZODB? In particular, I want to prevent some content objects, like images, from being removed from the folder if they are used in some other content object, like a news article. Do I have to keep track of object referencing in ZODB myself through events or there are some built-in mechanism in ZODB to take care of this for me? Thanks for info. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] How do I submit an update to zope translation?
Hi, If I find the current translation in zope.app.locales not satisfactory, how can I submit an update? In particular, I find a bug in the Chinese (zh_CN) translation which causes the sizes of content objects not displayed in the rotterdam skin. Following is the fix, hope someone can commit it. Index: zope.po === --- zope.po (revision 86390) +++ zope.po (working copy) @@ -6647,7 +6647,7 @@ #: src/zope/size/__init__.py:52 msgid "${size} KB" -msgstr "${SIZE}KB" +msgstr "${size} KB" #: src/zope/traversing/browser/absoluteurl.py:28 msgid "" -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] z3c.jsonrpc response content type bug
When I use z3c.jsonrpc (svn head) to publish an object, the response generated gets the content header: Content-Type: application/x-javascript According to the README.txt of the package: This project provides the proposed request type "application/json". The request type "application/json-rpc" is supported as long it is not officialy deprecated. And it also expects to receive a request with 'application/json' header. So this should be a bug. To fix it, one just need to modify _prepareResult method in the file publisher.py to change from # set content type self.setHeader('content-type', "application/x-javascript;charset=%s" \ % charset) to # set content type self.setHeader('content-type', "application/json;charset=%s" \ % charset) -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] z3c.jsonrpc response content type bug
On Tue, Oct 28, 2008 at 6:32 PM, Jim Washington <[EMAIL PROTECTED]> wrote: > > A bit of history on this. The content-type in this bit of code was > determined more than three years ago by testing with several old major > web browsers. At the time, 'application/x-javascript' was the > content-type that reliably told the web browser to use its javascript > parser on the document so that the rpc data could be used. Other > settings did not work on all of the web browsers I tested. > > So, this content-type was decided empirically (a long time ago), not > from specification. It maybe should continue to be the default for > compatibility with creaky old web browsers. But maybe it can be > changeable (if you *really* know what you are doing) so that the > outgoing document can meet the expectations of client libraries. > > - Jim Washington > > Reasonable. Then it would be nice to add a configuration directive so that user can set the content-type based on the requirement of client libraries. For me, I am using IE6, IE7, FF2 and FF3 with the ExtJS library and applicatin/json works fine. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] z3c.jsonrpc response content type bug
Hi, Roger, > > That's very interesting, which JS library are you using for JSON-RPC calls > from ExtJS? > Or does ExtJS provide JSON-RPC calls out of the box? > No, it is regretful that ExtJS (at least 2.0.1 which I am using) doesn't function well with z3c.jsonrpc out of the box, because z3c.jsonrpc is expecting a content type 'application/json' while the default json implementation of that of ExtJS sends out 'application/x-www-form-urlencoded'. So I use a slightly customized version which overrides several functions of the default Ext.lib.Ajax, especially the request method, to add the required header. Ext.lib.Ajax.asyncRequest = function(method, uri, callback, postData, async){ var o = this.getConnectionObject(); if (!o) { return null; } else { o.conn.open(method, uri, async); if (this.useDefaultXhrHeader) { if (!this.defaultHeaders['X-Requested-With']) { this.initHeader('X-Requested-With', this.defaultXhrHeader, true); } } if(postData && this.useDefaultHeader && (this.headers['Content-Type']===undefined)){ this.initHeader('Content-Type', this.defaultPostHeader); } if (this.hasDefaultHeaders || this.hasHeaders) { this.setHeader(o); } this.handleReadyState(o, callback); o.conn.send(postData || null); return o; } }; Ext.lib.Ajax.request = function(method, uri, cb, data, options) { if(options){ var hs = options.headers; if(hs){ for(var h in hs){ if(hs.hasOwnProperty(h)){ this.initHeader(h, hs[h], false); } } } if(options.xmlData){ this.initHeader('Content-Type', 'text/xml', false); method = 'POST'; data = options.xmlData; }else if(options.jsonData){ this.headers['Content-Type'] = 'application/json'; this.hasHeaders = true; method = 'POST'; data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; } } var async = (options.async === false) ? false : true; return this.asyncRequest(method, uri, cb, data, async); }; I made a report of this to the ExtJS folks. And the source code of the most recent version 2.2 now has 'application/json' in the request method. I suppose it should be working out of box now, although I am still using the old version. -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users