def make_tree(file):
max_files_count = current_app.config.get('<STR_LIT>', <NUM_LIT:1000>)<EOL>tree = {'<STR_LIT:type>': '<STR_LIT>', '<STR_LIT:id>': -<NUM_LIT:1>, '<STR_LIT>': {}}<EOL>try:<EOL><INDENT>with file.open() as fp:<EOL><INDENT>zf = zipfile.ZipFile(fp)<EOL>sample = '<STR_LIT:U+0020>'.join(zf.namelist()[:max_files_count])<EOL>if not isinstance(sample, binary_type):<EOL><INDENT>sample = sample.encode('<STR_LIT>')<EOL><DEDENT>encoding = chardet.detect(sample).get('<STR_LIT>', '<STR_LIT:utf-8>')<EOL>for i, info in enumerate(zf.infolist()):<EOL><INDENT>if i > max_files_count:<EOL><INDENT>raise BufferError('<STR_LIT>')<EOL><DEDENT>comps = info.filename.split(os.sep)<EOL>node = tree<EOL>for c in comps:<EOL><INDENT>if not isinstance(c, text_type):<EOL><INDENT>c = c.decode(encoding)<EOL><DEDENT>if c not in node['<STR_LIT>']:<EOL><INDENT>if c == '<STR_LIT>':<EOL><INDENT>node['<STR_LIT:type>'] = '<STR_LIT>'<EOL>continue<EOL><DEDENT>node['<STR_LIT>'][c] = {<EOL>'<STR_LIT:name>': c,<EOL>'<STR_LIT:type>': '<STR_LIT>',<EOL>'<STR_LIT:id>': '<STR_LIT>'.format(i),<EOL>'<STR_LIT>': {}<EOL>}<EOL><DEDENT>node = node['<STR_LIT>'][c]<EOL><DEDENT>node['<STR_LIT:size>'] = info.file_size<EOL><DEDENT><DEDENT><DEDENT>except BufferError:<EOL><INDENT>return tree, True, None<EOL><DEDENT>except (zipfile.LargeZipFile):<EOL><INDENT>return tree, False, '<STR_LIT>'<EOL><DEDENT>except Exception as e:<EOL><INDENT>current_app.logger.warning(str(e), exc_info=True)<EOL>return tree, False, '<STR_LIT>'<EOL><DEDENT>return tree, False, None<EOL>
Create tree structure from ZIP archive.