Project

General

Profile

« Previous | Next » 

Revision 2932

strings.py, sql_gen.py: Renamed add_suffix() to concat() to reflect that this is a fixed-length replacement for +

View differences:

lib/sql_gen.py
16 16

  
17 17
identifier_max_len = 63 # works for both PostgreSQL and MySQL
18 18

  
19
def add_suffix(str_, suffix):
19
def concat(str_, suffix):
20 20
    '''Preserves version so that it won't be truncated off the string, leading
21 21
    to collisions.'''
22 22
    # Preserve version
......
25 25
        str_ = before
26 26
        suffix = sep+version+suffix
27 27
    
28
    return strings.add_suffix(str_, suffix, identifier_max_len)
28
    return strings.concat(str_, suffix, identifier_max_len)
29 29

  
30
def truncate(str_): return add_suffix(str_, '')
30
def truncate(str_): return concat(str_, '')
31 31

  
32 32
def is_safe_name(name):
33 33
    '''A name is safe *and unambiguous* if it:
lib/sql.py
472 472
    if match:
473 473
        name, version = match.groups()
474 474
        version = int(version)+1
475
    return sql_gen.add_suffix(name, '#'+str(version))
475
    return sql_gen.concat(name, '#'+str(version))
476 476

  
477 477
def lock_table(db, table, mode):
478 478
    table = sql_gen.as_Table(table)
......
1280 1280
            sql_gen.ColValueCond(in_col, value))
1281 1281
    
1282 1282
    def insert_pkeys_table(which):
1283
        return sql_gen.Table(sql_gen.add_suffix(in_table.name,
1283
        return sql_gen.Table(sql_gen.concat(in_table.name,
1284 1284
            '_insert_'+which+'_pkeys'))
1285 1285
    insert_out_pkeys = insert_pkeys_table('out')
1286 1286
    insert_in_pkeys = insert_pkeys_table('in')
lib/strings.py
7 7

  
8 8
##### Parsing
9 9

  
10
def concat(str0, str1, max_len): return str0[:max_len-len(str1)]+str1
11

  
10 12
def split(sep, str_):
11 13
    '''Returns [] if str_ == ""'''
12 14
    if str_ == '': return []
......
32 34
    if removed_ref[0]: return str_[:-len(suffix)]
33 35
    else: return str_
34 36

  
35
def add_suffix(str_, suffix, max_len): return str_[:max_len-len(suffix)]+suffix
36

  
37 37
def contains_any(haystack, needles):
38 38
    for needle in needles:
39 39
        if haystack.find(needle) >= 0: return True

Also available in: Unified diff