Exemplo n.º 1
0
def wrap_with_abbreviation(abbr, text, syntax="html", profile="plain"):
    """
	Wraps passed text with abbreviation. Text will be placed inside last
	expanded element
	@param abbr: Abbreviation
	@type abbr: str
	
	@param text: Text to wrap
	@type text: str
	
	@param syntax: Document type (html, xml, etc.)
	@type syntax: str
	
	@param profile: Output profile's name.
	@type profile: str
	@return {String}
	"""
    tree_root = utils.parse_into_tree(abbr, syntax)
    pasted = False

    if tree_root:
        if tree_root.multiply_elem:
            # we have a repeating element, put content in
            tree_root.multiply_elem.set_paste_content(text)
            tree_root.multiply_elem.repeat_by_lines = pasted = True

        tree = utils.rollout_tree(tree_root)

        if not pasted:
            tree.paste_content(text)

        utils.apply_filters(tree, syntax, profile, tree_root.filters)
        return utils.replace_variables(tree.to_string())

    return None
Exemplo n.º 2
0
def wrap_with_abbreviation(abbr, text, syntax='html', profile='plain'):
    """
	Wraps passed text with abbreviation. Text will be placed inside last
	expanded element
	@param abbr: Abbreviation
	@type abbr: str
	
	@param text: Text to wrap
	@type text: str
	
	@param syntax: Document type (html, xml, etc.)
	@type syntax: str
	
	@param profile: Output profile's name.
	@type profile: str
	@return {String}
	"""
    tree_root = utils.parse_into_tree(abbr, syntax)
    pasted = False

    if tree_root:
        if tree_root.multiply_elem:
            # we have a repeating element, put content in
            tree_root.multiply_elem.set_paste_content(text)
            tree_root.multiply_elem.repeat_by_lines = pasted = True

        tree = utils.rollout_tree(tree_root)

        if not pasted:
            tree.paste_content(text)

        utils.apply_filters(tree, syntax, profile, tree_root.filters)
        return utils.replace_variables(tree.to_string())

    return None
Exemplo n.º 3
0
def expand_abbreviation(abbr, syntax='html', profile_name='plain'):
	"""
	Expands abbreviation into a XHTML tag string
	@type abbr: str
	@return: str
	"""
	tree_root = utils.parse_into_tree(abbr, syntax)
	if tree_root:
		tree = utils.rollout_tree(tree_root)
		utils.apply_filters(tree, syntax, profile_name, tree_root.filters)
		return utils.replace_variables(tree.to_string())
	
	return ''
Exemplo n.º 4
0
def expand_abbreviation(abbr, syntax='html', profile_name='plain'):
	"""
	Expands abbreviation into a XHTML tag string
	@type abbr: str
	@return: str
	"""
	tree_root = utils.parse_into_tree(abbr, syntax)
	if tree_root:
		tree = utils.rollout_tree(tree_root)
		utils.apply_filters(tree, syntax, profile_name, tree_root.filters)
		return utils.replace_variables(tree.to_string())
	
	return ''
Exemplo n.º 5
0
def check_tautology(input_string):
    is_tautology = True
    input_string = input_string.replace(" ", "")
    variables = get_variables(
        input_string)  # get list of distinct variables in string
    input_combos = truth_combos(
        variables)  # generate all possible input combinations
    for truth_values in input_combos:  # iterate over all input combinations
        valued_statement = replace_variables(
            input_string, truth_values
        )  # replace variables with their corresponding truth values
        new_statement = replace_negation(
            valued_statement)  # Replace all the negation operators directly
        postfix_expression = create_postfix(
            new_statement)  # create a postfix expresion
        result = evaluate_postfix(postfix_expression)  # Evaluate postfix
        if result != 1:
            is_tautology = False
            break
    return is_tautology
Exemplo n.º 6
0
 def test_multiple_variables(self):
     string = 'a|b'
     truth_values = {'a': 1, 'b': 0}
     output = replace_variables(string, truth_values)
     self.assertEqual(output, '1|0')
Exemplo n.º 7
0
 def test_simple_expr(self):
     string = 'a'
     truth_values = {'a': 1}
     output = replace_variables(string, truth_values)
     self.assertEqual(output, '1')