;ELC ;;; Compiled ;;; in Emacs version 28.0.50 ;;; with all optimizations. #@29 Path to the curl executable (defvar grapnel-program (executable-find "curl") (#$ . 87)) #@113 Additional options to pass to all curl requests. Enter them just as they would be entered on the command line. (defvar grapnel-options "" (#$ . 182)) #@51 Dispatch function for handling the curl response. (defvar grapnel-callback-dispatch-fn 'grapnel-callback-dispatch (#$ . 339)) #@16 URI encode STR (defalias 'grapnel-url-escape #[(str) "\301\302\303\304\"\305\"!\207" [str url-hexify-string encode-coding-string format "%s" utf-8] 5 (#$ . 471)]) #@73 Convert an alist of params into an & delimeted string suitable for curl (defalias 'grapnel-format-params #[(params) "\301\302\303#\207" [params mapconcat #[(p) ":\203\301@!\302\301A!Q\207\301!\207" [p grapnel-url-escape "="] 4] "&"] 4 (#$ . 641)]) #@53 Converts the passed arguments into the curl command (defalias 'grapnel-command #[(url &optional request-method url-params request-data-file request-headers) "\206\306\n\205 \307\n!\211\203\310\311 !8\202\312 \204%\202B\313\314\315\316#)\266\203\203=\317\202>\313\320 !Q \203O\321\322 \"\202P\323 \324\232\203j\325\326\"A\204j\326\fBB\202l\211 \204v\323\202|\327\330 \323# \312!GW\203\215\331!P\202\216\323\"\321\332#\" \333!&.\207" [request-method method request-data-file filename filesize url-params "GET" expand-file-name 7 file-attributes 0 "?" nil t string-match "&" grapnel-format-params format " --data @%s" "" "POST" assoc "Content-Length" mapconcat #[(header-pair) "\301\302\303\301\304@A#!\"\207" [header-pair format " --header %s" shell-quote-argument "%s: %s"] 7] " " "%s%s%s --include --silent --request %s%s %s" shell-quote-argument url inhibit-changing-match-data data request-headers headers grapnel-options options grapnel-program] 10 (#$ . 902)]) #@67 Extracts the response code and converts the headers into an alist (defalias 'grapnel-parse-headers #[(header-str) "\205 \302\303\304#\305\306\307 @\"\210\310\311\312 @\"!D\313\314 A\")B\207" [header-str split-headers split-string "\n" t "response-code" string-match "\\([[:digit:]][[:digit:]][[:digit:]]\\)" string-to-number match-string 1 mapcar #[(line) "\301\302\"\207" [line split-string ": "] 3]] 5 (#$ . 1936)]) #@46 Extract the headers from the response buffer (defalias 'grapnel-response-headers #[nil "edU?\205Jeb\210\302\303\304\305#\203\306\307\304\211#\210\202\neb\210\302\310\304\305#\2031\311 \312y\210`|\210\202eb\210\313\314\304\305#\211\205Ie{eT|\210 ))\207" [pos headers re-search-forward "[ ]" nil t replace-match "" "^HTTP/1.1 100 Continue" point-at-bol 2 search-forward-regexp "^$"] 5 (#$ . 2365)]) #@620 Default dispatch function. Call the first matching function in HANDLER-ALIST based on the response. HANDLER-ALIST is in the form: '((success . (lambda (response response-headers) ...)) (error . (lambda (response error-code) ...))) The valid keys in the alist are (in order of precedence): - 'error - for when the curl call fails in some way - the HTTP response code as a number - 'success - any HTTP response 200-299 - 'failure - any HTTP response 400-599 - 'complete - any HTTP response 'error is the only one that is called with (response error-code) all of the rest of them are called with (response headers) (defalias 'grapnel-callback-dispatch #[(handler-alist exit-code response headers) "\305\306\"A@\307\n\236\203 \310U\204\311\307\n\236A\f D\"\202\206\305 \n\"\2033\311\305 \n\"A\fD\"\202\206\312\n\236\203Q\313 X\203Q \314W\203Q\311\312\n\236A\fD\"\202\206\315\n\236\203o\316 X\203o \317W\203o\311\315\n\236A\fD\"\202\206\320\n\236\203\201\311\320\n\236A\fD\"\202\206\321\322 #)\207" [headers response-code handler-alist exit-code response assoc "response-code" error 0 apply success 200 300 failure 400 600 complete message "GRAPNEL WARNING: Missing handler for response. Curl exit code: %s, Response code: %s"] 4 (#$ . 2781)]) #@49 Sentinel function that watches the curl process (defalias 'grapnel-sentinel #[(handler-alist buffer-name data-file process signal) "\306\216\307\310\"\204\307\311\"\205+r q\210\312\313 !\314 \f \315!\n $\210*\316 !))\207" [signal buffer-name response headers grapnel-callback-dispatch-fn handler-alist #[nil "\3021\303!\205\304 !?\205\305!0\207\210\306\207" [data-file process (error) file-exists-p process-live-p delete-file nil] 2] string-match "^finished" "^exited abnormally" grapnel-parse-headers grapnel-response-headers buffer-string process-exit-status kill-buffer process] 5 (#$ . 4057)]) #@84 Create and return a temp file populated with DATA. Return nil if there is no data. (defalias 'grapnel-prepare-data-file #[(data) "\205.\304\305\306\307#\211\310\311\312\"\313\216r\nq\210\203c\210)r\nq\210\314\306\211 \306\315%\210, )\207" [data data-file #1=#:temp-buffer #2=#:temp-file make-temp-file "grapnel" nil "tmp" generate-new-buffer " *temp file*" t #[nil "\301!\205 \302!\207" [#1# buffer-name kill-buffer] 2] write-region 0] 7 (#$ . 4678)]) #@439 Retrieve URL asynchronously and call the corresponding handler in HANDLER-ALIST. See the documentation for `grapnel-callback-dispatch' for details on HANDLER-ALIST. REQUEST-METHOD: a string and can be any valid HTTP verb URL-PARAMS: an alist and will be formatted into a query string and url encoded REQUEST-DATA: an alist, automatically formatted and urlencoded, sent over stdin REQUEST-HEADERS: an alist of header name to value pairs (defalias 'grapnel-retrieve-url #[(url handler-alist &optional request-method url-params request-data request-headers) "\205<\203\306!\202\307 !\310\311!\3121A\313\f \n%\314\315 #\316\317\320 \n$\"*0\210\202N\321\n!\205L\322\n!)\210+\323\207" [request-data data tmp-file buffer-name url request-method grapnel-format-params grapnel-prepare-data-file generate-new-buffer-name " grapnel" (error) grapnel-command start-process-shell-command "grapnel" set-process-sentinel apply-partially grapnel-sentinel file-exists-p delete-file nil url-params request-headers command proc handler-alist err] 7 (#$ . 5149)]) #@63 Behaves the same as `grapnel-retrieve-url' but synchronously. (defalias 'grapnel-retrieve-url-sync #[(url handler-alist &optional request-method url-params request-data request-headers) "\205<\203\306!\202\307\310!\311 !\312\216\313\f  %\314 \n\315$r\nq\210\316\317 !\320 $\321\n!\210.\n\207" [request-data data buffer-name tmp-file url request-method grapnel-format-params generate-new-buffer-name " grapnel" grapnel-prepare-data-file #[nil "\3011\302!\205 \303!0\207\210\304\207" [tmp-file (error) file-exists-p delete-file nil] 2] grapnel-command call-process-shell-command nil grapnel-parse-headers grapnel-response-headers buffer-string kill-buffer url-params request-headers command exit-code headers response grapnel-callback-dispatch-fn handler-alist ret] 6 (#$ . 6232)]) (provide 'grapnel)