def bz2_pack(source):
import bz2, base64<EOL>out = "<STR_LIT>"<EOL>first_line = source.split('<STR_LIT:\n>')[<NUM_LIT:0>]<EOL>if analyze.shebang.match(first_line):<EOL><INDENT>if py3:<EOL><INDENT>if first_line.rstrip().endswith('<STR_LIT>'): <EOL><INDENT>first_line = first_line.rstrip()<EOL>first_line += '<STR_LIT:3>' <EOL><DEDENT><DEDENT>out = first_line + '<STR_LIT:\n>'<EOL><DEDENT>compressed_source = bz2.compress(source.encode('<STR_LIT:utf-8>'))<EOL>out += '<STR_LIT>'<EOL>out += "<STR_LIT>"<EOL>out += base64.b64encode(compressed_source).decode('<STR_LIT:utf-8>')<EOL>out += "<STR_LIT>"<EOL>return out<EOL>
Returns 'source' as a bzip2-compressed, self-extracting python script.

.. note::

    This method uses up more space than the zip_pack method but it has the
    advantage in that the resulting .py file can still be imported into a
    python program.