本文整理汇总了Python中pyasm.biz.ExpressionParser.eval方法的典型用法代码示例。如果您正苦于以下问题:Python ExpressionParser.eval方法的具体用法?Python ExpressionParser.eval怎么用?Python ExpressionParser.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.biz.ExpressionParser
的用法示例。
在下文中一共展示了ExpressionParser.eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def init(my):
list_item_table = ''
my.full_item_list = []
if my.kwargs.has_key( 'list_item_table' ):
list_item_table = my.kwargs.get( 'list_item_table' )
expr = '@SOBJECT(MMS/%s)' % list_item_table
parser = ExpressionParser()
my.full_item_list = parser.eval(expr)
my.el_name = ''
if my.kwargs.has_key( 'element_name' ):
my.el_name = my.kwargs.get( 'element_name' )
my.input_el_name = ''
if my.kwargs.has_key( 'input_element_to_find' ):
my.input_el_name = my.kwargs.get( 'input_element_to_find' )
my.col_to_match = ''
if my.kwargs.has_key( 'column_to_match_value' ):
my.col_to_match = my.kwargs.get( 'column_to_match_value' )
my.col_for_label = ''
if my.kwargs.has_key( 'column_for_label' ):
my.col_for_label = my.kwargs.get( 'column_for_label' )
my.select_element = HtmlElement('select')
示例2: get_group_bottom_wdg
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_group_bottom_wdg(my, sobjects):
expression = my.get_option("group_bottom")
if not expression:
return None
# parse the expression
my.vars = my.get_vars()
parser = ExpressionParser()
result = parser.eval(expression, sobjects=sobjects, vars=my.vars)
format_str = my.kwargs.get("display_format")
if format_str:
from tactic.ui.widget import FormatValueWdg
format_wdg = FormatValueWdg(format=format_str, value=result)
result = format_wdg
else:
result = str(result)
div = DivWdg()
div.add(result)
div.add_style("text-align: right")
# div.add_class( "spt_%s_expr_bottom" % (my.get_name()) )
# add a listener
# for sobject in sobjects:
# if sobject.is_insert():
# continue
#
# if my.enable_eval_listener:
# my.add_js_expression(div, sobject, expression)
return div
示例3: cache
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def cache(self):
# get the value from cache
from pyasm.biz import ExpressionParser
parser = ExpressionParser()
logins = parser.eval("@SOBJECT(sthpw/login)")
self.attrs[self.key] = logins
示例4: get_message
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_message(my):
search_type_obj = my.sobject.get_search_type_obj()
title = search_type_obj.get_title()
subject = my.get_subject()
notification_message = my.notification.get_value("message")
if notification_message:
# parse it through the expression
sudo = Sudo()
parser = ExpressionParser()
snapshot = my.input.get('snapshot')
env_sobjects = {}
# turn prev_data and update_data from input into sobjects
prev_data = SearchType.create("sthpw/virtual")
id_col = prev_data.get_id_col()
if id_col:
del prev_data.data[id_col]
prev_dict = my.input.get("prev_data")
if prev_dict:
for name, value in prev_dict.items():
if value != None:
prev_data.set_value(name, value)
update_data = SearchType.create("sthpw/virtual")
id_col = update_data.get_id_col()
if id_col:
del update_data.data[id_col]
update_dict = my.input.get("update_data")
if update_dict:
for name, value in update_dict.items():
if value != None:
update_data.set_value(name, value)
if snapshot:
env_sobjects = {
'snapshot': snapshot
}
env_sobjects['prev_data'] = prev_data
env_sobjects['update_data'] = update_data
notification_message = parser.eval(notification_message, my.sobject, env_sobjects=env_sobjects, mode='string')
del sudo
return notification_message
message = "%s %s" % (title, my.sobject.get_name())
message = '%s\n\nReport from transaction:\n%s\n' % (message, subject)
return message
示例5: get_subject
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_subject(my):
subject = my.notification.get_value("subject",no_exception=True)
if subject:
# parse it through the expression
sudo = Sudo()
parser = ExpressionParser()
subject = parser.eval(subject, my.sobject, mode='string')
del sudo
else:
subject = '%s - %s' %(my.sobject.get_update_description(), my.command.get_description())
return subject
示例6: get_display
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_display(my):
filter_data = FilterData.get_from_cgi()
values = filter_data.get_values("custom", "year")
year = 0
for value in values:
if value:
try:
year = int(value)
except:
pass
if not year:
date = Date()
year = int(date.get_year())
sobject = my.get_current_sobject()
id = sobject.get_id()
column = my.get_option("column")
month = int( my.get_option('month') )
end_year = year
end_month = month + 1
if end_month > 12:
end_month = 1
end_year += 1
search_type = 'MMS/personal_time_log'
if year:
search = Search(search_type)
search.add_filter('login_id', id)
search.add_filter('work_performed_date', '%s-%0.2d-01' % (year,month), '>')
search.add_filter('work_performed_date', '%s-%0.2d-01' % (end_year,end_month), '<')
sobjects = search.get_sobjects()
else:
sobjects = []
if sobjects:
parser = ExpressionParser()
sum = parser.eval("@SUM(%s.%s)" % (search_type,column),sobjects=sobjects)
else:
sum = 0
div = DivWdg()
div.add(sum)
return div
示例7: get_display
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_display(my):
sobject = my.get_current_sobject()
expression = my.get_option("expression")
parser = ExpressionParser()
value = parser.eval(expression, sobject)
div = DivWdg()
div.add_style("text-align: center")
if value == False:
div.add( IconWdg("XXX", IconWdg.DOT_GREEN) )
else:
div.add( IconWdg("YYY", IconWdg.DOT_RED) )
return div
示例8: get_message
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_message(my):
search_type_obj = my.sobject.get_search_type_obj()
title = search_type_obj.get_title()
subject = my.get_subject()
notification_message = my.notification.get_value("message")
if notification_message:
# parse it through the expression
sudo = Sudo()
parser = ExpressionParser()
notification_message = parser.eval(notification_message, my.sobject, mode='string')
del sudo
return notification_message
message = "%s %s" % (title, my.sobject.get_name())
message = '%s\n\nReport from transaction:\n%s\n' % (message, subject)
return message
示例9: get_bottom_wdg
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def get_bottom_wdg(my):
my.init_kwargs()
sobjects = my.sobjects
# ignore the first 2 (edit and insert) if it's on the old TableLayoutWdg
if my.get_layout_wdg().get_layout_version() == '1':
sobjects = sobjects[2:]
if not sobjects:
return None
expression = my.get_option("bottom")
if not expression:
return None
# parse the expression
my.vars = my.get_vars()
parser = ExpressionParser()
result = parser.eval(expression, sobjects=sobjects, vars=my.vars)
format_str = my.kwargs.get("display_format")
if format_str:
from tactic.ui.widget import FormatValueWdg
format_wdg = FormatValueWdg(format=format_str, value=result)
result = format_wdg
else:
result = str(result)
div = DivWdg()
div.add(result)
div.add_style("text-align: right")
div.add_class( "spt_%s_expr_bottom" % (my.get_name()) )
# add a listener
for sobject in sobjects:
if sobject.is_insert():
continue
if my.enable_eval_listener:
my.add_js_expression(div, sobject, expression)
return div
示例10: get_display
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
#.........这里部分代码省略.........
include_mako = my.view_attrs.get("include_mako")
if xml:
mako_node = xml.get_node("config/%s/mako" % my.view)
if mako_node is not None:
mako_str = xml.get_node_value(mako_node)
html = "<%%\n%s\n%%>\n%s" % (mako_str, html)
from pyasm.web import Palette
num_palettes = Palette.num_palettes()
#if include_mako in ['true', True]:
if include_mako not in ['false', False]:
html = html.replace("<", "<")
html = html.replace(">", ">")
html = my.process_mako(html)
# preparse out expressions
# use relative expressions - [expr]xxx[/expr]
p = re.compile('\[expr\](.*?)\[\/expr\]')
parser = ExpressionParser()
matches = p.finditer(html)
for m in matches:
full_expr = m.group()
expr = m.groups()[0]
result = parser.eval(expr, sobjects, single=True, state=my.state)
if isinstance(result, basestring):
result = Common.process_unicode_string(result)
else:
result = str(result)
html = html.replace(full_expr, result )
# use absolute expressions - [expr]xxx[/expr]
p = re.compile('\[abs_expr\](.*?)\[\/abs_expr\]')
parser = ExpressionParser()
matches = p.finditer(html)
for m in matches:
full_expr = m.group()
expr = m.groups()[0]
result = parser.eval(expr, single=True)
if isinstance(result, basestring):
result = Common.process_unicode_string(result)
else:
result = str(result)
html = html.replace(full_expr, result )
# need a top widget that can be used to refresh
top = my.top
my.set_as_panel(top)
top.add_class("spt_custom_top")
ignore_events = my.kwargs.get("ignore_events") in ['true', True]
if ignore_events:
top.add_style("pointer-events: none")
示例11: alter_search
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def alter_search(my, search):
if my.is_admin_flag:
return True
group = "search_filter"
search_type = search.get_base_search_type()
my.alter_search_type_search(search)
# qualify the key with a project_code
#project_code = "*"
#key = "%s?project=%s" % (key, project_code)
rules = my.groups.get(group)
if not rules:
return
from pyasm.biz import ExpressionParser
parser = ExpressionParser()
current_project = None
for rule in rules.values():
access, dct = rule
"""
# FIXME: hacky: break the encoding done earlier
parts = rule.split("||")
data = parts[0]
data = data.replace("?project=*", "")
rule = eval(data)
"""
rule = dct
rule_search_type = rule.get('search_type')
if not rule_search_type:
print "No [search_type] defined in security rule"
continue
# search types must match
if rule_search_type != search_type:
continue
column = rule.get('column')
value = rule.get('value')
project = rule.get('project')
# to avoid infinite recursion, get the project here
if not current_project:
from pyasm.biz import Project
current_project = Project.get_project_code()
if project and project not in ['*', current_project]:
continue
# If a relationship is set, then use that
# FIXME: this is not very clear how to procede.
related = rule.get('related')
#if search_type == 'MMS/job':
# related = "@SOBJECT(MMS/request)"
sudo = Sudo()
if related:
sobjects = parser.eval(related)
search.add_relationship_filters(sobjects)
del sudo
return
# interpret the value
# since the expression runs float(), we want to avoid that a number 5 being converted to 5.0
# if we can't find @ or $
if value.find('@') != -1 or value.find('$') != -1:
values = parser.eval(value, list=True)
else:
values = [value]
op = rule.get('op')
# TODO: made this work with search.add_op_filters() with the expression parser instead of this
# simpler implementation
if len(values) == 1:
if not op:
op = '='
quoted = True
# special case for NULL
if values[0] == 'NULL':
quoted = False
if op in ['not in', '!=']:
search.add_op('begin')
search.add_filter(column, values[0], op=op, quoted=quoted)
search.add_filter(column, None)
search.add_op('or')
else:
search.add_filter(column, values[0], op=op, quoted=quoted)
elif len(values) > 1:
if not op:
op = 'in'
if op in ['not in', '!=']:
search.add_op('begin')
#.........这里部分代码省略.........
示例12: handle_sobject
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def handle_sobject(my, main_sobject, caller, notification, input):
# TODO: deal with parents later
parent = main_sobject.get_parent()
snapshot = input.get('snapshot')
env_sobjects = {}
if snapshot:
env_sobjects = {
'snapshot': snapshot
}
# get the rules from the database
rules_xml = notification.get_xml_value("rules")
rule_nodes = rules_xml.get_nodes("rules/rule")
is_skipped = True
parser = ExpressionParser()
# process the rules
for rule_node in rule_nodes:
rule = []
group_type = Xml.get_attribute( rule_node, "group" )
rule_key = Xml.get_attribute(rule_node, 'key')
rule_value = Xml.get_attribute(rule_node, 'value')
compare = Xml.get_attribute(rule_node, 'compare')
# evaluate the expression if it exists
expression = Xml.get_node_value(rule_node)
if expression:
result = parser.eval(expression, main_sobject, env_sobjects=env_sobjects)
if not result:
break
else:
continue
# DEPRECATED: likely the expression complete replaces this
# parse the rule
if group_type == "sobject":
if not my._process_sobject(main_sobject, rule_key, compare):
break
value = main_sobject.get_value(rule_key, no_exception=True )
elif group_type == "parent":
if not parent or not my._process_sobject(parent, rule_key, compare):
break
value = parent.get_value(rule_key, no_exception=True )
else: # group_type == 'command'
try:
value = caller.get_info(rule_key)
except:
value = ''
if not value:
break
# match the rule to the value
p = re.compile(rule_value)
if not p.match(value):
print "... skipping: '%s' != %s" % (value, rule_value)
break
else:
is_skipped = False
# allow the handler to check for whether an email should be sent
handler = my.get_email_handler(notification, main_sobject, parent, caller, input)
if is_skipped or not handler.check_rule():
my.add_description('Notification not sent due to failure to pass the set rules. Comment out the rules for now if you are just running email test.')
return
print "sending email!!!"
# if all rules are met then get the groups for this notification
try:
to_users = handler.get_to()
cc_users = handler.get_cc()
bcc_users = handler.get_bcc()
subject = handler.get_subject()
if len(subject) > 60:
subject = subject[0:60] + " ..."
message = handler.get_message()
except SObjectValueException, e:
raise Exception("Error in running Email handler [%s]. %s" \
%(handler.__class__.__name__, e.__str__()))
示例13: alter_search
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def alter_search(self, search):
if self.is_admin_flag:
return True
group = "search_filter"
search_type = search.get_base_search_type()
self.alter_search_type_search(search)
rules = self.groups.get(group)
if not rules:
return
from pyasm.biz import ExpressionParser
parser = ExpressionParser()
current_project = None
# preprocess to get a list of rule that will apply
rules_dict = {}
for rule_item in rules.values():
access, dct = rule_item
rule = dct
rule_search_type = rule.get('search_type')
if not rule_search_type:
print "No [search_type] defined in security rule"
continue
# search types must match
if rule_search_type != search_type:
continue
project = rule.get('project')
# to avoid infinite recursion, get the project here
if not current_project:
from pyasm.biz import Project
current_project = Project.get_project_code()
if project and project not in ['*', current_project]:
continue
column = rule.get('column')
rules_list = rules_dict.get(column)
if rules_list == None:
rules_list = []
rules_dict[column] = rules_list
rules_list.append(rule)
for column, rules_list in rules_dict.items():
if len(rules_list) > 1:
search.add_op("begin")
for rule in rules_list:
column = rule.get('column')
value = rule.get('value')
# If a relationship is set, then use that
related = rule.get('related')
sudo = Sudo()
if related:
sobjects = parser.eval(related)
search.add_relationship_filters(sobjects)
del sudo
return
# interpret the value
# since the expression runs float(), we want to avoid that a number 5 being converted to 5.0
# if we can't find @ or $
if value.find('@') != -1 or value.find('$') != -1:
values = parser.eval(value, list=True)
elif value.find("|") == -1:
values = value.split("|")
else:
values = [value]
op = rule.get('op')
# TODO: made this work with search.add_op_filters() with the expression parser instead of this
# simpler implementation
if len(values) == 1:
if not op:
op = '='
quoted = True
# special case for NULL
if values[0] == 'NULL':
quoted = False
#.........这里部分代码省略.........
示例14: process_data_gather
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def process_data_gather( self, search_key, gather_specs, layout_html ):
sobject = Search.get_by_search_key( search_key )
for label,info in gather_specs.iteritems():
if label == "@":
subs_list = info.get("element_subs")
for sub in subs_list:
value = sobject.get_value( sub )
if not value:
value = " "
substitution_tag = "${@.%s}" % sub
layout_html = layout_html.replace( substitution_tag, "%s" % value )
elif info.get("type") == "sobject":
expr = info.get("expr")
expr_vars_list = info.get("expr_vars")
if expr_vars_list:
for e_var in expr_vars_list:
bits = e_var.split("=")
var_name = bits[0]
value = sobject.get_value( bits[1].replace("@.","") )
expr = expr.replace( var_name, "%s" % value )
parser = ExpressionParser()
result = parser.eval( expr )
if result:
if type(result) == types.ListType:
other_sobject = result[0]
else:
other_sobject = result
subs_list = info.get("element_subs")
for sub in subs_list:
src_col = sub
dst_col = sub
if "#" in sub:
sub_bits = sub.split("#")
src_col = sub_bits[0]
dst_col = sub_bits[1]
value = other_sobject.get_value( src_col )
if not value:
value = " "
if "_date" in dst_col:
value = value.split(" ")[0]
if "_time" in dst_col:
time_bits = value.split(" ")[1].split(":")
value = "%s:%s" % (time_bits[0], time_bits[1])
substitution_tag = "${%s.%s}" % (label, dst_col )
layout_html = layout_html.replace( substitution_tag, "%s" % value )
elif info.get("type") == "gather_list_class":
import_stmt = "%s as GatherClass" % info.get("import_stmt")
exec import_stmt
gc = GatherClass( sobject )
item_list = gc.get_items()
subs_list = info.get("element_subs")
for c, item in enumerate(item_list):
for sub in subs_list:
substitution_tag = "${%s[%s].%s}" % (label, c, sub)
layout_html = layout_html.replace( substitution_tag, "%s" % item[ sub ] )
max_id = info.get("max_id")
if max_id > (len(item_list) - 1):
for c in range(len(item_list),max_id+1):
for sub in subs_list:
substitution_tag = "${%s[%s].%s}" % (label, c, sub)
layout_html = layout_html.replace( substitution_tag, " " )
elif info.get("type") == "value":
parser = ExpressionParser()
value = parser.eval( info.get("expr"), sobject )
if not value:
value = " "
layout_html = layout_html.replace( "${%s}" % label, "%s" % value )
return layout_html
示例15: _get_result
# 需要导入模块: from pyasm.biz import ExpressionParser [as 别名]
# 或者: from pyasm.biz.ExpressionParser import eval [as 别名]
def _get_result(self, sobject, expression):
'''get the result of the expression'''
element_name = self.get_name()
use_cache = self.kwargs.get("use_cache")
if use_cache == "true":
try:
return sobject.get_value(element_name)
except Exception as e:
print "Error: ", e.message
if type(sobject) != types.ListType:
if sobject.is_insert():
return ''
self.vars = {
'ELEMENT_NAME': element_name,
'ELEMENT': element_name,
'SOBJECT_ID': sobject.get_id(),
'SOBJECT_CODE': sobject.get_code(),
}
return_type = self.kwargs.get("return")
if return_type == 'single':
single = True
list = False
elif return_type == 'list':
single = False
list = True
else:
single = True
list = False
# if this expression is an absolute expression, then don't bother
# with the sobject
expression_mode = self.get_option('expression_mode')
if expression_mode == 'absolute':
sobject = None
calc_mode = self.get_option("calc_mode")
if not calc_mode:
calc_mode = 'slow'
#calc_mode = 'fast'
# parse the expression
parser = ExpressionParser()
if calc_mode == 'fast':
if self.cache_results == None:
self.cache_results = parser.eval(expression, self.sobjects, vars=self.vars, dictionary=True, show_retired=self.show_retired)
if isinstance(self.cache_results, basestring):
if self.cache_results:
self.cache_results = eval(self.cache_results)
else:
self.cache_results = {}
search_key = sobject.get_search_key()
result = self.cache_results.get(search_key)
if single:
if result and len(result):
result = result[0]
else:
result = ''
else:
result = parser.eval(expression, sobject, vars=self.vars, single=single, list=list, show_retired=self.show_retired)
# FIXME: don't know how to do this any other way
try:
if not list:
result = result.get_display_value()
except AttributeError, e:
pass