'assemble a file from a directory of fragments'

def _assemble_from_fragments(self, src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False, decrypt=True):

    (tmpfd, temp_path) = tempfile.mkstemp()
    tmp = os.fdopen(tmpfd, 'wb')
    delimit_me = False
    add_newline = False
    for f in (to_text(p, errors='surrogate_or_strict') for p in sorted(os.listdir(src_path))):
        if (compiled_regexp and (not compiled_regexp.search(f))):
            continue
        fragment = (u'%s/%s' % (src_path, f))
        if ((not os.path.isfile(fragment)) or (ignore_hidden and os.path.basename(fragment).startswith('.'))):
            continue
        fragment_content = open(self._loader.get_real_file(fragment, decrypt=decrypt), 'rb').read()
        if add_newline:
            tmp.write('\n')
        if delimit_me:
            if delimiter:
                delimiter = codecs.escape_decode(delimiter)[0]
                tmp.write(delimiter)
                if (delimiter[(-1)] != '\n'):
                    tmp.write('\n')
        tmp.write(fragment_content)
        delimit_me = True
        if fragment_content.endswith('\n'):
            add_newline = False
        else:
            add_newline = True
    tmp.close()
    return temp_path
