From 16cb32a1a656ac50b6ff03bf258dc42cda969f16 Mon Sep 17 00:00:00 2001 From: dickmao Date: Sat, 20 Oct 2018 20:45:22 -0400 Subject: [PATCH] more request-curl callback protections --- .appveyor.yml | 10 +++++----- lisp/ein-contents-api.el | 20 ++++++++++++++------ lisp/ein-core.el | 4 ++-- lisp/ein-loaddefs.el | 2 +- test/test-func.el | 4 +++- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index fc300b7..7fabf2c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -204,15 +204,15 @@ build: off # - [DAL, BL] # 2nd job # scripts to run before tests (working directory and environment changes are persisted from the previous steps such as "before_build") -before_test: +#before_test: # to run your custom scripts instead of automatic tests -test_script: - - cd c:\projects\myproject +#test_script: +# - cd c:\projects\myproject # - make quick # scripts to run after tests -after_test: +#after_test: # to disable automatic tests test: off @@ -233,4 +233,4 @@ deploy: off # after build failure or success on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) diff --git a/lisp/ein-contents-api.el b/lisp/ein-contents-api.el index 571a49c..42e0605 100644 --- a/lisp/ein-contents-api.el +++ b/lisp/ein-contents-api.el @@ -90,9 +90,9 @@ global setting. For global setting and more information, see (ein:log 'debug "ein:query-contents--complete %s" resp-string)) (defun* ein:content-query-contents--error (url-or-port path callback iteration &key symbol-status response error-thrown &allow-other-keys) - (if (and (eq (request-response-status-code response) 403) (< iteration 3)) + (if (< iteration 3) (progn - (ein:log 'info "Retry content-query-contents #%s" iteration) + (ein:log 'info "Retry content-query-contents #%s in response to %s" iteration (request-response-status-code response)) (ein:content-query-contents url-or-port path callback (1+ iteration))) (ein:log 'error "ein:content-query-contents--error %s REQUEST-STATUS %s DATA %s" (concat (file-name-as-directory url-or-port) path) symbol-status (cdr error-thrown)))) @@ -346,8 +346,10 @@ global setting. For global setting and more information, see ;;; Sessions -(defun ein:content-query-sessions (url-or-port callback) +(defun ein:content-query-sessions (url-or-port callback &optional iteration) "Register CALLBACK of arity 1 to retrieve the sessions" + (unless iteration + (setq iteration 0)) (ein:query-singleton-ajax (list 'content-query-sessions url-or-port) (ein:url url-or-port "api/sessions") @@ -355,7 +357,7 @@ global setting. For global setting and more information, see :parser #'ein:json-read :complete (apply-partially #'ein:content-query-sessions--complete url-or-port callback) :success (apply-partially #'ein:content-query-sessions--success url-or-port callback) - :error (apply-partially #'ein:content-query-sessions--error url-or-port) + :error (apply-partially #'ein:content-query-sessions--error url-or-port callback iteration) :sync ein:force-sync)) (defun* ein:content-query-sessions--success (url-or-port callback &key data &allow-other-keys) @@ -370,8 +372,14 @@ global setting. For global setting and more information, see (setf (gethash (read-name (plist-get s :notebook)) session-hash) (cons (plist-get s :id) (plist-get s :kernel))))))) -(defun* ein:content-query-sessions--error (url-or-port &key error-thrown &allow-other-keys) - (ein:log 'error "ein:content-query-sessions--error %s: ERROR %s DATA %s" url-or-port (car error-thrown) (cdr error-thrown))) +(defun* ein:content-query-sessions--error (url-or-port callback iteration + &key response error-thrown + &allow-other-keys) + (if (< iteration 3) + (progn + (ein:log 'info "Retry sessions #%s in response to %s" iteration (request-response-status-code response)) + (ein:content-query-sessions url-or-port callback (1+ iteration))) + (ein:log 'error "ein:content-query-sessions--error %s: ERROR %s DATA %s" url-or-port (car error-thrown) (cdr error-thrown)))) (defun* ein:content-query-sessions--complete (url-or-port callback &key data response diff --git a/lisp/ein-core.el b/lisp/ein-core.el index 3a54252..6dfcc16 100644 --- a/lisp/ein-core.el +++ b/lisp/ein-core.el @@ -186,9 +186,9 @@ the source is in git repository." (defun* ein:query-kernelspecs--error (url-or-port callback iteration &key response error-thrown &allow-other-keys) - (if (and (eq (request-response-status-code response) 403) (< iteration 3)) + (if (< iteration 3) (progn - (ein:log 'info "Retry kernelspecs #%s" iteration) + (ein:log 'info "Retry kernelspecs #%s in response to %s" iteration (request-response-status-code response)) (ein:query-kernelspecs url-or-port callback (1+ iteration))) (ein:log 'error "ein:query-kernelspecs-error %s: ERROR %s DATA %s" url-or-port (car error-thrown) (cdr error-thrown)))) diff --git a/lisp/ein-loaddefs.el b/lisp/ein-loaddefs.el index 4f1f441..da9bdd1 100644 --- a/lisp/ein-loaddefs.el +++ b/lisp/ein-loaddefs.el @@ -499,7 +499,7 @@ Show full traceback in traceback viewer. ;;;;;; "ein-python.el" "ein-pytools.el" "ein-query.el" "ein-scratchsheet.el" ;;;;;; "ein-skewer.el" "ein-smartrep.el" "ein-subpackages.el" "ein-timestamp.el" ;;;;;; "ein-utils.el" "ein-websocket.el" "ein-worksheet.el" "ein.el" -;;;;;; "ob-ein.el" "zeroein.el") (23499 16469 728162 481000)) +;;;;;; "ob-ein.el" "zeroein.el") (23499 54796 72693 801000)) ;;;*** diff --git a/test/test-func.el b/test/test-func.el index a0bf6be..8093d05 100644 --- a/test/test-func.el +++ b/test/test-func.el @@ -196,6 +196,7 @@ See the definition of `create-image' for how it works." (should (search-forward-regexp "^Hello$" nil t)))))) (ert-deftest 14-notebook-execute-current-cell-question () + :expected-result (if (eq system-type 'darwin) t :passed) (let ((notebook (ein:testing-get-untitled0-or-create *ein:testing-port*))) (ein:testing-wait-until (lambda () (ein:aand (ein:$notebook-kernel notebook) @@ -205,7 +206,8 @@ See the definition of `create-image' for how it works." (insert "range?") (let ((cell (call-interactively #'ein:worksheet-execute-cell))) (ein:testing-wait-until (lambda () (and (not (oref cell :running)) - (ein:$notebook-pager notebook))))) + (ein:$notebook-pager notebook) + (get-buffer (ein:$notebook-pager notebook)))))) (with-current-buffer (get-buffer (ein:$notebook-pager notebook)) (should (search-forward "Docstring:"))))))