[Python-Dev] Terminology for PEP 343

Michael Sparks Michaels at rd.bbc.co.uk
Wed Jul 6 10:12:58 CEST 2005


On Monday 04 Jul 2005 03:10, Phillip J. Eby wrote:
> At 03:41 PM 7/3/2005 -0400, Raymond Hettinger wrote:
> >[Michael Hudson]
> > > This is possible.  I just wanted to expand everyone's minds :)
> > The mechanism is more general than resourcemanagement.  
> Expand your mind.  :) "Resource" can include whatever objects you want it
> to -- or no objects at all.

Is printing HTML and guaranteeing ending tags a resource ? I've been reading 
this thread, and been thinking that Holger Kregel's XPython hack could be 
implemented using the new with statement.

with some_encoding:
   with html:
      with body:
         with h1:
            print "Some heading"
         with p:
            print "This is paragraph 1"
         with p:
            print "This is paragraph 2"
         with h2:
            print "Another heading"

The enter/exit for html would be to print <html> </html> respectively and so 
on. (Though "p" would be special cased, etc)

Personally it seems to me that "with" is more a form of *guarantee* -
something that has a guard to enter the block, and something that
does something after the block.

From that perspective you could even imagine:

with enforce_conditions(pre,post):
   do some work.
   ...
   ...

enforce_conditions
   - enforces the "pre" before entering the block, and may choose to throw an
     exception if the precondition is false.
   - checks that "post" holds after the block, and may throw an exception if
     the postcondition is false.

Again, I don't really see that as a resource type scenario. It *may* involve
a resource scenario, but it may not. (eg did a condition finish within a 
certain time?)

Perhaps calling it a guarantor? (or similar)
   * You can guarantee that you have the lock on a resource if you enter the
      block ?
   * You can guarantee that you will have properly form (X|HT)ML if using an
     appropriate approach ?
   * You can guarantee checking of post conditions in a uniform manner ?

(Assumption: That the word guarantee in this case matches that of the intent)

If you just call the with statement a "resource manager" I suspect that people 
will more /naturally/ think just along the idea of resources, rather than 
also along the lines of things that need guarantees.

Is that really a resource type scenario? 

Best Regards,


Michael.
-- 
Michael Sparks, Senior R&D Engineer, Digital Media Group
Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This e-mail may contain personal views which are not the views of the BBC.


More information about the Python-Dev mailing list