本文整理汇总了Python中pyasm.common.Common.get_dict_list方法的典型用法代码示例。如果您正苦于以下问题:Python Common.get_dict_list方法的具体用法?Python Common.get_dict_list怎么用?Python Common.get_dict_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Common
的用法示例。
在下文中一共展示了Common.get_dict_list方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_access
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import get_dict_list [as 别名]
def get_access(my, type, key, default=None):
# if a list of keys is provided, then go through each key
if isinstance(key, list):
for item in key:
user_access = my.get_access(type, item)
if user_access != None:
return user_access
return None
# qualify the key with a project_code
project_code = "*"
if isinstance(key, dict):
# this avoids get_access() behavior changes on calling it twice
key2 = key.copy()
rule_project = key.get('project')
if rule_project:
project_code = rule_project
key2.pop('project')
key = Common.get_dict_list(key2)
# special case for projects
elif type == "project":
project_code = key
key = [('code','plugins')]
key = "%s?project=%s" % (key, project_code)
#print "key: ", key
# Fix added below to remove any unicode string markers from 'key' string ... sometimes the values
# of the 'key' dictionary that is passed in contains values that are unicode strings, and sometimes
# values that are ascii.
#
# FIXME: however might not necessarily be the best fix here, so this should be re-assessed at
# some point to see if a better fix can be put in place
# boris: Since we took out str() in Common.get_dict_list(), we have to re-introduce this back, but with , instead of : since it's a tuple
key = key.replace("', u'", "', '")
# if there are no rules, just return the default
rules = my.groups.get(type)
if not rules:
return default
result = None
value = rules.get(key)
if value:
result, dct = value
# DEPRECATED
if not result:
result = rules.get('__DEFAULT__')
if not result:
result = default
return result
示例2: add_xml_rules
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import get_dict_list [as 别名]
def add_xml_rules(my, xml):
'''xml should be an XML object with the data in the form of
<rules>
<group type='sobject' default='<default>'>
<rule key='<key>' access='<access>'/>
</group>
</rules>
'''
if isinstance(xml, basestring):
xmlx = Xml()
xmlx.read_string(xml)
xml = xmlx
my.xml = xml
# parse shorthand rules
rule_nodes = xml.get_nodes("rules/rule")
if not rule_nodes:
return
if my.project_codes == None:
search = Search('sthpw/project')
projects = search.get_sobjects()
my.project_codes = [x.get_code() for x in projects]
my.project_codes.append('*')
for rule_node in rule_nodes:
# initiate the project_code here for each loop
project_code = '*'
group_type = Xml.get_attribute( rule_node, "group" )
if not group_type:
# category is the preferred name over group now
# TODO: phase out the use of group completely
group_type = Xml.get_attribute( rule_node, "category" )
# get an existing rule set or create a new one
if my.groups.has_key(group_type):
rules = my.groups[group_type]
else:
rules = {}
my.groups[group_type] = rules
# set the default, if specified
group_default = xml.get_attribute( rule_node, "default" )
if group_default:
rules['__DEFAULT__'] = group_default
continue
# generate the rule key
#rule_key = xml.get_attribute(rule_node, 'key')
attrs = xml.get_attributes(rule_node)
attrs2 = {}
count = 0
for name, value in attrs.items():
if name in ['access', 'group', 'category', 'project']:
continue
# have to turn everything into strings
attrs2[str(name)] = str(value)
count += 1
if count == 1 and attrs2.has_key('key'):
# backwards compatibility
rule_key = attrs2['key']
else:
#rule_key = str(attrs2)
rule_key = str(Common.get_dict_list(attrs2))
rule_project = xml.get_attribute(rule_node, 'project')
if rule_project:
project_code = rule_project
# special treatment for search_filter to enable
# project-specific search
if group_type=='search_filter':
attrs2['project'] = rule_project
# if there is a value, then combine it with the key
rule_value = xml.get_attribute(rule_node, 'value')
if rule_value:
rule_key = "%s||%s" % (rule_key, rule_value)
# add a project code qualifier
rule_keys = []
if project_code == '*' and group_type != 'search_filter':
for code in my.project_codes:
key = "%s?project=%s" % (rule_key, code)
rule_keys.append(key)
else:
key= "%s?project=%s" % (rule_key, project_code)
#key = str(key) # may need to stringify unicode string
rule_keys.append(key)
rule_access = xml.get_attribute(rule_node, 'access')
#if rule_access == "":
#.........这里部分代码省略.........
示例3: get_access
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import get_dict_list [as 别名]
def get_access(my, group, key, default=None):
# if a list of keys is provided, then go through each key
if isinstance(key, list):
for item in key:
user_access = my.get_access(group, item)
if user_access != None:
return user_access
return None
# qualify the key with a project_code
project_code = "*"
rule_project = None
if isinstance(key, dict):
# this avoids get_access() behavior changes on calling it twice
key2 = key.copy()
rule_project = key.get('project')
if rule_project:
project_code = rule_project
key2.pop('project')
# backward compatibility with the key attribute
if len(key2) == 1 and key2.keys() == ['key']:
key = key2['key']
else:
key = Common.get_dict_list(key2)
if group == 'project':
key = str(key)
else:
key = "%s?project=%s" % (key, project_code)
# Fix added below to remove any unicode string markers from 'key' string ... sometimes the values
# of the 'key' dictionary that is passed in contains values that are unicode strings, and sometimes
# values that are ascii.
#
# FIXME: however might not necessarily be the best fix here, so this should be re-assessed at
# some point to see if a better fix can be put in place
# boris: Since we took out str() in Common.get_dict_list(), we have to re-introduce this back, but with , instead of : since it's a tuple
key = key.replace("', u'", "', '")
# if there are no rules, just return the default
rules = my.groups.get(group)
if not rules:
return default
result = None
value = rules.get(key)
if value:
result, dct = value
# if default is explicitly turned off by caller, don't use __DEFAULT__
if not result and default != None:
result = rules.get('__DEFAULT__')
if not result:
result = default
return result