# 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
        packages = OrderedDict()
        for result in results:
            result = result.strip()
            if not result:
                continue
            lines = result.split('\n')
            name = lines[0]
            # fmt: off
            contents = result[len(name):]
            # fmt: on
            packages[name] = self._get_uci_blocks(contents)
        return packages

    def _get_uci_blocks(self, text):
        results = re.split(block_pattern, text)
        blocks = []
        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()

# 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

        packages = OrderedDict()
        for result in results:
            result = result.strip()
            if not result:
                continue
            lines = result.split('\n')
            name = lines[0]
            # fmt: off
            contents = result[len(name):]
            # fmt: on
            packages[name] = self._get_uci_blocks(contents)
        return packages

    def _get_uci_blocks(self, text):
        results = re.split(block_pattern, text)
        blocks = []
        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