Revision 4067cdaf kamaki/clients/utils.py

b/kamaki/clients/utils.py
34 34

  
35 35
def matches(val1, val2, exactMath=True):
36 36
    """Case Insenstive match"""
37

  
37 38
    if exactMath:
38 39
        return True if val1.lower() == val2.lower() else False
39 40
    else:
......
44 45
    """@return a dict that contains the entries of d
45 46
        that are NOT prefixed with prefic
46 47
    """
48

  
47 49
    ret = {}
48 50
    for key, val in d.items():
49 51
        if not matches(key, prefix, exactMath=exactMatch):
......
55 57
    """@return a dict that contains only the entries of d
56 58
        that are prefixed with prefix
57 59
    """
60

  
58 61
    ret = {}
59 62
    for key, val in d.items():
60 63
        if matches(key, prefix, exactMath=exactMatch):
......
65 68
def prefix_keys(d, prefix):
66 69
    """@return a sallow copy of d with all its keys prefixed with prefix
67 70
    """
71

  
68 72
    ret = {}
69 73
    for key, val in d.items():
70 74
        ret[prefix + key] = val
......
75 79
    """@return a string with all args in the form /arg1/arg2/...
76 80
       @param args must be strings
77 81
    """
82

  
78 83
    path = ''
79 84
    for arg in args:
80 85
        suffix = unicode(arg)
......
92 97

  
93 98
def params4url(params):
94 99
    """@return a string with all params in the form ?key1=val1&key2=val2&...
95
            e.g. input
96
                {'key1':'val1', 'key2':None, 'key3':'val3'}
97
            will return
98
                ?key1=val1&key2&key3=val3
99 100
       @param should be a dict.
100
            Use params['somekey']=None for params that will apear without
101
            a value at the final string
102 101
    """
102

  
103 103
    assert(type(params) is dict)
104 104
    result = ''
105 105
    dlmtr = '?'
......
112 112

  
113 113
def list2str(alist, seperator=','):
114 114
    """@return a string of comma seperated elements of the list"""
115

  
115 116
    ret = ''
116 117
    slist = sorted(alist)
117 118
    for item in slist:

Also available in: Unified diff