# Path: netjsonconfig/utils.py
# def sorted_dict(dict_):
#     return OrderedDict(sorted(dict_.items()))
# 
# Path: netjsonconfig/backends/base/parser.py
# class BaseParser(object):
#     """
#     Base Parser class
#     Parsers are used to parse a string or tar.gz
#     which represents the router configuration
#     """
# 
#     def __init__(self, config):
#         if isinstance(config, str):
#             data = self.parse_text(config)
#         # presence of read() method
#         # indicates a file-like object
#         elif hasattr(config, 'read'):
#             data = self.parse_tar(config)
#         else:
#             raise ParseError('Unrecognized format')
#         self.intermediate_data = data
# 
#     def parse_text(self, config):
#         raise NotImplementedError()
# 
#     def parse_tar(self, config):
#         raise NotImplementedError()


import re
import tarfile
from collections import OrderedDict
from ...utils import sorted_dict
from ..base.parser import BaseParser
        counter = 0
        for result in results:
            result = result.strip()
            if not result:
                continue
            counter += 1
            lines = result.split('\n')
            parts = lines[0].split()
            config_type = self._strip_quotes(parts[0])
            try:
                config_name = self._strip_quotes(parts[1])
            except IndexError:
                config_name = '{0}_{1}'.format(config_type, counter)
            block = OrderedDict()
            block['.type'] = config_type
            block['.name'] = config_name
            # loop over rest of lines
            for line in lines[1:]:
                match = re.search(config_pattern, line.strip())
                if not match:
                    continue
                parts = match.groups()
                key = self._strip_quotes(parts[1])
                value = self._strip_quotes(parts[2])
                # simple options
                if parts[0] == 'option':
                    block[key] = value
                # list options
                else:
                    block[key] = block.get(key, []) + [value]

# Path: netjsonconfig/utils.py
# def sorted_dict(dict_):
#     return OrderedDict(sorted(dict_.items()))
# 
# Path: netjsonconfig/backends/base/parser.py
# class BaseParser(object):
#     """
#     Base Parser class
#     Parsers are used to parse a string or tar.gz
#     which represents the router configuration
#     """
# 
#     def __init__(self, config):
#         if isinstance(config, str):
#             data = self.parse_text(config)
#         # presence of read() method
#         # indicates a file-like object
#         elif hasattr(config, 'read'):
#             data = self.parse_tar(config)
#         else:
#             raise ParseError('Unrecognized format')
#         self.intermediate_data = data
# 
#     def parse_text(self, config):
#         raise NotImplementedError()
# 
#     def parse_tar(self, config):
#         raise NotImplementedError()


# Path: netjsonconfig/backends/openwrt/parser.py
import re
import tarfile
from collections import OrderedDict
from ...utils import sorted_dict
from ..base.parser import BaseParser

        counter = 0
        for result in results:
            result = result.strip()
            if not result:
                continue
            counter += 1
            lines = result.split('\n')
            parts = lines[0].split()
            config_type = self._strip_quotes(parts[0])
            try:
                config_name = self._strip_quotes(parts[1])
            except IndexError:
                config_name = '{0}_{1}'.format(config_type, counter)
            block = OrderedDict()
            block['.type'] = config_type
            block['.name'] = config_name
            # loop over rest of lines
            for line in lines[1:]:
                match = re.search(config_pattern, line.strip())
                if not match:
                    continue
                parts = match.groups()
                key = self._strip_quotes(parts[1])
                value = self._strip_quotes(parts[2])
                # simple options
                if parts[0] == 'option':
                    block[key] = value
                # list options
                else:
                    block[key] = block.get(key, []) + [value]

            blocks.append(sorted_dict(block))