Revision 691c81b7 lib/utils.py
b/lib/utils.py | ||
---|---|---|
2959 | 2959 |
return ", ".join([str(val) for val in names]) |
2960 | 2960 |
|
2961 | 2961 |
|
2962 |
def FindMatch(data, name): |
|
2963 |
"""Tries to find an item in a dictionary matching a name. |
|
2964 |
|
|
2965 |
Callers have to ensure the data names aren't contradictory (e.g. a regexp |
|
2966 |
that matches a string). If the name isn't a direct key, all regular |
|
2967 |
expression objects in the dictionary are matched against it. |
|
2968 |
|
|
2969 |
@type data: dict |
|
2970 |
@param data: Dictionary containing data |
|
2971 |
@type name: string |
|
2972 |
@param name: Name to look for |
|
2973 |
@rtype: tuple; (value in dictionary, matched groups as list) |
|
2974 |
|
|
2975 |
""" |
|
2976 |
if name in data: |
|
2977 |
return (data[name], []) |
|
2978 |
|
|
2979 |
for key, value in data.items(): |
|
2980 |
# Regex objects |
|
2981 |
if hasattr(key, "match"): |
|
2982 |
m = key.match(name) |
|
2983 |
if m: |
|
2984 |
return (value, list(m.groups())) |
|
2985 |
|
|
2986 |
return None |
|
2987 |
|
|
2988 |
|
|
2962 | 2989 |
def BytesToMebibyte(value): |
2963 | 2990 |
"""Converts bytes to mebibytes. |
2964 | 2991 |
|
Also available in: Unified diff