def remake_connection(self, *args):
     if self.debug:
         return ' '.join(args)
     else:
         link_from = args[0]
         conn_type = args[1]
         link_to = args[2]
         return '%s %s %s' % (fut.strip_prefix(link_from, k_label_sep), 
                              conn_type, 
                              fut.strip_prefix(link_to, k_label_sep))
Beispiel #2
0
 def remake_connection(self, *args):
     # Expecting three args, e.g. 'filt_from', '>>>', 'filt_to'
     if self.debug:
         return ' '.join(args)
     else:
         link_from = args[0]
         conn_type = args[1]
         link_to = args[2]
         return '%s %s %s' % (fut.strip_prefix(link_from,
                                               k_label_sep), conn_type,
                              fut.strip_prefix(link_to, k_label_sep))
 def remake_connection(self, *args):
     # Expecting three args, e.g. 'filt_from', '>>>', 'filt_to'
     if self.debug:
         return ' '.join(args)
     else:
         link_from = args[0]
         conn_type = args[1]
         link_to = args[2]
         return '%s %s %s' % (fut.strip_prefix(link_from, k_label_sep), 
                              conn_type, 
                              fut.strip_prefix(link_to, k_label_sep))
Beispiel #4
0
 def pipeline_for_print(self, prefixed_route):
     result = []
     indent = 0
     base_indent = 4
     for x in prefixed_route.split():
         txt = x
         while '(' in txt:
             indent += base_indent
             txt = txt.replace('(', '$$OPEN$$', 1)
         new_indent = indent
         while ')' in txt:
             new_indent -= base_indent
             txt = txt.replace(')', '$$CLOSE$$', 1)
         txt = txt.replace('$$OPEN$$', '(')
         txt = txt.replace('$$CLOSE$$', ')')
         if not txt.endswith(')'):
             txt += ' >>>'
         if indent > 0 and txt.startswith('('):
             extra_in = base_indent - 1
         else:
             extra_in = base_indent
         result.append(' ' * (indent + extra_in) + \
                       fut.strip_prefix(txt, k_label_sep))
         indent = new_indent
     # Route can't end in a branch, so last line has spurious trailing '>>>'
     result[-1] = result[-1][:-4]
     return result
 def pipeline_for_print(self, prefixed_route):
     result = []
     indent = 0
     base_indent = 4
     for x in prefixed_route.split():
         txt = x
         while '(' in txt:
             indent += base_indent
             txt = txt.replace('(', '$$OPEN$$', 1)
         new_indent = indent
         while ')' in txt:
             new_indent -= base_indent
             txt = txt.replace(')', '$$CLOSE$$', 1)
         txt = txt.replace('$$OPEN$$', '(')
         txt = txt.replace('$$CLOSE$$', ')')
         if not txt.endswith(')'):
             txt += ' >>>'
         if indent > 0 and txt.startswith('('):
             extra_in = base_indent - 1
         else:
             extra_in = base_indent
         result.append(' ' * (indent + extra_in) + \
                       fut.strip_prefix(txt, k_label_sep))
         indent = new_indent
     # Route can't end in a branch, so last line has spurious trailing '>>>'
     result[-1] = result[-1][:-4]
     return result
    def parse_route(self, route_in, debug=False, tracking=False): 
        self.connections = []
        self.filter_dict = {}
        self.token_counter = 0
##        print '**16200** self = %s' % self
##        pprint.pprint(self.__dict__)
##        print '**16210** in parse_route, self.token_counter = %s' % (
##            self.token_counter)
        self.filter_counter = 0
        self.branch_counter = 0
        route2 = route_in.strip()
        if not route2:  # No input to parse
            return None, None, None
        # Make input into a branch, to simplify start/end handling. Therefore
        # it must not already start or end with parentheses. The newline is
        # needed before the final parenthesis to allow a trailing comment,
        # which would otherwise hide it, giving an "Unexpected end of file"
        # syntax error.
        route3 = self.parser.parse('(%s\n)' % route2, 
                                   debug=debug, tracking=tracking)
        if route3:
            route4 = route3.split('None ')[1]  # Remove leading None
            if not route4[0] == '(' or not route4[-1] == ')':
                raise SyntaxError, 'Bad parentheses in "%s"' % route4
            route_with_prefixes = route4[1:-1]  # Remove outer parentheses
            route5 = fut.strip_prefixes(route_with_prefixes,
                                         prefix_regex=r'\d\d\d\d' + k_label_sep)
            self.connections.sort()
            connections2_gen = (link.split() for link in self.connections)
            connections3 = [self.remake_connection(*link2) 
                            for link2 in connections2_gen]
            filters_gen = (fut.strip_prefix(link.split()[0], k_label_sep) 
                           for link in self.connections)
            # Maintain the order
            ##filters = [filt for filt in set(filters_gen)]
            filter_names = []
            for filt in filters_gen:
                if filt not in filter_names:
                    filter_names.append(filt)
            ##print '**10560** route5 = \n    %s\n-----------' % (
                ##route5.replace(' ', '\n    '))
            ##if connections3:
                ##self.print_connections(connections3)
                
            return route5, connections3, filter_names
        else:
            return None, None, None
Beispiel #7
0
 def test_strip_prefix(self):
     self.assertEquals(fut.strip_prefix('001~xx', '~'), 'xx')
     self.assertEquals(fut.strip_prefix('001~', '~'), '')
     self.assertEquals(fut.strip_prefix('~xx', '~'), 'xx')
     self.assertEquals(fut.strip_prefix('xx', '~'), 'xx')
     self.assertEquals(fut.strip_prefix('001-xx', '-'), 'xx')
 def test_strip_prefix(self):
     self.assertEquals(fut.strip_prefix('001~xx', '~'), 'xx')
     self.assertEquals(fut.strip_prefix('001~', '~'), '')
     self.assertEquals(fut.strip_prefix('~xx', '~'), 'xx')
     self.assertEquals(fut.strip_prefix('xx', '~'), 'xx')
     self.assertEquals(fut.strip_prefix('001-xx', '-'), 'xx')