aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorAugusto Stoffel2021-09-10 13:04:54 +0200
committerLars Ingebrigtsen2021-09-10 16:39:13 +0200
commit195da78e2ee8ec27de9da7d2ba777313db31e4b7 (patch)
treec20230b97f7d830b6068b917eee1414d33181e6f /lisp/progmodes/python.el
parent5ee6583cb26801ba079e671071179482ccdd679a (diff)
downloademacs-195da78e2ee8ec27de9da7d2ba777313db31e4b7.tar.gz
emacs-195da78e2ee8ec27de9da7d2ba777313db31e4b7.zip
Properly encode all strings sent to Python shell
* lisp/progmodes/python.el: Now depends on Emacs 28. (python-shell-package-enable, python-shell-completion-get-completions) (python-ffap-module-path, python-eldoc--get-doc-at-point): Enconde Python strings using 'python-shell--encode-string' instead of triple quotes. (python-shell-completion-string-code, python-eldoc-string-code) (python-ffap-string-code): Remove defcustoms. (bug#50503).
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el64
1 files changed, 21 insertions, 43 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e342ce7f563..9434d26b7b8 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2571,10 +2571,12 @@ the `buffer-name'."
2571 (format 2571 (format
2572 (concat 2572 (concat
2573 "import os.path;import sys;" 2573 "import os.path;import sys;"
2574 "sys.path.append(os.path.dirname(os.path.dirname('''%s''')));" 2574 "sys.path.append(os.path.dirname(os.path.dirname(%s)));"
2575 "__package__ = '''%s''';" 2575 "__package__ = %s;"
2576 "import %s") 2576 "import %s")
2577 directory package package) 2577 (python-shell--encode-string directory)
2578 (python-shell--encode-string package)
2579 package)
2578 (python-shell-get-process))) 2580 (python-shell-get-process)))
2579 2581
2580(defun python-shell-accept-process-output (process &optional timeout regexp) 2582(defun python-shell-accept-process-output (process &optional timeout regexp)
@@ -3532,14 +3534,6 @@ def __PYTHON_EL_get_completions(text):
3532 "25.1" 3534 "25.1"
3533 "Completion string code must work for (i)pdb.") 3535 "Completion string code must work for (i)pdb.")
3534 3536
3535(defcustom python-shell-completion-string-code
3536 "';'.join(__PYTHON_EL_get_completions('''%s'''))"
3537 "Python code used to get a string of completions separated by semicolons.
3538The string passed to the function is the current python name or
3539the full statement in the case of imports."
3540 :type 'string
3541 :group 'python)
3542
3543(defcustom python-shell-completion-native-disabled-interpreters 3537(defcustom python-shell-completion-native-disabled-interpreters
3544 ;; PyPy's readline cannot handle some escape sequences yet. Native 3538 ;; PyPy's readline cannot handle some escape sequences yet. Native
3545 ;; completion doesn't work on w32 (Bug#28580). 3539 ;; completion doesn't work on w32 (Bug#28580).
@@ -3834,9 +3828,10 @@ completion."
3834 (python-util-strip-string 3828 (python-util-strip-string
3835 (python-shell-send-string-no-output 3829 (python-shell-send-string-no-output
3836 (format 3830 (format
3837 (concat python-shell-completion-setup-code 3831 "%s\nprint(';'.join(__PYTHON_EL_get_completions(%s)))"
3838 "\nprint (" python-shell-completion-string-code ")") 3832 python-shell-completion-setup-code
3839 input) process)))) 3833 (python-shell--encode-string input))
3834 process))))
3840 (when (> (length completions) 2) 3835 (when (> (length completions) 2)
3841 (split-string completions 3836 (split-string completions
3842 "^'\\|^\"\\|;\\|'$\\|\"$" t))))) 3837 "^'\\|^\"\\|;\\|'$\\|\"$" t)))))
@@ -4559,28 +4554,16 @@ def __FFAP_get_module_path(objstr):
4559 :type 'string 4554 :type 'string
4560 :group 'python) 4555 :group 'python)
4561 4556
4562(defcustom python-ffap-string-code
4563 "__FFAP_get_module_path('''%s''')"
4564 "Python code used to get a string with the path of a module."
4565 :type 'string
4566 :group 'python)
4567
4568(defun python-ffap-module-path (module) 4557(defun python-ffap-module-path (module)
4569 "Function for `ffap-alist' to return path for MODULE." 4558 "Function for `ffap-alist' to return path for MODULE."
4570 (let ((process (or 4559 (when-let ((process (python-shell-get-process))
4571 (and (derived-mode-p 'inferior-python-mode) 4560 (module-file
4572 (get-buffer-process (current-buffer))) 4561 (python-shell-send-string-no-output
4573 (python-shell-get-process)))) 4562 (format "%s\nprint(__FFAP_get_module_path(%s))"
4574 (if (not process) 4563 python-ffap-setup-code
4575 nil 4564 (python-shell--encode-string module)))))
4576 (let ((module-file 4565 (unless (string-empty-p module-file)
4577 (python-shell-send-string-no-output 4566 (python-util-strip-string module-file))))
4578 (concat
4579 python-ffap-setup-code
4580 "\nprint (" (format python-ffap-string-code module) ")")
4581 process)))
4582 (unless (zerop (length module-file))
4583 (python-util-strip-string module-file))))))
4584 4567
4585(defvar ffap-alist) 4568(defvar ffap-alist)
4586 4569
@@ -4671,12 +4654,6 @@ See `python-check-command' for the default."
4671 :type 'string 4654 :type 'string
4672 :group 'python) 4655 :group 'python)
4673 4656
4674(defcustom python-eldoc-string-code
4675 "__PYDOC_get_help('''%s''')"
4676 "Python code used to get a string with the documentation of an object."
4677 :type 'string
4678 :group 'python)
4679
4680(defun python-eldoc--get-symbol-at-point () 4657(defun python-eldoc--get-symbol-at-point ()
4681 "Get the current symbol for eldoc. 4658 "Get the current symbol for eldoc.
4682Returns the current symbol handling point within arguments." 4659Returns the current symbol handling point within arguments."
@@ -4706,11 +4683,12 @@ returns will be used. If not FORCE-PROCESS is passed what
4706 ;; enabled. Bug#18794. 4683 ;; enabled. Bug#18794.
4707 (python-util-strip-string 4684 (python-util-strip-string
4708 (python-shell-send-string-no-output 4685 (python-shell-send-string-no-output
4709 (concat 4686 (format
4687 "%s\nprint(__PYDOC_get_help(%s))"
4710 python-eldoc-setup-code 4688 python-eldoc-setup-code
4711 "\nprint(" (format python-eldoc-string-code input) ")") 4689 (python-shell--encode-string input))
4712 process))))) 4690 process)))))
4713 (unless (zerop (length docstring)) 4691 (unless (string-empty-p docstring)
4714 docstring))))) 4692 docstring)))))
4715 4693
4716(defvar-local python-eldoc-get-doc t 4694(defvar-local python-eldoc-get-doc t