[Zope-dev] Re: Deciphering Zope Comments

2008-06-05 Thread Christian Zagrodnick

On 2008-06-04 20:28:07 +0200, Dieter Maurer [EMAIL PROTECTED] said:


Shane Hathaway wrote at 2008-6-4 00:01 -0600:


That led me to the zope.thread module, which is apparently deprecated
already, yet zope.app.component still depends on it.  Is that an
hysterical accident?


As I have read, thread local variables have been invented and
implemented in Zope 3 land and donated to Python.

Now, that it is in Python, the original Zope implementation
can go away. Maybe, that is the purpose of the zope.thread module?


Actually zope.thread does nothing but importhing the python 
implementation. The module is there for backward compatibility.


--
Christian Zagrodnick · [EMAIL PROTECTED]
gocept gmbh  co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 4 · fax +49 345 1229889 1
Zope and Plone consulting and development


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

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


Re: [Zope-dev] Re: SQLAlchemy (zope.sqlalchemy) integration

2008-06-05 Thread Hermann Himmelbauer
Am Mittwoch, 4. Juni 2008 22:09 schrieb Laurence Rowe:
 Hermann Himmelbauer wrote:
  In my application, I then use getSASession() to retrieve my session.
 
  However, what I think is not that beautiful is the s.bind = engine
  part. Are there any suggestions how to improve this?

 You have two options

 If you ever need to mix objects from different `sites` into the same
 session, you should use an adapter on your root object like:

 If you don't need to mix objects from different `sites` then you can
 register a local utility for ISessionConfig.

 def scope():
return getUtility(ISessionConfig).uid, thread.get_ident()

 def factory():
engine = Engine(getUtility(ISessionConfig).url)
return create_session(
  transactional=True, autoflush=True, bind=engine
  extension=ZopeTransactionExtension(),
  ))

 Session = scoped_session(factory, scopefunc=scope)

 Then you can just import Session and use:
 session = Session()

Ok, great, thanks for help. The only thing I don't understand is what uid 
from the SessionConfig utility is. Below is my full database integration code 
which works for me, perhaps this is helpful to someone else.

Btw., I'd suggest to put such code / session use cases in some Zope package, 
maybe into zope.sqlalchemy, or e.g. zope.sqlalchemy_utility as it's really 
difficult for non-insiders to set this up.

-
import thread
from persistent import Persistent
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, create_session
from zope.interface import Interface, implements, alsoProvides
from zope.schema import TextLine, Bool
from zope.component import getUtility, adapter
from zope.sqlalchemy import ZopeTransactionExtension

from zmyapp.interfaces import INewMySiteEvent

from zope.i18nmessageid import MessageFactory
_ = MessageFactory('xyz')

class ISAEngineUtility(Interface):
SQLAlchemy Engine Utility

db_type = TextLine(title = _(uDatabase Type))
db_username = TextLine(title = _(uDatabase Username))
db_password = TextLine(title = _(uDatabase Password))
db_host = TextLine(title = _(uDatabase Host))
db_name = TextLine(title = _(uDatabase Name))
db_echo = Bool(title = _(uEcho Database Operations))
db_enconding = TextLine(title = _(uDatabase Encoding))
db_convert_unicode = Bool(title = _(uDatabase Unicode Conversion))

class SAEngineUtility(Persistent):
implements(ISAEngineUtility)

# FIXME FIXME!!!
uid = 12345

def reset_engine_on_attrset(dsn_part):
doc = Reset engine when setting variable (stored in %s) % dsn_part
def fget(self):
return getattr(self, dsn_part, None)
def fset(self, value):
oldvalue = getattr(self, dsn_part, None)
if oldvalue != value:
setattr(self, dsn_part, value)
if getattr(self, 'init_done', False):
self._resetEngine()
return {'fget': fget, 'fset': fset, 'doc': doc}

db_type = property(**reset_engine_on_attrset('_db_type'))
db_username = property(**reset_engine_on_attrset('_db_username'))
db_password = property(**reset_engine_on_attrset('_db_password'))
db_host = property(**reset_engine_on_attrset('_db_host'))
db_name = property(**reset_engine_on_attrset('_db_name'))
db_echo = property(**reset_engine_on_attrset('_db_echo'))
db_encoding = property(**reset_engine_on_attrset('_db_encoding'))
db_convert_unicode =property(
 **reset_engine_on_attrset('_db_convert_unicode'))

def __init__(self, db_type, db_username, db_password, db_host, db_name,
 db_echo = False,
 db_encoding = 'utf-8',
 db_convert_unicode = False):
self.db_type = db_type
self.db_username = db_username
self.db_password = db_password
self.db_host = db_host
self.db_name = db_name
self.db_echo = db_echo
self.db_encoding = db_encoding
self.db_convert_unicode = db_convert_unicode
self.init_done = True

def mkDSN(self):
Create database DSN out of DSN elements
userpass = ''
if self.db_username:
userpass += self.db_username
if self.db_password:
userpass += ':' + self.db_password
if self.db_host == 'localhost':
db_host = ''
else:
db_host = self.db_host
if db_host and userpass:
db_host = userpass + '@' + self.db_host
elif not db_host and userpass:
db_host = userpass + '@localhost'
return '%s://%s/%s' % (self.db_type, db_host, self.db_name)

def getEngine(self):
engine = getattr(self, '_v_engine', None)
if engine:
return engine

# No engine available, create a new one
self._v_engine = create_engine(self.mkDSN(),
   echo = self.db_echo,
  

[Zope-dev] Zope Tests: 5 OK

2008-06-05 Thread Zope Tests Summarizer
Summary of messages to the zope-tests list.
Period Wed Jun  4 11:00:00 2008 UTC to Thu Jun  5 11:00:00 2008 UTC.
There were 5 messages: 5 from Zope Tests.


Tests passed OK
---

Subject: OK : Zope-2.8 Python-2.3.6 : Linux
From: Zope Tests
Date: Wed Jun  4 21:00:48 EDT 2008
URL: http://mail.zope.org/pipermail/zope-tests/2008-June/009655.html

Subject: OK : Zope-2.9 Python-2.4.4 : Linux
From: Zope Tests
Date: Wed Jun  4 21:02:18 EDT 2008
URL: http://mail.zope.org/pipermail/zope-tests/2008-June/009656.html

Subject: OK : Zope-2.10 Python-2.4.4 : Linux
From: Zope Tests
Date: Wed Jun  4 21:03:48 EDT 2008
URL: http://mail.zope.org/pipermail/zope-tests/2008-June/009657.html

Subject: OK : Zope-2.11 Python-2.4.4 : Linux
From: Zope Tests
Date: Wed Jun  4 21:05:18 EDT 2008
URL: http://mail.zope.org/pipermail/zope-tests/2008-June/009658.html

Subject: OK : Zope-trunk Python-2.4.4 : Linux
From: Zope Tests
Date: Wed Jun  4 21:06:48 EDT 2008
URL: http://mail.zope.org/pipermail/zope-tests/2008-June/009659.html

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


Re: [Zope-dev] Conflict Errors

2008-06-05 Thread Wichert Akkerman
Previously David Otero Figueroa wrote:
  Hello everyone,
 
 
 I have a couple questions related to conflict errors.
 
 During our home page stress testing (20 concurrent users), we detected
 several conflict errors (see trace below), We thought these could ONLY
 appear when writing objects in the ZODB.

That is correct. You need to audit your check to check for undesired
writes.

Wichert.

-- 
Wichert Akkerman [EMAIL PROTECTED]It is simple to make things.
http://www.wiggy.net/   It is hard to make things simple.
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Conflict Errors

2008-06-05 Thread David Otero Figueroa
 Hello everyone,


I have a couple questions related to conflict errors.

During our home page stress testing (20 concurrent users), we detected
several conflict errors (see trace below), We thought these could ONLY
appear when writing objects in the ZODB.
2008-05-27T18:57:53 INFO ZODB conflict error at /portal/ (26 conflicts since
startup at 2008-05-27T13:37:19)

I have this problems too in a not estress testing. In a simple access (2
concurrents users) I have this response:

2008-05-27T13:23:48 INFO ZODB conflict error at /portal/ (22 conflicts since
startup at 2008-05-27T10:37:28)
2008-05-27T13:23:48 INFO ZODB conflict error at /portal/ (23 conflicts since
startup at 2008-05-27T10:37:28)
2008-05-27T13:29:21 INFO ZODB conflict error at
/portal/login_form_usuario_pwd/ (29 conflicts since startup at
2008-05-27T10:37:28)
2008-05-27T13:29:22 INFO ZODB conflict error at
/portal/login_form_usuario_pwd/ (30 conflicts since startup at
2008-05-27T10:37:28)
2008-05-27T19:48:40 INFO ZODB conflict error at /portal/portal_css/Plone
Default/ploneStyles5658.css (68 conflicts since startup at
2008-05-27T13:37:19)


I would like to know:
- Can conflict errors appear when reading objects from the ZODB?
- Could conflict errors be the cause of a spinning ZOPE scenario?
- Is there any situation where ZOPE could try to write objects when
rendering an only read page?
- How can they be solved?
- Can I realize partial commits? How to?

Our configuration is as follows: Apache + Pound + ZEO architecture (5 ZEO
clients, 1 ZEO storage server - 650.000 ZODB objects)

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


Re: [Zope-dev] Conflict Errors

2008-06-05 Thread Jim Fulton


On Jun 5, 2008, at 10:16 AM, Jim Fulton wrote:



On Jun 5, 2008, at 9:52 AM, David Otero Figueroa wrote:


I would like to know:
- Can conflict errors appear when reading objects from the ZODB?


Yes



Gaaa. I meant no.

Jim

--
Jim Fulton
Zope Corporation


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

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


[Zope-dev] Restricted Python not handling slices correctly

2008-06-05 Thread Stephan Richter
Hi everyone,

I am starting to use Restricted Python a lot and I found the following problem 
with slicing:

 from zope.security import checker
 l = [1, 2]
 l[-3:]
[1, 2]
 lp = checker.ProxyFactory(l)
 lp[-3:]
[2]

The problem is that -3 gets converted to 1 somewhere, but it should be a 
negative number signalizing the slice to start at the beginning of the 
sequence.

The problem exists both in Python 2.4 and 2.5 and affects both Zope 2 and 3, 
since both Zopes use the RestrictedPython package.

I suspect that the problem lies with the new slicing syntax introduced in 
Python 2.4. I am willing to fix the bug, but I would need some guidance and 
goodwill from the gods of RestrictedPython. Anyone?

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. Zope Stephan Richter
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: SQLAlchemy (zope.sqlalchemy) integration

2008-06-05 Thread Laurence Rowe

Hermann Himmelbauer wrote:

Am Mittwoch, 4. Juni 2008 22:09 schrieb Laurence Rowe:

Hermann Himmelbauer wrote:

In my application, I then use getSASession() to retrieve my session.

However, what I think is not that beautiful is the s.bind = engine
part. Are there any suggestions how to improve this?

You have two options

If you ever need to mix objects from different `sites` into the same
session, you should use an adapter on your root object like:

If you don't need to mix objects from different `sites` then you can
register a local utility for ISessionConfig.

def scope():
   return getUtility(ISessionConfig).uid, thread.get_ident()

def factory():
   engine = Engine(getUtility(ISessionConfig).url)
   return create_session(
 transactional=True, autoflush=True, bind=engine
 extension=ZopeTransactionExtension(),
 ))

Session = scoped_session(factory, scopefunc=scope)

Then you can just import Session and use:
session = Session()


Ok, great, thanks for help. The only thing I don't understand is what uid 
from the SessionConfig utility is. Below is my full database integration code 
which works for me, perhaps this is helpful to someone else.


uid is some id that distinguishes your various application instances. On 
zope 2 I would probably use getPhysicalPath(). I don't know what the 
zope3 equivalent is.


Looking at your code, why did you decide to store the engine on a _v_ 
attribute? I don't think you need to save it at all. You can access a 
connection through session.connection()



Btw., I'd suggest to put such code / session use cases in some Zope package, 
maybe into zope.sqlalchemy, or e.g. zope.sqlalchemy_utility as it's really 
difficult for non-insiders to set this up.


We would need to work out what parts are useful to the various higher 
level sqlalchemy / zope packages. Once we can agree on a common core 
then we should at least make simple use cases available through 
zope.sqlalchemy directly.


Laurence

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

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


[Zope-dev] Re: Restricted Python not handling slices correctly

2008-06-05 Thread Martijn Faassen

Hey Stephan,

Stephan Richter wrote:

I am starting to use Restricted Python a lot


I'm curious to learn what you're using it for.

Regards,

Martijn

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

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


Re: [Zope-dev] Re: Restricted Python not handling slices correctly

2008-06-05 Thread Stephan Richter
On Thursday 05 June 2008, Martijn Faassen wrote:
 Stephan Richter wrote:
  I am starting to use Restricted Python a lot

 I'm curious to learn what you're using it for.

I cannot give you the full details yet, but Keas, the company I am working for 
now, has been developing a domain-specific language that is based on Python. 
We did some cool stuff overriding slicing and item lookup; I will be able to 
say more once we launched.

Clearly we do not allow to run unrestricted Python and run everything in 
restricted Python. The slicing and getitem syntax is very central to us, so 
then the problem popped up pretty quickly.

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. Zope Stephan Richter
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: Restricted Python not handling slices correctly

2008-06-05 Thread Martijn Faassen

Stephan Richter wrote:

On Thursday 05 June 2008, Martijn Faassen wrote:

Stephan Richter wrote:

I am starting to use Restricted Python a lot

I'm curious to learn what you're using it for.


I cannot give you the full details yet

[snip hints]

Thanks for the info nonetheless. My curiosity has only increased now, 
but that can't be helped. :) Keas sounds interesting!


Regards,

Martijn

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

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


[Zope-dev] fast_listen - fast-listen for 2.11

2008-06-05 Thread Stefan H. Holek
I'd like to sneak the following patch into 2.11 before final. The  
idea is that zope.conf option names should use dashes and not  
underscores. The downside is that it will break all zope.conf files  
that already use this option.


Objections?

Stefan


+Bugs Fixed
+
+  - Fixed against-the-rules zope.conf option 'fast_listen' to read
+'fast-listen' (dash, not underscore).
+
   Zope 2.11 rc 1 (2008/05/08)

 Bugs Fixed
Index: skel/etc/zope.conf.in
===
--- skel/etc/zope.conf.in   (revision 84838)
+++ skel/etc/zope.conf.in   (working copy)
@@ -975,8 +975,7 @@
   #
   # To defer the opening of the HTTP socket until the end of the
   # startup phase:
-  # fast_listen false
-  #
+  # fast-listen off
 /http-server

 # Examples:
Index: lib/python/ZServer/component.xml
===
--- lib/python/ZServer/component.xml(revision 84838)
+++ lib/python/ZServer/component.xml(working copy)
@@ -19,10 +19,10 @@
  receive WebDAV source responses to GET requests.
/description
  /key
- key name=fast_listen datatype=boolean default=on
+ key name=fast-listen datatype=boolean default=on
description
- Defines wether the http server should listen to requests  
immediately

- or only after zope is ready to run
+ Defines whether the HTTP server should listen for requests
+ immediately or only after Zope is ready to run.
/description
  /key
  key name=use-wsgi datatype=boolean default=off /


--
Anything that, in happening, causes something else to happen,
causes something else to happen.  --Douglas Adams


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

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


Re: [Zope-dev] Restricted Python not handling slices correctly

2008-06-05 Thread Shane Hathaway

Stephan Richter wrote:

Hi everyone,

I am starting to use Restricted Python a lot and I found the following problem 
with slicing:



from zope.security import checker
l = [1, 2]
l[-3:]

[1, 2]

lp = checker.ProxyFactory(l)
lp[-3:]

[2]

The problem is that -3 gets converted to 1 somewhere, but it should be a 
negative number signalizing the slice to start at the beginning of the 
sequence.


The problem exists both in Python 2.4 and 2.5 and affects both Zope 2 and 3, 
since both Zopes use the RestrictedPython package.


I suspect that the problem lies with the new slicing syntax introduced in 
Python 2.4. I am willing to fix the bug, but I would need some guidance and 
goodwill from the gods of RestrictedPython. Anyone?


Are you in fact using RestrictedPython?  The code snippet looks like it 
only uses a security proxy.  RestrictedPython is a custom Python 
compiler; you're not using it unless your interactive Python prompt uses 
RestrictedPython to compile all expressions.


The behavior you saw is exactly what happens when an object implements 
__getitem__ and __len__ but not __getslice__.  If lp matches that 
description, and the length of lp is 2, then Python evaluates lp[-3:] 
as lp.__getitem__(slice(-1, 2147483647, None)).  I wish Python would 
instead evaluate it as lp.__getitem__(slice(-3)), but maybe there are 
historical reasons for this.


OTOH, if RestrictedPython really is involved, RP will convert the 
expression to _getitem_(lp, slice(-3, None)), which would probably do 
what you wanted, assuming the _getitem_ function is not too clever.


BTW, here's the code I used to answer this email. :-)

 class itemgetter:
... def __getitem__(self, i):
... return i
... def __len__(self):
... return 2
...
 itemgetter()[-3:]
slice(-1, 2147483647, None)

Shane

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

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


Re: [Zope-dev] fast_listen - fast-listen for 2.11

2008-06-05 Thread Christian Theune
On Fri, Jun 06, 2008 at 01:37:16AM +0200, Stefan H. Holek wrote:
 I'd like to sneak the following patch into 2.11 before final. The idea is 
 that zope.conf option names should use dashes and not underscores. The 
 downside is that it will break all zope.conf files that already use this 
 option.

Hmm. Was this around in 2.10 already? If yes, then I'd consider it a bit late
to make a cosmetic fix that breaks config files.

If no, then it's probably not as bad and should be done to avoid config files
getting created with a variable we know will change.

Christian

-- 
Christian Theune · [EMAIL PROTECTED]
gocept gmbh  co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 7 · fax +49 345 1229889 1
Zope and Plone consulting and development
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope] Counting the elements of a result in a ZCatalog

2008-06-05 Thread Marco Bizzarri
Hi all.

I need to query a ZCatalog, and I would like to know how many elements
are there. I'm working from inside a python product, so, I could do
something like:

results = Catalog(criteria)
return len(results)


But this creates a number of objects which are completly useless for
me. After all, I'm interested in just the length, not in the objects.

I could do something like this:

results = Catalog(criteria, sort_limit=1)
return results.actual_result_count

since I should have a LazyMap, which does not (should not) actually
load all the objects (at least, I hope so).

This does not work if I have no result. So, what I should do would be:

results = Catalog(criteria, sort_limit=1)
if len(results) == 0:
return 0
return results.actual_result_count

Am I missing something?

Regards
Marco

-- 
Marco Bizzarri
http://iliveinpisa.blogspot.com/
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Counting the elements of a result in a ZCatalog

2008-06-05 Thread Janko Hauser


Am 05.06.2008 um 12:56 schrieb Marco Bizzarri:


Hi all.

I need to query a ZCatalog, and I would like to know how many elements
are there. I'm working from inside a python product, so, I could do
something like:

results = Catalog(criteria)
return len(results)


But this creates a number of objects which are completly useless for
me. After all, I'm interested in just the length, not in the objects.

I could do something like this:

results = Catalog(criteria, sort_limit=1)
return results.actual_result_count

since I should have a LazyMap, which does not (should not) actually
load all the objects (at least, I hope so).

This does not work if I have no result. So, what I should do would be:

results = Catalog(criteria, sort_limit=1)
if len(results) == 0:
   return 0
return results.actual_result_count

Am I missing something?


Yes, you do the expensive operation just for the test, so there is no  
benefit.


if result:
   result_len = results.actual_result_count
else:
   result_len = 0

return result_len

HTH,

__Janko


PGP.sig
Description: This is a digitally signed message part
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Counting the elements of a result in a ZCatalog

2008-06-05 Thread Marco Bizzarri
On Thu, Jun 5, 2008 at 1:28 PM, Janko Hauser [EMAIL PROTECTED] wrote:

 Am 05.06.2008 um 12:56 schrieb Marco Bizzarri:

 Hi all.

 I need to query a ZCatalog, and I would like to know how many elements
 are there. I'm working from inside a python product, so, I could do
 something like:

 results = Catalog(criteria)
 return len(results)


 But this creates a number of objects which are completly useless for
 me. After all, I'm interested in just the length, not in the objects.

 I could do something like this:

 results = Catalog(criteria, sort_limit=1)
 return results.actual_result_count

 since I should have a LazyMap, which does not (should not) actually
 load all the objects (at least, I hope so).

 This does not work if I have no result. So, what I should do would be:

 results = Catalog(criteria, sort_limit=1)
 if len(results) == 0:
   return 0
 return results.actual_result_count

 Am I missing something?

 Yes, you do the expensive operation just for the test, so there is no
 benefit.

 if result:
   result_len = results.actual_result_count
 else:
   result_len = 0

 return result_len

 HTH,

 __Janko

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



Hi, Janko.

Thanks for your answer, but there is something I do not understand:

if results:

an empty result from ZCatlog is false in a boolen condition?


Regards
Marco

-- 
Marco Bizzarri
http://iliveinpisa.blogspot.com/
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] acl_users folder 25000

2008-06-05 Thread Martijn Jacobs


It appears that the database of my client is not accessible. They 
can provide me an excel file with the members.


The intended application actually is an election. It is a one time 
thing. Every member is using this application once, and presumably not 
all of them. Would it still be unwise then to put these 25000 accounts 
in an ordinary acl_users folder?




You could import the users in a database (like mysql) and authenticate 
with a PAS plugin. Performance wise it could be really slow to have 25K 
users in a userfolder.


I found this userfolder today as well : 
http://www.simplistix.co.uk/software/zope/simpleuserfolder. You could 
easily write a ZSQL method for authentication for this (it's easier than 
writing a PAS plugin). If you have time or resources to write a PAS 
plugin I suggest to invest some time for that.



Martijn.

--
Martijn Jacobs
Four Digits, Internet Solutions

a: Willemsplein 15-1 6811 KB Arnhem NL 
kvk: 09162137 | btw: 8161.22.234.B01

e-mail: [EMAIL PROTECTED] | web: http://www.fourdigits.nl
tel: +31 (0)26 44 22 700 | fax: +31 (0)84 22 06 117 

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


Re: [Zope] Counting the elements of a result in a ZCatalog

2008-06-05 Thread Tino Wildenhain

Hi,

Marco Bizzarri wrote:
...

if result:
  result_len = results.actual_result_count
else:
  result_len = 0

return result_len


...


Thanks for your answer, but there is something I do not understand:

if results:

an empty result from ZCatlog is false in a boolen condition?


Yes, thats standard Python behavior, empty lists, dictionaries
and similar objects are assumed False when used as boolean.

This means you could even write it this way:

return (results and results.actual_result_count) or 0

in python2.5 (not yet supported by Zope) even:

return results.actual_result_count if results else 0

Cheers
Tino



smime.p7s
Description: S/MIME Cryptographic Signature
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] acl_users folder 25000

2008-06-05 Thread Martijn Jacobs
I wouldn't know, it seems like something is not correctly configured to 
reach the GMail server.


However, I suggested the gmailauthplugin as an example for writing a PAS 
plugin, not as a functional product for a website :)  Take a look 
authenticateCredentials in GMailAuthPlugin.py, there is where the 
authentication is happening.



Martijn.



Thanks for the link to the gmailauthplugin.

I am trying it out on plone 3 on a mac tiger laptop and I'm getting
the following error:


Exception Type  URLError
Exception Value urlopen error no host given

*  Module ZPublisher.Publish, line 110, in publish
* Module ZPublisher.BaseRequest, line 580, in traverse
* Module Products.PluggableAuthService.PluggableAuthService, line
233, in validate
* Module Products.PluggableAuthService.PluggableAuthService, line
600, in _extractUserIds
* Module Products.GMailAuthPlugin.GMailAuthPlugin, line 89, in
authenticateCredentials
* Module Products.GMailAuthPlugin.libgmail_incl.libgmail, line 320, in login
* Module Products.GMailAuthPlugin.libgmail_incl.libgmail, line
333, in _retrievePage
* Module urllib2, line 130, in urlopen
* Module urllib2, line 356, in open
* Module urllib2, line 943, in do_request_

Here is the environment specifics:

 Zope Version  (Zope 2.10.5-final, python 2.4.4, darwin)
Python Version 2.4.4 (#1, Feb 21 2008, 21:15:12) [GCC 4.0.1 (Apple
Computer, Inc. build 5250)]
System Platform darwin
SOFTWARE_HOME /Applications/Plone-3.0.6/lib/python

Any Suggestions?
Thanks in advance.
-Tim
www.medicinebrain.com


On 6/3/08, Martijn Jacobs [EMAIL PROTECTED] wrote:
  

Kees de Brabander wrote:


I have no idea.
I have been looking at the PAS, but did not find to much documentation
on it.
Would it be possible to use a database that my client does maintain?

cb
  

Yes that would be possible. Take a look at
http://plone.org/products/gmailauthplugin as it's a pretty nice example
how to write a plugin yourself. You can also take a look at
https://svn.plone.org/svn/collective/PASPlugins/


Martijn

--
Martijn Jacobs
Four Digits, Internet Solutions

a: Willemsplein 15-1 6811 KB Arnhem NL
kvk: 09162137 | btw: 8161.22.234.B01
e-mail: [EMAIL PROTECTED] | web: http://www.fourdigits.nl
tel: +31 (0)26 44 22 700 | fax: +31 (0)84 22 06 117






--
Martijn Jacobs
Four Digits, Internet Solutions

a: Willemsplein 15-1 6811 KB Arnhem NL 
kvk: 09162137 | btw: 8161.22.234.B01

e-mail: [EMAIL PROTECTED] | web: http://www.fourdigits.nl
tel: +31 (0)26 44 22 700 | fax: +31 (0)84 22 06 117 


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

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


RE: [Zope] acl_users folder 25000

2008-06-05 Thread Kees de Brabander
 

  _  

Van: Martijn Jacobs [mailto:[EMAIL PROTECTED] 
Verzonden: donderdag 5 juni 2008 15:35
Aan: Kees de Brabander
CC: zope@zope.org
Onderwerp: Re: [Zope] acl_users folder  25000




It appears that the database of my client is not accessible. They can
provide me an excel file with the members. 

The intended application actually is an election. It is a one time thing.
Every member is using this application once, and presumably not all of them.
Would it still be unwise then to put these 25000 accounts in an ordinary
acl_users folder?


You could import the users in a database (like mysql) and authenticate with
a PAS plugin. Performance wise it could be really slow to have 25K users in
a userfolder. 

I found this userfolder today as well :
http://www.simplistix.co.uk/software/zope/simpleuserfolder. You could easily
write a ZSQL method for authentication for this (it's easier than writing a
PAS plugin). If you have time or resources to write a PAS plugin I suggest
to invest some time for that.

 For the moment, MySql and simpleuserfolder would be the easiest way, I
presume. Thanks again, cb 
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Counting the elements of a result in a ZCatalog

2008-06-05 Thread Marco Bizzarri
On Thu, Jun 5, 2008 at 3:35 PM, Tino Wildenhain [EMAIL PROTECTED] wrote:
 Hi,

 Marco Bizzarri wrote:
 ...

 if result:
  result_len = results.actual_result_count
 else:
  result_len = 0

 return result_len

 ...

 Thanks for your answer, but there is something I do not understand:

 if results:

 an empty result from ZCatlog is false in a boolen condition?

 Yes, thats standard Python behavior, empty lists, dictionaries
 and similar objects are assumed False when used as boolean.

 This means you could even write it this way:

 return (results and results.actual_result_count) or 0

 in python2.5 (not yet supported by Zope) even:

 return results.actual_result_count if results else 0

 Cheers
 Tino




Tino, Janko, thanks for the clarification. I understand the standard
behaviour of list and tuples. But what a Catalog returns is not (if I
understand it correctly) a list or a tuple, even though it presents as
such. It is a subclass of Lazy. Is Lazy behaving like a list or a
tuple, in this respect?

Regards
Marco




-- 
Marco Bizzarri
http://iliveinpisa.blogspot.com/
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )