On Feb 13, 2008 9:37 PM, Danek Duvall <[EMAIL PROTECTED]> wrote:
> On Wed, Feb 13, 2008 at 09:05:43PM -0600, Shawn Walker wrote:
>
> > >From publish.py:
> >
> >  94         status, id = t.open(config, pargs[0])
> >  95
> >  96         if status / 100 == 4 or status / 100 == 5:
> >  97                 print >> sys.stderr, \
> >  98                     _("pkgsend: server failed (status %s)") % status
> >  99                 sys.exit(1)
> >
> > If I'm reading this right, this is "clever code" that says that if the
> > response code returned is anything in the 400 or 500 range, it should
> > be considered an error.
>
> That's right.

For the record, that's the niftiest use I've seen of a language's
integer math in a while :-]

> > I was thinking of using a lambda to do a quasi-switch-case on the
> > response codes that are valid.
>
> What did you have in mind?  I mean, I think it'd be fine if you moved the

I can understand the desire to keep things simple, and let's be
honest, it's highly unlikely that the response code values are going
to change anytime soon :)

I can see a few possible approaches from here out:

* Leave the clever code, because it is rather nifty and takes
advantage of python's much-maligned integer math :)

* Use some a function that painfully lists out each enumerated
possible value but may miss some cases as you point out

* Consolidate the check in publish.py to a single function, so the
status checks can at least be maintained easier:

publish.py:96:        if status / 100 == 4 or status / 100 == 5:
publish.py:163:        if status / 100 == 4 or status / 100 == 5:
publish.py:189:                         if status / 100 == 4 or status
/ 100 == 5:

Leave the check here alone:
util/distro-import/solaris.py:377:        if status / 100 in (4, 5) or not id:

> two if-tests into a method if you want, but if you end up testing for each
> of the enumerated, named 4xx and 5xx codes in httplib, then you'll end up
> not catching other codes we might end up returning.

Why would we return codes that don't match up with the enumerated set?

Cheers,
-- 
Shawn Walker, Software and Systems Analyst
http://binarycrusader.blogspot.com/

"To err is human -- and to blame it on a computer is even more so." -
Robert Orben
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to