'Extract the ZipInfo object \'member\' to a physical
file on the path targetpath.'

def _extract_member(self, member, targetpath, pwd):

    arcname = member.filename.replace('/', os.path.sep)
    if os.path.altsep:
        arcname = arcname.replace(os.path.altsep, os.path.sep)
    arcname = os.path.splitdrive(arcname)[1]
    arcname = os.path.sep.join((x for x in arcname.split(os.path.sep) if (x not in ('', os.path.curdir, os.path.pardir))))
    if (os.path.sep == '\\'):
        illegal = ':<>|"?*'
        if isinstance(arcname, unicode):
            table = {ord(c): ord('_') for c in illegal}
        else:
            table = string.maketrans(illegal, ('_' * len(illegal)))
        arcname = arcname.translate(table)
        arcname = (x.rstrip('.') for x in arcname.split(os.path.sep))
        arcname = os.path.sep.join((x for x in arcname if x))
    targetpath = os.path.join(targetpath, arcname)
    targetpath = os.path.normpath(targetpath)
    upperdirs = os.path.dirname(targetpath)
    if (upperdirs and (not os.path.exists(upperdirs))):
        os.makedirs(upperdirs)
    if (member.filename[(-1)] == '/'):
        if (not os.path.isdir(targetpath)):
            os.mkdir(targetpath)
        return targetpath
    with self.open(member, pwd=pwd) as source:
        with file(targetpath, 'wb') as target:
            shutil.copyfileobj(source, target)
    return targetpath
