'take a path and make sure if fits within the chroot
remove \'../\', \'./\', and \'/\' from the beginning of path'

def _chrootize(self, name):

    normalized = os.path.normpath(os.path.abspath(name))
    if normalized.startswith(self.chroot):
        return normalized
    normalized = os.path.normpath(name)
    while True:
        if normalized.startswith('/'):
            normalized = normalized[1:]
        elif normalized.startswith('./'):
            normalized = normalized[2:]
        elif normalized.startswith('../'):
            normalized = normalized[3:]
        else:
            break
    return os.path.join(self.chroot, normalized)
