Re: [Zope-dev] BUG: ValueError while changing height of the templateedit window

2002-12-11 Thread Dmitry Vasiliev
Casey Duncan wrote:

On Tuesday 10 December 2002 03:14 pm, Guido van Rossum wrote:


Can we get the same patch without the generic except:, please?

the last thing I want is a database corruption caused by resizing the
Edit box...


Why would this particular except clause cause database corruption?


I think Leonard is refering to catching ConflictErrors. However I don't think 
int() touches the database ;^).

I saw try: int() except: pattern in many places through all the Zope 
code. I think catching ValueError only does the job, but then we should 
replace it in all the places. :-)

--
Dmitry Vasiliev (dima at hlabs.spb.ru)


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


Re: [Zope-dev] BUG: ValueError while changing height of the templateedit window

2002-12-11 Thread Steve Alexander
Guido van Rossum wrote:

Can we get the same patch without the generic except:, please?


snipped part about whether there could be database corruption


int() happens to raise a bunch of different exceptions, and I think
an unqualified except: clause is okay here (though it needs a
comment).


I think this would be a useful note for the Zope3 style guide.


What exceptions can int() raise?

On converting a preexisting value to an int:

  ValueError, OverflowError, TypeError, AttributeError

  (Any others?)

On converting an instance that implements __int__:

  Anything at all.
  It can even return a non-int value.

On evaluating the expression inside the int() brackets:

  Anything at all.


I would suggest that only the four exceptions I listed first are worth 
catching. The other cases are programming errors.
Of those four exceptions, in this situation, I think you only need to 
catch ValueError. The other cases are application logic errors that I 
think it is counterproductive to catch. If you get one, there is a bug 
in some code, or some template, that should be fixed.


Here's how I produced the errors listed in the first category:

 int('xxx')
Traceback (most recent call last):
  File stdin, line 1, in ?
ValueError: invalid literal for int(): xxx

 import sys
 int(sys.maxint+1)
Traceback (most recent call last):
  File stdin, line 1, in ?
OverflowError: long int too large to convert to int

 int(int)
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: int() argument must be a string or a number

 int(AttributeError())
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: AttributeError instance has no attribute '__int__'

--
Steve Alexander


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


Re: [Zope-dev] BUG: ValueError while changing height of the templateedit window

2002-12-11 Thread Steve Alexander


Anything can raise MemoryError.


Ok. But I don't think regular application code should catch these.



On converting an 8bit string to an int:

 ValueError *only*


Ok.


On converting a Unicode string to an int:

 ValueError
 UnicodeError (or UnicodeEncodeError, which is a subclass of it)


Can you provide an example of raising a unicode error like this:

  u = makeUnicodeString()  # your choice of function
  int(u)

My point is that once you have a valid unicode object, I don't see how 
calling int(valid_unicode_object) will raise a UnicodeError.

If this is so, then the style should be:

  value = expression_to_compute_value
  try:
  i = int(value)
  except ValueError:
  # take corrective action

rather than:

  try:
  i = int(expression_to_compute_value)
  except:  # Note: calling 'int()' can raise just about anything
  # take corrective action


--
Steve Alexander



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


Re: [Zope-dev] BUG: ValueError while changing height of the templateedit window

2002-12-11 Thread Steve Alexander
I spoke too soon.  UnicodeEncodeError is a subclass of ValueError.  So
catching ValueError from int(str_or_unicode) is the way to go.  Who's
writing that Zope 3 style guide again?


Great.

http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ZopePythonStyleGuide

--
Steve Alexander


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


Re: [Zope-dev] BUG: ValueError while changing height of the templateedit window

2002-12-10 Thread Dmitry Vasiliev
Casey Duncan wrote:

Please submit a collector issue for this http://collector.zope.org/Zope so the 
patch doesn't get lost.


I tried it first, but my zope member login hadn't work yet and I had a 
problem with file uploading. I'm new with the collector, was I doing 
some things wrong?

--
Dmitry Vasiliev (dima at hlabs.spb.ru)


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