<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mkdir(self, path, title="", recurse=False):
 """ Make a new directory. If recurse is True, create parent directories as required. Return the newly created TDirectory. """

        head, tail = os.path.split(os.path.normpath(path))
        if tail == "":
            raise ValueError("invalid directory name: {0}".format(path))
        with preserve_current_directory():
            dest = self
            if recurse:
                parent_dirs = head.split(os.path.sep)
                for parent_dir in parent_dirs:
                    try:
                        newdest = dest.GetDirectory(parent_dir)
                        dest = newdest
                    except DoesNotExist:
                        dest = dest.mkdir(parent_dir)
            elif head != "":
                dest = dest.GetDirectory(head)
            if tail in dest:
                raise ValueError("{0} already exists".format(path))
            newdir = asrootpy(super(_DirectoryBase, dest).mkdir(tail, title))
        return newdir