How to use the pyral.query_builder.RallyQueryFormatter function in pyral

To help you get started, we’ve selected a few pyral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RallyTools / RallyRestToolkitForPython / test / test_query.py View on Github external
def test_query_target_value_with_ampersand():
    """
        Query for a Project.Name = 'R&D'
    """
    criteria = ['Project.Name = R&D']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == 'Project.Name = R&D'.replace('&', '%26')

    criteria = ['Project.Name = "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == 'Project.Name = "R&D"'.replace('&', '%26')

    criteria = ['Project.Name contains "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == 'Project.Name contains "R&D"'.replace('&', '%26')

    criteria = 'Railhead.Company.Name != "Atchison Topeka & Santa Fe & Cunard Lines"'
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == criteria.replace('&', '%26')
github RallyTools / RallyRestToolkitForPython / pyral / query_builder.py View on Github external
if     criteria.count('(')  == 1    and criteria.count(')')  == 1    and \
               criteria.strip()[0]  == '('  and criteria.strip()[-1] == ')':
            return criteria.strip()[1:-1].replace(' ', '%20')
       
        # if caller has more than one opening paren, summarily return the query 
        # after stripping off the opening paren at the start of the string and the 
        # closing parent at the end of the string
        # The assumption is that the caller has correctly done the parenthisized grouping 
        # to end up in a binary form but we strip off the enclosing parens because the 
        # caller (RallyUrlBuilder) will be immediately supplying them after the return from here.
        if criteria.count('(') > 1:
            stripped_and_plugged  = criteria.strip()[1:-1].replace(' ', '%20')
            return stripped_and_plugged

        criteria = criteria.replace('&', '%26')        
        parts = RallyQueryFormatter.CONJUNCTION_PATT.split(criteria.strip())
##
##        print("RallyQueryFormatter parts: %s" % repr(parts))
##
        
        # if no CONJUNCTION is in parts, use the condition as is (simple case)
        conjunctions = [p for p in parts if p in RallyQueryFormatter.CONJUNCTIONS]
        if not conjunctions:
            expression = quote(criteria.strip()).replace('%28', '(').replace('%29', ')')
##
##            print("RallyQueryFormatter.no_conjunctions: |%s|" % expression)
##
            return expression

        parts = RallyQueryFormatter.validatePartsSyntax(parts)
        binary_expression = parts.pop()
        while parts:
github RallyTools / RallyRestToolkitForPython / pyral / query_builder.py View on Github external
criteria = criteria.replace('&', '%26')        
        parts = RallyQueryFormatter.CONJUNCTION_PATT.split(criteria.strip())
##
##        print("RallyQueryFormatter parts: %s" % repr(parts))
##
        
        # if no CONJUNCTION is in parts, use the condition as is (simple case)
        conjunctions = [p for p in parts if p in RallyQueryFormatter.CONJUNCTIONS]
        if not conjunctions:
            expression = quote(criteria.strip()).replace('%28', '(').replace('%29', ')')
##
##            print("RallyQueryFormatter.no_conjunctions: |%s|" % expression)
##
            return expression

        parts = RallyQueryFormatter.validatePartsSyntax(parts)
        binary_expression = parts.pop()
        while parts:
            item = parts.pop()
            if item in RallyQueryFormatter.CONJUNCTIONS:
                conj = item
                binary_expression = "%s (%s)" % (conj, binary_expression)
            else:
                cond = quote(item)
                binary_expression = "(%s) %s" % (cond, binary_expression)

        final_expression = binary_expression.replace('%28', '(')
        final_expression =  final_expression.replace('%29', ')')
##
##        print("RallyQueryFormatter.final_expression: |%s|" % final_expression)
##        print("==============================================")
##
github RallyTools / RallyRestToolkitForPython / pyral / query_builder.py View on Github external
# closing parent at the end of the string
        # The assumption is that the caller has correctly done the parenthisized grouping 
        # to end up in a binary form but we strip off the enclosing parens because the 
        # caller (RallyUrlBuilder) will be immediately supplying them after the return from here.
        if criteria.count('(') > 1:
            stripped_and_plugged  = criteria.strip()[1:-1].replace(' ', '%20')
            return stripped_and_plugged

        criteria = criteria.replace('&', '%26')        
        parts = RallyQueryFormatter.CONJUNCTION_PATT.split(criteria.strip())
##
##        print("RallyQueryFormatter parts: %s" % repr(parts))
##
        
        # if no CONJUNCTION is in parts, use the condition as is (simple case)
        conjunctions = [p for p in parts if p in RallyQueryFormatter.CONJUNCTIONS]
        if not conjunctions:
            expression = quote(criteria.strip()).replace('%28', '(').replace('%29', ')')
##
##            print("RallyQueryFormatter.no_conjunctions: |%s|" % expression)
##
            return expression

        parts = RallyQueryFormatter.validatePartsSyntax(parts)
        binary_expression = parts.pop()
        while parts:
            item = parts.pop()
            if item in RallyQueryFormatter.CONJUNCTIONS:
                conj = item
                binary_expression = "%s (%s)" % (conj, binary_expression)
            else:
                cond = quote(item)
github RallyTools / RallyRestToolkitForPython / pyral / query_builder.py View on Github external
elif unquoted_value_pattern.match(part):
                wordles = part.split(' ', 2)
                recast_part = '%s %s "%s"' % tuple(wordles)
                valid_parts.append(recast_part)
            else:
                if re.match(r'^(AND|OR)$', part, re.I):
                    valid_parts.append(part)
                else:
                    front = part + " "

        if not valid_parts:
            raise Exception("Invalid query expression syntax in: %s" % (" ".join(parts)))
        
        return valid_parts

AgileCentralQueryFormatter = RallyQueryFormatter