Re: [Python-Dev] Adding content to exception messages

2005-05-29 Thread Nicolas Fleury
Nick Coghlan wrote:
> With PEP 344, this could simply be:
> 
>try:
>parser.parseFile(file)
>exeption Exception, exception:
>raise type(exception)("Error at line %s in file %s" % (x,y))
> 
> Introspectively,
> Nick.
> 

It doesn't work (unless I misundertand you).  For example, the 
exceptions.UnicodeTranslateError constructor needs 4 arguments, not 1. 
That's the reason why I think a parallel mechanism is necessary to add 
additional information when it is necessary to keep the same exception type.

I probably didn't explain myself well too.  Suppose this very hacky 
implementation working with the statu quo:

class ExceptionStr:
 def __init__(self, content):
 self.content = content
 self.infos = []
 def addinfo(self, info):
 self.infos.insert(0, info)
 def __call__(self):
 return '\n'.join(self.infos + [self.content])

import sys
def reraise(exception, info=None):
 strFunc = getattr(exception, "__str__", None)
 if not isinstance(strFunc, ExceptionStr):
 strFunc = ExceptionStr(str(exception))
 exception.__str__ = strFunc
 if info:
 strFunc.addinfo(info)
 raise exception, None, sys.exc_info()[-1]

The following code:

try:
 try:
 raise Exception("hello")
 except Exception, exception:
 reraise(exception, "doing x")
except Exception, exception:
 reraise(exception, "doing y")

would produce something like:

Traceback (most recent call last):
   File "somefile.py", line 7, in ?
 reraise(exception, "doing y")
   File "somefile.py", line 5, in ?
 reraise(exception, "doing x")
   File "somefile..py", line 3, in ?
 raise Exception("hello")
Exception: doing y
doing x
hello

(Note that having the lines 5 and 7 in the traceback is not wanted)

What I propose is to instead have something like:

try:
 try:
 raise Exception("hello")
 except Exception, exception:
 # have some way to reraise a copy of "exception"
 # or the same exception with additional info "doing x"
 # For example:
 exception.addinfo("doing x")
 raise exception from exception.__context__
except Exception, exception:
 # Idem with "doing y"

And have as output:

Traceback (most recent call last):
   File "somefile..py", line 3, in ?
 raise Exception("hello")
Additional info:
   doing y
   doing x
Exception: hello

Regards,
Nicolas

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] python/dist/src/Lib/test test_site.py, 1.6, 1.7

2005-05-29 Thread Michael Hudson
Skip Montanaro <[EMAIL PROTECTED]> writes:

> mwh> Fix test_site to not call open('...', 'wU'), as that now raises an
> mwh> error.
>
> mwh> Is anyone running the test suite regularly at the moment?
>
> Whoops.  I obviously failed to run it after applying that change.  My
> apologies.

Well, it wasn't just that you didn't run the test suite, obviously
noone else did for about a week, either!

Cheers,
mwh

-- 
  ... the U.S. Department of Transportation today disclosed that its
  agents have recently cleared airport security checkpoints with an 
  M1 tank, a beluga whale, and a fully active South American volcano.
 -- http://www.satirewire.com/news/march02/screeners.shtml
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Split MIME headers into multiple lines near a space

2005-05-29 Thread Nick Coghlan
Noam Raphael wrote:
> Do you think it's ok? Could this be added to email.Header?

Noam posted a patch to SF (#1210680), and I assigned it to Barry to 
have a look at. Noam's suggestion seems reasonable to me, but I'm not 
sure what the performance implications are.

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
 http://boredomandlaziness.blogspot.com
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com