[POS-commit] CVS: StandalonePOS Admin.py,1.15.2.20,1.15.2.20.2.1 Catalog.py,1.10.2.5,1.10.2.5.2.1 INSTALL,1.1.2.2,1.1.2.2.2.1 Log.py,1.9.2.2,1.9.2.2.2.1 POS.py,1.9.2.17,1.9.2.17.2.1 install,1.1.2.1,1.1.2.1.2.1 install.py,1.1.2.30,1.1.2.30.2.1 setup.py,1.1.2.2,1.1.2.2.2.1

Christian Reis kiko at async.com.br
Fri Feb 14 01:31:16 BRDT 2003


On Thu, Feb 13, 2003 at 11:58:28PM -0200, Bruno Trevisan wrote:

Not to bother, but you can simplify these exceptions a lot. I'll
explain.

When catching an exception using Python, you can catch multiple
exceptions in a single clause. For instance:

> +class SalesPrinter:

[snip!]

> +        try:
> +            return getattr(self.conn, attr)
> +        except socket.error, msg:
> +            raise PrinterError, socket_error
> +        except socket.gaierror, msg:
> +            raise PrinterError, socket_error

These can be rewritten as:

    except (socket.error, socket.gaierror), msg:
        raise PrinterError, socket_error

(let's hope we don't have too many gai errors hihihi)
        
And this should be done for all these:

> +        except xmlrpclib.ProtocolError:
> +            raise PrinterError, "Protocol Error: " + \
> +                                    " check printer server configuration"
> +        except xmlrpclib.ResponseError:
> +            raise PrinterError, "Response Error: " + \
> +                                    "check printer server status"
> +        except xmlrpclib.Fault, msg:
> +            raise PrinterError, msg
> +
> +        except xmlrpclib.Error, msg:
> +            raise PrinterError, msg

And here:

> Index: POS.py
> @@ -581,21 +583,19 @@
>          if self.sale.can_close() and r:
>              try:
>                  self.sale.close()
> -            except FiscalPrinter.Error, e:
> -                self.win.statusbar.alert(
> -                    _("Error printing: %s") % e.msg ) 
> +            except PrinterError, msg:
> +                self.win.statusbar.alert("%s." % msg ) 
>                  try:
>                      get_printer().cancel_cupon()
> -                except FiscalPrinter.Error, e:
> -                    self.win.statusbar.alert(
> -                        _("Cancel error: %s") % e.msg ) 
> +                except PrinterError, msg:
> +                    self.win.statusbar.alert("%s." % msg) 
>                      return
>              except Domain.Sale.PrinterError, e:
> -                self.warnctl.run("%s." % e)
> +                self.warnctl.run("%s" % e)
>              except Domain.Sale.JournalError, e:
> -                self.warnctl.run("%s." % e)
> +                self.warnctl.run("%s" % e)
>              except Domain.Sale.PaymentError, e:
> -                self.warnctl.run("%s." % e)
> +                self.warnctl.run("%s" % e)
>              else:    

Okay?

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL


More information about the POS-commit mailing list