Project

General

Profile

« Previous | Next » 

Revision 300

Renamed ex.py to exc.py

View differences:

lib/ex.py
1
# Exception handling
2

  
3
def add_msg(e, msg): e.args = (str(e).rstrip()+'\n'+msg,)
4

  
5
def repl_msg(e, **repls): e.args = (str(e) % repls,)
6

  
7
class ExceptionWithCause(Exception):
8
    def __init__(self, msg, cause=None):
9
        Exception.__init__(self, msg)
10
        if cause != None: add_msg(self, 'cause: '+str(cause))
lib/xml_func.py
2 2

  
3 3
import datetime
4 4

  
5
import ex
5
import exc
6 6
import xml_dom
7 7

  
8 8
class SyntaxException(Exception):
......
77 77
    if name.startswith('_') and name in funcs:
78 78
        try: value = funcs[name](xml_dom.NodeTextEntryIter(node))
79 79
        except SyntaxException, e:
80
            ex.add_msg(e, 'function: '+str(node))
80
            exc.add_msg(e, 'function: '+str(node))
81 81
            raise
82 82
        else: xml_dom.replace_with_text(node, value)
83 83
    else:
lib/sql.py
4 4
import re
5 5
import sys
6 6

  
7
import ex
7
import exc
8 8
import util
9 9

  
10 10
def get_cur_query(cur):
......
12 12
    elif hasattr(cur, '_last_executed'): return cur._last_executed
13 13
    else: return None
14 14

  
15
def _add_cursor_info(e, cur): ex.add_msg(e, 'query: '+get_cur_query(cur))
15
def _add_cursor_info(e, cur): exc.add_msg(e, 'query: '+get_cur_query(cur))
16 16

  
17 17
class NameException(Exception): pass
18 18

  
19
class DbException(ex.ExceptionWithCause):
19
class DbException(exc.ExceptionWithCause):
20 20
    def __init__(self, msg, cause=None, cur=None):
21
        ex.ExceptionWithCause.__init__(self, msg, cause)
21
        exc.ExceptionWithCause.__init__(self, msg, cause)
22 22
        if cur != None: _add_cursor_info(self, cur)
23 23

  
24 24
class ExceptionWithColumn(DbException):
lib/exc.py
1
# Exception handling
2

  
3
def add_msg(e, msg): e.args = (str(e).rstrip()+'\n'+msg,)
4

  
5
def repl_msg(e, **repls): e.args = (str(e) % repls,)
6

  
7
class ExceptionWithCause(Exception):
8
    def __init__(self, msg, cause=None):
9
        Exception.__init__(self, msg)
10
        if cause != None: add_msg(self, 'cause: '+str(cause))
lib/db_xml.py
89 89
            id_ = sql.get(db, table, row, pkey_, True, row_ct_ref)
90 90
            if store_ids: xml_dom.set_id(node, id_)
91 91
            break
92
        except sql.NullValueException, ex:
92
        except sql.NullValueException, e:
93 93
            if try_num > 0: raise # exception still raised after retry
94
            if store_ids and is_ptr(ex.col):
94
            if store_ids and is_ptr(e.col):
95 95
                # Search for required column in ancestors and their children
96
                target = find_by_name(node, ptr_type_guess(ex.col))
96
                target = find_by_name(node, ptr_type_guess(e.col))
97 97
                if target == None: raise
98
                row[ex.col] = xml_dom.get_id(target)
98
                row[e.col] = xml_dom.get_id(target)
99 99
            else: raise
100 100
    
101 101
    # Insert children with fkeys to parent

Also available in: Unified diff