# Path: module/plugins/internal/misc.py
# def decode(value, encoding=None, errors='strict'):
#     """
#     Encoded string (default to own system encoding) -> unicode string
#     """
#     if isinstance(value, str):
#         res = unicode(
#             value, encoding or get_console_encoding(
#                 sys.stdout.encoding), errors)
# 
#     elif isinstance(value, unicode):
#         res = value
# 
#     else:
#         res = unicode(value)
# 
#     # Hotfix UnicodeDecodeError
#     try:
#         str(res)
#     except UnicodeEncodeError:
#         return normalize(res)
# 
#     return res
# 
# def encode(value, encoding='utf-8', errors='backslashreplace'):
#     """
#     Unicode string -> encoded string (default to UTF-8)
#     """
#     if isinstance(value, unicode):
#         res = value.encode(encoding, errors)
# 
#     elif isinstance(value, str):
#         decoding = get_console_encoding(sys.stdin.encoding)
#         if encoding == decoding:
#             res = value
#         else:
#             res = transcode(value, decoding, encoding)
# 
#     else:
#         res = str(value)
# 
#     return res


import re
import xml.dom.minidom
import Crypto.Cipher.AES
from ..internal.Container import Container
from ..internal.misc import decode, encode

        dlc_key = data[-88:]
        dlc_data = data[:-88].decode('base64')
        dlc_content = self.load(self.API_URL % dlc_key)

        try:
            rc = re.search(
                r'<rc>(.+)</rc>',
                dlc_content,
                re.S).group(1).decode('base64')

        except AttributeError:
            self.fail(_("Container is corrupted"))

        key = iv = Crypto.Cipher.AES.new(
            self.KEY, Crypto.Cipher.AES.MODE_CBC, self.IV).decrypt(rc)

        self.data = Crypto.Cipher.AES.new(
            key,
            Crypto.Cipher.AES.MODE_CBC,
            iv).decrypt(dlc_data).decode('base64')
        self.packages = [(name or pyfile.name, links, name or pyfile.name)
                         for name, links in self.get_packages()]

    def get_packages(self):
        root = xml.dom.minidom.parseString(self.data).documentElement
        content = root.getElementsByTagName("content")[0]
        return self.parse_packages(content)

    def parse_packages(self, startNode):

# Path: module/plugins/internal/misc.py
# def decode(value, encoding=None, errors='strict'):
#     """
#     Encoded string (default to own system encoding) -> unicode string
#     """
#     if isinstance(value, str):
#         res = unicode(
#             value, encoding or get_console_encoding(
#                 sys.stdout.encoding), errors)
# 
#     elif isinstance(value, unicode):
#         res = value
# 
#     else:
#         res = unicode(value)
# 
#     # Hotfix UnicodeDecodeError
#     try:
#         str(res)
#     except UnicodeEncodeError:
#         return normalize(res)
# 
#     return res
# 
# def encode(value, encoding='utf-8', errors='backslashreplace'):
#     """
#     Unicode string -> encoded string (default to UTF-8)
#     """
#     if isinstance(value, unicode):
#         res = value.encode(encoding, errors)
# 
#     elif isinstance(value, str):
#         decoding = get_console_encoding(sys.stdin.encoding)
#         if encoding == decoding:
#             res = value
#         else:
#             res = transcode(value, decoding, encoding)
# 
#     else:
#         res = str(value)
# 
#     return res


# Path: module/plugins/container/DLC.py
import re
import xml.dom.minidom
import Crypto.Cipher.AES
from ..internal.Container import Container
from ..internal.misc import decode, encode


        dlc_key = data[-88:]
        dlc_data = data[:-88].decode('base64')
        dlc_content = self.load(self.API_URL % dlc_key)

        try:
            rc = re.search(
                r'<rc>(.+)</rc>',
                dlc_content,
                re.S).group(1).decode('base64')

        except AttributeError:
            self.fail(_("Container is corrupted"))

        key = iv = Crypto.Cipher.AES.new(
            self.KEY, Crypto.Cipher.AES.MODE_CBC, self.IV).decrypt(rc)

        self.data = Crypto.Cipher.AES.new(
            key,
            Crypto.Cipher.AES.MODE_CBC,
            iv).decrypt(dlc_data).decode('base64')
        self.packages = [(name or pyfile.name, links, name or pyfile.name)
                         for name, links in self.get_packages()]

    def get_packages(self):
        root = xml.dom.minidom.parseString(self.data).documentElement
        content = root.getElementsByTagName("content")[0]
        return self.parse_packages(content)

    def parse_packages(self, startNode):

        return [(decode(node.getAttribute("name")).decode('base64'), self.parse_links(node))