I think something like this should work better then vim.command('silent! cd ' + 
path) with or without escaping

(untested, do not apply this patch now):

diff -r bca5a13b9afd runtime/doc/if_pyth.txt
--- a/runtime/doc/if_pyth.txt   Fri May 31 06:59:29 2013 +0400
+++ b/runtime/doc/if_pyth.txt   Fri May 31 08:23:50 2013 +0400
@@ -176,6 +176,16 @@
        |python-bindeval-objects|. These python objects let you modify (|List| 
        or |Dictionary|) or call (|Funcref|) vim objecs.
 
+vim.strwidth(str)                                      *python-strwidth*
+       Like |strwidth()|: returns number of display cells str occupies, tab 
+       is counted as one cell.
+
+vim.chdir(dir, local=False)                            *python-chdir*
+       Change current directory running all appropriate vim stuff. If local 
+       is set to True acts as |:lcd|.
+       Note: "-" special directory is not supported: it tries to cd to 
+       directory named "-".
+
 Error object of the "vim" module
 
 vim.error                                              *python-error*
@@ -329,6 +339,8 @@
                        |BufFilePost| autocommands are launched.
        b.number        Buffer number. Can be used as |python-buffers| key.
                        Read-only.
+       b.valid         True or False. Buffer becames invalid when it is wiped 
+                       out.
 
 The buffer object methods are:
        b.append(str)   Append a line to the buffer
@@ -433,6 +445,8 @@
        row, col (read-only)    On-screen window position in display cells.
                                First position is zero.
        tabpage (read-only)     Window tab page.
+       valid (read-write)      True or False. Window becames invalid when it 
+                               is closed.
 
 The height attribute is writable only if the screen is split horizontally.
 The width attribute is writable only if the screen is split vertically.
@@ -456,6 +470,8 @@
        windows         Like |python-windows|, but for current tab page.
        vars            The tab page |t:| variables.
        window          Current tabpage window.
+       valid           True or False. Tab page becames invalid when it is 
+                       closed.
 
 TabPage object type is available using "TabPage" attribute of vim module.
 
diff -r bca5a13b9afd src/ex_docmd.c
--- a/src/ex_docmd.c    Fri May 31 06:59:29 2013 +0400
+++ b/src/ex_docmd.c    Fri May 31 08:23:50 2013 +0400
@@ -8182,6 +8182,64 @@
 }
 #endif
 
+    int
+do_chdir(new_dir, local, forceit)
+    char_u     *new_dir;
+    int                local;
+    int                forceit;
+{
+#ifdef FEAT_AUTOCMD
+    if (allbuf_locked())
+       return FAIL;
+#endif
+    if (vim_strchr(p_cpo, CPO_CHDIR) != NULL && curbufIsChanged()
+                                                        && !forceit)
+    {
+       EMSG(_("E747: Cannot change directory, buffer is modified (add ! to 
override)"));
+       return FAIL;
+    }
+
+    /* Save current directory for next ":cd -" */
+    tofree = prev_dir;
+    if (mch_dirname(NameBuff, MAXPATHL) == OK)
+       prev_dir = vim_strsave(NameBuff);
+    else
+       prev_dir = NULL;
+
+    if (new_dir == NULL || vim_chdir(new_dir))
+    {
+       EMSG(_(e_failed));
+       return FAIL;
+    }
+    else
+    {
+       vim_free(curwin->w_localdir);
+       if (local)
+       {
+           /* If still in global directory, need to remember current
+            * directory as global directory. */
+           if (globaldir == NULL && prev_dir != NULL)
+               globaldir = vim_strsave(prev_dir);
+           /* Remember this local directory for the window. */
+           if (mch_dirname(NameBuff, MAXPATHL) == OK)
+               curwin->w_localdir = vim_strsave(NameBuff);
+       }
+       else
+       {
+           /* We are now in the global directory, no need to remember its
+            * name. */
+           vim_free(globaldir);
+           globaldir = NULL;
+           curwin->w_localdir = NULL;
+       }
+
+       shorten_fnames(TRUE);
+    }
+    vim_free(tofree);
+
+    return OK;
+}
+
 
 /*
  * ":cd", ":lcd", ":chdir" and ":lchdir".
@@ -8201,17 +8259,6 @@
     else
 #endif
     {
-#ifdef FEAT_AUTOCMD
-       if (allbuf_locked())
-           return;
-#endif
-       if (vim_strchr(p_cpo, CPO_CHDIR) != NULL && curbufIsChanged()
-                                                            && !eap->forceit)
-       {
-           EMSG(_("E747: Cannot change directory, buffer is modified (add ! to 
override)"));
-           return;
-       }
-
        /* ":cd -": Change to previous directory */
        if (STRCMP(new_dir, "-") == 0)
        {
@@ -8223,13 +8270,6 @@
            new_dir = prev_dir;
        }
 
-       /* Save current directory for next ":cd -" */
-       tofree = prev_dir;
-       if (mch_dirname(NameBuff, MAXPATHL) == OK)
-           prev_dir = vim_strsave(NameBuff);
-       else
-           prev_dir = NULL;
-
 #if defined(UNIX) || defined(VMS)
        /* for UNIX ":cd" means: go to home directory */
        if (*new_dir == NUL)
@@ -8249,37 +8289,13 @@
            new_dir = NameBuff;
        }
 #endif
-       if (new_dir == NULL || vim_chdir(new_dir))
-           EMSG(_(e_failed));
-       else
-       {
-           vim_free(curwin->w_localdir);
-           if (eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir)
-           {
-               /* If still in global directory, need to remember current
-                * directory as global directory. */
-               if (globaldir == NULL && prev_dir != NULL)
-                   globaldir = vim_strsave(prev_dir);
-               /* Remember this local directory for the window. */
-               if (mch_dirname(NameBuff, MAXPATHL) == OK)
-                   curwin->w_localdir = vim_strsave(NameBuff);
-           }
-           else
-           {
-               /* We are now in the global directory, no need to remember its
-                * name. */
-               vim_free(globaldir);
-               globaldir = NULL;
-               curwin->w_localdir = NULL;
-           }
-
-           shorten_fnames(TRUE);
-
+
+       if (do_chdir(new_dir,
+                   eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir,
+                   eap->forceit) != FAIL &&
+               (KeyTyped || p_verbose >= 5))
            /* Echo the new current directory if the command was typed. */
-           if (KeyTyped || p_verbose >= 5)
-               ex_pwd(eap);
-       }
-       vim_free(tofree);
+           ex_pwd(eap);
     }
 }
 
diff -r bca5a13b9afd src/if_py_both.h
--- a/src/if_py_both.h  Fri May 31 06:59:29 2013 +0400
+++ b/src/if_py_both.h  Fri May 31 08:23:50 2013 +0400
@@ -706,6 +706,45 @@
            );
 }
 
+    static int
+py_to_bool(PyObject *obj, int *result)
+{
+    int                r;
+
+    if ((r = PyObject_IsTrue(obj)) == -1)
+       return 1;
+
+    *result = r;
+
+    return 0;
+}
+
+    static PyObject *
+VimChdir(PyObject *self UNUSED, PyObject *args)
+{
+    char       *new_dir;
+    int                local = 0;
+
+    if (!PyArg_ParseTuple(args, "s|O&", &new_dir, py_to_bool, &local))
+       return NULL;
+
+    VimTryStart();
+
+    if (do_chdir(new_dir, local, FALSE) == FAIL)
+    {
+       if (VimTryEnd())
+           return NULL;
+       PyErr_SetVim(_("failed to change directory"));
+       return NULL;
+    }
+
+    if (VimTryEnd())
+       return NULL;
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 /*
  * Vim module - Definitions
  */
@@ -716,6 +755,7 @@
     {"eval",        VimEval,           METH_VARARGS,   "Evaluate an expression 
using Vim evaluator" },
     {"bindeval",     VimEvalPy,                METH_VARARGS,   "Like eval(), 
but returns objects attached to vim ones"},
     {"strwidth",     VimStrwidth,      METH_VARARGS,   "Screen string width, 
counts <Tab> as having width 1"},
+    {"chdir",       VimChdir,          METH_VARARGS,   "Change directory"},
     { NULL,         NULL,              0,              NULL }
 };
 
diff -r bca5a13b9afd src/proto/ex_docmd.pro
--- a/src/proto/ex_docmd.pro    Fri May 31 06:59:29 2013 +0400
+++ b/src/proto/ex_docmd.pro    Fri May 31 08:23:50 2013 +0400
@@ -53,4 +53,5 @@
 int put_line __ARGS((FILE *fd, char *s));
 void dialog_msg __ARGS((char_u *buff, char *format, char_u *fname));
 char_u *get_behave_arg __ARGS((expand_T *xp, int idx));
+int do_chdir __ARGS((char_u *new_dir, int local, int forceit));
 /* vim: set ft=c : */

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Raspunde prin e-mail lui