StackedObjectProxy (again)

2007-10-19 Thread Matt Feifarek
Some time ago, I wrote to the list to ask for help with StackedObjectProxy:

  [ Groups doesn't seem to have it in search results, but my message was on
Sept. 14 ]

I was never able to grok the instructions in the context of my app, so I
started with a naked pylons app and tried to figure it out. I made a
pylons_minimal app called sop and inside of sop there is a module called 
mymodule.py:

# mymodule.py
from paste.registry import StackedObjectProxy

real_container = {'val' : 'DEFAULT'}
sop_container = StackedObjectProxy(name=my container)

Then, I made a controller named ack.py:

#ack.py
import logging
from sop.controllers import *
log = logging.getLogger(__name__)

from sop.mymodule import sop_container

class AckController(BaseController):

def __call__(self, environ, start_response):
from sop.mymodule import sop_container, real_container
environ['paste.registry'].register(sop_container,
real_container)
return BaseController.__call__(self, environ, start_response)

def index(self):
return sop_container val is '%s' % sop_container['val']

def push(self):
sop_container['val'] = PUSHED
return pushed it: '%s' % sop_container['val']

Running this app and hitting http://localhost:5000/ack, I get the expected
result:

sop_container val is 'DEFAULT'

Then I hit http://localhost:5000/ack/push, I get:

pushed it: 'PUSHED'

Then when I hit index again, I get:

sop_container val is 'PUSHED'

...

So obviously I'm still misunderstanding something here. If sop_container is
a wrapper to real_container that exists per-request, why does val stay
PUSHED on another request? I was expecting the modified container (the one
that has PUSHED) to disappear after the request that set it that way was
done, leaving the container value as DEFAULT for other requests.

This trivial example begs the question: why would you want to do that? In my
real application, the container object is much more complex, is the answer.
I have some objects I want to use in a request-specific manner that I don't
want to re-instantiate for each request.

I have tried moving the register command out of the __call__ and into the
module level, and into the action itself, etc. No dice -- I get a thread
error.

Sorry if I'm being dense; I have really tried to grok the
StackedObjectProxy.__doc__ and also the email referenced above, but I just
don't seem to get it: I think I have a fundamental misunderstanding of the
nature of SOP. Can I get another nudge in the right direction?

Thanks!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Sessions - database or filesystem

2007-10-19 Thread Damjan

 If you're not clustered, I see no reason to use  the filesystem session as 
 it'll be faster.

no reason to use or not to use??


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Object is not callable thrown when accessing easyBay object

2007-10-19 Thread Jeff

Hi,

When trying to use easyBay, attempting to access the object returned
by the API causes the error below.

Code:
api = eBay(config=ebay.ini)
r = api.GetItem(ItemID=230180298347)
return r.Item.Title

I tested the above code standalone outside of Pylons and it returned
the result fine. Any idea why?

  log.debug(Controller returned a Response
object, merging 
  it with pylons.response)
response.headers.update(pylons.response.headers)
for c in pylons.response.cookies.values():
response.headers.add('Set-Cookie',
c.output(header=''))
response.headers.update(pylons.response.headers)
exceptions.TypeError: 'Node' object is not callable

Thanks,
Jeff


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



ToscaWidgets Tabber

2007-10-19 Thread Philip Cooper

I've started using some Toscawidgets and everything looks fine so far.

   OT: I've used them in TG and think that pylons should have some form 
of the widgetbroser.

I even easy_installed twTinyMCE and it ran fine (haven't found docs or 
examples on attributes or options thought).

Has anyone used twTabber?  It looks like an MIA widget.  I found the 
project on the turbogears trac but was wondering if there is a reason 
it's not released like twForms twTinyMCE twMochikit et. al.

On a related issue, I use Mochikit for some asnyc stuff.  Mochikit is 
built on Prototype and ${h.javascript_include_tag(builtins=True)} brings 
in both prototype and scritaculous.  Anyone have practical experience on 
how to limit all the reduddant js that starts flying around?

--
Phil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Paster web server crashing on image response

2007-10-19 Thread Razor19110

Doesn't fix it. I changed the function to be this instead:

def Photo_Test(self):
from PIL import Image
from StringIO import StringIO
lock.acquire()
f=open(test.jpg,rb)
data=f.read(100)
response.headers[content-type]=image/jpeg
response.write(data)
lock.release()

with the lock being defined at the top of the file.

I wouldn't expect it to fix it since it's just one user (me)
connecting and trying to get the image shouldn't be multithreaded.

Thanks.

On Oct 19, 3:01 am, zunzun [EMAIL PROTECTED] wrote:
 Try threadlocking PIL as I do here;

 http://wiki.pylonshq.com/display/pylonscommunity/Adding+graphical+output

  James

 On Oct 18, 2:26 am, Razor19110 [EMAIL PROTECTED] wrote:



  The test.jpg file is just a tiny test jpeg. When I run paster serve --
  reload development.ini and go to the page that would execute this
  function paster just quits, and the browser is left with an empty
  page.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: FormEncode form validators

2007-10-19 Thread Christoph Haas

On Thu, Oct 18, 2007 at 10:28:52PM -0400, Yannick Gingras wrote:
 Christoph Haas [EMAIL PROTECTED] writes:
 
  I could contribute validators for:
 
  - valid IPv4 network/address specifications
(e.g. 10.0.0.0/8 or 192.168.25.1 but not 1.2.3.4/123)
 
 Here is what I use for IPv4 addr ranges:
 
 from formencode import validators
 import iplib
 
 class CIDRValidator(validators.UnicodeString):
  An IP range in CIDR notation.  Single IP accepted without the
 '/32' qualifier.  An iplib.CIDR object is returned. 
 def _to_python(self, value, state):
 if iplib.is_dot(value):
 return iplib.CIDR(value+/32)
 try:
 return iplib.CIDR(value)
 except ValueError:
 raise validators.Invalid(
 Must be an IP range in CIDR notation. Ex: '192.168.0.0/24',
 val, 
 state)
 
 It requires iplib which plays badly with easy_install but it's a
 single python file so I repackage it in my project.

I did it without iplib:

class Cidr(formencode.FancyValidator):

Formencode validator to check whether a string is in correct CIDR
notation.

messages = {
'not_cidr_format' : u'Please enter a valid IP address (a.b.c.d) or 
IP network (a.b.c.d/e)',
'illegal_octets' : u'The octets must be within the range of 0-255',
'illegal_bits' : u'The network size (bits) must be within the range 
of 8-32',
}

def validate_python(self, value, state):
try:
# Split into octets and bits
if '/' in value: # a.b.c.d/e
addr, bits = value.split('/')
else: # a.b.c.d
addr, bits = value, 32

octets = addr.split('.')

# Only 4 octets?
if len(octets) != 4:
raise formencode.Invalid(self.message(not_cidr_format, 
state), value, state)

# Correct octets?
for octet in octets:
if int(octet)  0 or int(octet)  255:
raise formencode.Invalid(self.message(illegal_octets, 
octet), value, state)

# Bits (netmask) correct?
if int(bits)  8 or int(bits)  32:
raise formencode.Invalid(self.message(illegal_bits, 
bits), value, state)

# Splitting faild: wrong syntax
except ValueError:
raise formencode.Invalid(self.message(not_cidr_format, state), 
value, state)



And my MAC/hardware address validator:

class MacAddress(formencode.FancyValidator):

Formencode validator to check whether a string is a correct hardware
(MAC) address.

messages = {
'wrong_format' : u'Please enter a valid hardware (MAC) address (12 
hex digits)',
}

def validate_python(self, value, state):
address = value.replace(':','') # remove colons
if len(address)!=12:
raise formencode.Invalid(self.message(wrong_format, state), 
address, state)
for char in address:
if char not in string.hexdigits:
raise formencode.Invalid(self.message(wrong_format, state), 
address, state)



Feel free to use it if it's good enough. MIT license or whatever.

Cheers
 Christoph


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Messages in error documents

2007-10-19 Thread Yannick Gingras

Philip Jenvey [EMAIL PROTECTED] writes:

 You don't, at least not currently. Well, you could probably hack  
 something to do it like this (I think):

 def abort(code, detail, etc):
  request.environ['pylons.error.message'] = detail
  abort(code, detail, etc)

 Then grab request.environ['pylons.error.message'] in your  
 ErrorController (hopefully it's still there).

Nope, there is nothing in there when I arrive at the error controller.
The request is overwritten by paste.httpexceptions?

-- 
Yannick Gingras

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Paster web server crashing on image response

2007-10-19 Thread zunzun

Try threadlocking PIL as I do here;

http://wiki.pylonshq.com/display/pylonscommunity/Adding+graphical+output

 James


On Oct 18, 2:26 am, Razor19110 [EMAIL PROTECTED] wrote:

 The test.jpg file is just a tiny test jpeg. When I run paster serve --
 reload development.ini and go to the page that would execute this
 function paster just quits, and the browser is left with an empty
 page.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Reducing pylons app memory usage?

2007-10-19 Thread Marcin Kasperski

 I've run a few tests on my OSX machine, can you run them on your box?

Could you share the [EMAIL PROTECTED] of test apps? I wouldn't like to
experiment too much with creating them

 Cheap VPS's (like serveraxis.com) start around $30/mth with half
 a gig of ram, and a gig of swap...

Well, I wouldn't call $30/m cheap, at least considering I mean hobby
project, not a business one. Of course it matters that I earn in
Poland, not in US...
But this is outside the main discussion. Paying some attention to
the memory usage makes sense even in stronger setups, RAM is still
fairly often the main scalability limit in web setups.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: FormEncode form validators

2007-10-19 Thread iain duncan

On Wed, 2007-17-10 at 13:20 -0500, Ian Bicking wrote:
 FormEncode is overdue for a release, but before that a request: there 
 has been some mention that FormEncode should ship more useful form 
 validators.  For instance, FieldsMatch is an example of something 
 currently shipped, but about the only example.  Other examples would be 
 helpful.  Probably also something generic to do easy whole-dict 
 validation would be quite helpful.
 
 Do people have classes or recipes they've written that are general 
 enough to include directly in FormEncode?  If so, please contribute! 
 Realistic examples in the docstrings will be very helpful.

I made one that uses Tidy and (optionally) beautiful soupt for user
submitted html. I think it's not really anything others haven't done
before, but perhaps it would be useful. Would you be interested in
getting that if it's ok to have a validator depend on tidy lib?

You might want to ask on the Turbogears list too, lots of custom
validators get used there too.

Iain


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Reducing pylons app memory usage?

2007-10-19 Thread Marcin Kasperski

 Are the Zope and Moin numbers from the same environment your Pylons  
 is running on?

Yes. [EMAIL PROTECTED] in both cases.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Clearing sessions when paster is down

2007-10-19 Thread voltron

For one reason or the other, the paster serve might be down,
maintenance, errors e.t.c. This would cause errors on the client if
certain pages depend on various session variables.Is there a hook,
callback that one can use to trigger an action when the server is
going down to clear out all the sessions? Polling in intervals to see
if the server is up might not be fast enough.


Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---