Mercurial > emacs
annotate lisp/url/url-util.el @ 110693:754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
`silent' flag to signal that the operation should be silent.
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Sat, 02 Oct 2010 04:04:20 +0200 |
parents | 5495085c9b6c |
children | af844b79b99f |
rev | line source |
---|---|
54695 | 1 ;;; url-util.el --- Miscellaneous helper routines for URL library |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
2 |
101912
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2001, 2004, 2005, 2006, 2007, |
106815 | 4 ;; 2008, 2009, 2010 Free Software Foundation, Inc. |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
5 |
54695 | 6 ;; Author: Bill Perry <wmperry@gnu.org> |
7 ;; Keywords: comm, data, processes | |
8 | |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
10 ;; |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92401
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92401
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92401
diff
changeset
|
14 ;; (at your option) any later version. |
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92401
diff
changeset
|
15 |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
19 ;; GNU General Public License for more details. |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92401
diff
changeset
|
20 |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92401
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
23 |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
24 ;;; Commentary: |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
25 |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
26 ;;; Code: |
54695 | 27 |
28 (require 'url-parse) | |
106965
2eca6c2d9334
* url-util.el: Require url-vars (Bug#5459).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
29 (require 'url-vars) |
92401
b7d3823f3c26
Require cl when compiling.
Andreas Schwab <schwab@suse.de>
parents:
92305
diff
changeset
|
30 (eval-when-compile (require 'cl)) |
54695 | 31 (autoload 'timezone-parse-date "timezone") |
32 (autoload 'timezone-make-date-arpa-standard "timezone") | |
54803
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
33 (autoload 'mail-header-extract "mailheader") |
54695 | 34 |
35 (defvar url-parse-args-syntax-table | |
36 (copy-syntax-table emacs-lisp-mode-syntax-table) | |
37 "A syntax table for parsing sgml attributes.") | |
38 | |
39 (modify-syntax-entry ?' "\"" url-parse-args-syntax-table) | |
40 (modify-syntax-entry ?` "\"" url-parse-args-syntax-table) | |
41 (modify-syntax-entry ?{ "(" url-parse-args-syntax-table) | |
42 (modify-syntax-entry ?} ")" url-parse-args-syntax-table) | |
43 | |
44 ;;;###autoload | |
45 (defcustom url-debug nil | |
110307 | 46 "What types of debug messages from the URL library to show. |
54695 | 47 Debug messages are logged to the *URL-DEBUG* buffer. |
48 | |
49 If t, all messages will be logged. | |
50 If a number, all messages will be logged, as well shown via `message'. | |
51 If a list, it is a list of the types of messages to be logged." | |
52 :type '(choice (const :tag "none" nil) | |
53 (const :tag "all" t) | |
54 (checklist :tag "custom" | |
55 (const :tag "HTTP" :value http) | |
56 (const :tag "DAV" :value dav) | |
57 (const :tag "General" :value retrieval) | |
58 (const :tag "Filename handlers" :value handlers) | |
59 (symbol :tag "Other"))) | |
60 :group 'url-hairy) | |
61 | |
62 ;;;###autoload | |
63 (defun url-debug (tag &rest args) | |
64 (if quit-flag | |
65 (error "Interrupted!")) | |
66 (if (or (eq url-debug t) | |
67 (numberp url-debug) | |
68 (and (listp url-debug) (memq tag url-debug))) | |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
69 (with-current-buffer (get-buffer-create "*URL-DEBUG*") |
54695 | 70 (goto-char (point-max)) |
71 (insert (symbol-name tag) " -> " (apply 'format args) "\n") | |
72 (if (numberp url-debug) | |
73 (apply 'message args))))) | |
74 | |
75 ;;;###autoload | |
76 (defun url-parse-args (str &optional nodowncase) | |
77 ;; Return an assoc list of attribute/value pairs from an RFC822-type string | |
78 (let ( | |
79 name ; From name= | |
80 value ; its value | |
81 results ; Assoc list of results | |
82 name-pos ; Start of XXXX= position | |
83 val-pos ; Start of value position | |
84 st | |
85 nd | |
86 ) | |
87 (save-excursion | |
88 (save-restriction | |
89 (set-buffer (get-buffer-create " *urlparse-temp*")) | |
90 (set-syntax-table url-parse-args-syntax-table) | |
91 (erase-buffer) | |
92 (insert str) | |
93 (setq st (point-min) | |
94 nd (point-max)) | |
95 (set-syntax-table url-parse-args-syntax-table) | |
96 (narrow-to-region st nd) | |
97 (goto-char (point-min)) | |
98 (while (not (eobp)) | |
99 (skip-chars-forward "; \n\t") | |
100 (setq name-pos (point)) | |
101 (skip-chars-forward "^ \n\t=;") | |
102 (if (not nodowncase) | |
103 (downcase-region name-pos (point))) | |
104 (setq name (buffer-substring name-pos (point))) | |
105 (skip-chars-forward " \t\n") | |
106 (if (/= (or (char-after (point)) 0) ?=) ; There is no value | |
107 (setq value nil) | |
108 (skip-chars-forward " \t\n=") | |
109 (setq val-pos (point) | |
110 value | |
111 (cond | |
112 ((or (= (or (char-after val-pos) 0) ?\") | |
113 (= (or (char-after val-pos) 0) ?')) | |
114 (buffer-substring (1+ val-pos) | |
115 (condition-case () | |
116 (prog2 | |
117 (forward-sexp 1) | |
118 (1- (point)) | |
119 (skip-chars-forward "\"")) | |
120 (error | |
121 (skip-chars-forward "^ \t\n") | |
122 (point))))) | |
123 (t | |
124 (buffer-substring val-pos | |
125 (progn | |
126 (skip-chars-forward "^;") | |
127 (skip-chars-backward " \t") | |
128 (point))))))) | |
129 (setq results (cons (cons name value) results)) | |
130 (skip-chars-forward "; \n\t")) | |
131 results)))) | |
132 | |
133 ;;;###autoload | |
134 (defun url-insert-entities-in-string (string) | |
135 "Convert HTML markup-start characters to entity references in STRING. | |
136 Also replaces the \" character, so that the result may be safely used as | |
137 an attribute value in a tag. Returns a new string with the result of the | |
138 conversion. Replaces these characters as follows: | |
139 & ==> & | |
140 < ==> < | |
141 > ==> > | |
142 \" ==> "" | |
143 (if (string-match "[&<>\"]" string) | |
105829
328150f0cf76
* url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101912
diff
changeset
|
144 (with-current-buffer (get-buffer-create " *entity*") |
54695 | 145 (erase-buffer) |
146 (buffer-disable-undo (current-buffer)) | |
147 (insert string) | |
148 (goto-char (point-min)) | |
149 (while (progn | |
150 (skip-chars-forward "^&<>\"") | |
151 (not (eobp))) | |
152 (insert (cdr (assq (char-after (point)) | |
153 '((?\" . """) | |
154 (?& . "&") | |
155 (?< . "<") | |
156 (?> . ">"))))) | |
157 (delete-char 1)) | |
158 (buffer-string)) | |
159 string)) | |
160 | |
161 ;;;###autoload | |
162 (defun url-normalize-url (url) | |
163 "Return a 'normalized' version of URL. | |
164 Strips out default port numbers, etc." | |
72218
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
165 (let (type data retval) |
54695 | 166 (setq data (url-generic-parse-url url) |
167 type (url-type data)) | |
168 (if (member type '("www" "about" "mailto" "info")) | |
169 (setq retval url) | |
98338 | 170 ;; FIXME all this does, and all this function seems to do in |
171 ;; most cases, is remove any trailing "#anchor" part of a url. | |
83823
dd2bcc6758a0
* url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78222
diff
changeset
|
172 (setf (url-target data) nil) |
54695 | 173 (setq retval (url-recreate-url data))) |
174 retval)) | |
175 | |
176 ;;;###autoload | |
177 (defun url-lazy-message (&rest args) | |
178 "Just like `message', but is a no-op if called more than once a second. | |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
179 Will not do anything if `url-show-status' is nil." |
110693
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
180 (if (or (and url-current-object |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
181 (url-silent url-current-object)) |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
182 (null url-show-status) |
54695 | 183 (active-minibuffer-window) |
184 (= url-lazy-message-time | |
185 (setq url-lazy-message-time (nth 1 (current-time))))) | |
186 nil | |
110693
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
187 (message "hei: %s" url-current-object) |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
188 (with-current-buffer (get-buffer-create "back") |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
189 (let ((standard-output (current-buffer))) |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
190 (backtrace))) |
54695 | 191 (apply 'message args))) |
192 | |
193 ;;;###autoload | |
194 (defun url-get-normalized-date (&optional specified-time) | |
92305
76175fc0a2f9
(url-get-normalized-date): Simplify
Teodor Zlatanov <tzz@lifelogs.com>
parents:
87649
diff
changeset
|
195 "Return a 'real' date string that most HTTP servers can understand." |
76175fc0a2f9
(url-get-normalized-date): Simplify
Teodor Zlatanov <tzz@lifelogs.com>
parents:
87649
diff
changeset
|
196 (let ((system-time-locale "C")) |
76175fc0a2f9
(url-get-normalized-date): Simplify
Teodor Zlatanov <tzz@lifelogs.com>
parents:
87649
diff
changeset
|
197 (format-time-string "%a, %d %b %Y %T GMT" |
76175fc0a2f9
(url-get-normalized-date): Simplify
Teodor Zlatanov <tzz@lifelogs.com>
parents:
87649
diff
changeset
|
198 (or specified-time (current-time)) t))) |
54695 | 199 |
200 ;;;###autoload | |
201 (defun url-eat-trailing-space (x) | |
202 "Remove spaces/tabs at the end of a string." | |
203 (let ((y (1- (length x))) | |
204 (skip-chars (list ? ?\t ?\n))) | |
205 (while (and (>= y 0) (memq (aref x y) skip-chars)) | |
206 (setq y (1- y))) | |
207 (substring x 0 (1+ y)))) | |
208 | |
209 ;;;###autoload | |
210 (defun url-strip-leading-spaces (x) | |
211 "Remove spaces at the front of a string." | |
212 (let ((y (1- (length x))) | |
213 (z 0) | |
214 (skip-chars (list ? ?\t ?\n))) | |
215 (while (and (<= z y) (memq (aref x z) skip-chars)) | |
216 (setq z (1+ z))) | |
217 (substring x z nil))) | |
218 | |
219 ;;;###autoload | |
220 (defun url-pretty-length (n) | |
221 (cond | |
222 ((< n 1024) | |
223 (format "%d bytes" n)) | |
224 ((< n (* 1024 1024)) | |
225 (format "%dk" (/ n 1024.0))) | |
226 (t | |
227 (format "%2.2fM" (/ n (* 1024 1024.0)))))) | |
228 | |
229 ;;;###autoload | |
230 (defun url-display-percentage (fmt perc &rest args) | |
110693
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
231 (when (and url-show-status |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
232 (or (null url-current-object) |
754df5a0efe9
Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110307
diff
changeset
|
233 (not (url-silent url-current-object)))) |
74135
e125bce98ce9
(url-display-percentage): Only show a message if `url-show-status' is non-nil.
Magnus Henoch <mange@freemail.hu>
parents:
72218
diff
changeset
|
234 (if (null fmt) |
e125bce98ce9
(url-display-percentage): Only show a message if `url-show-status' is non-nil.
Magnus Henoch <mange@freemail.hu>
parents:
72218
diff
changeset
|
235 (if (fboundp 'clear-progress-display) |
e125bce98ce9
(url-display-percentage): Only show a message if `url-show-status' is non-nil.
Magnus Henoch <mange@freemail.hu>
parents:
72218
diff
changeset
|
236 (clear-progress-display)) |
e125bce98ce9
(url-display-percentage): Only show a message if `url-show-status' is non-nil.
Magnus Henoch <mange@freemail.hu>
parents:
72218
diff
changeset
|
237 (if (and (fboundp 'progress-display) perc) |
e125bce98ce9
(url-display-percentage): Only show a message if `url-show-status' is non-nil.
Magnus Henoch <mange@freemail.hu>
parents:
72218
diff
changeset
|
238 (apply 'progress-display fmt perc args) |
e125bce98ce9
(url-display-percentage): Only show a message if `url-show-status' is non-nil.
Magnus Henoch <mange@freemail.hu>
parents:
72218
diff
changeset
|
239 (apply 'message fmt args))))) |
54695 | 240 |
241 ;;;###autoload | |
242 (defun url-percentage (x y) | |
243 (if (fboundp 'float) | |
244 (round (* 100 (/ x (float y)))) | |
245 (/ (* x 100) y))) | |
246 | |
247 ;;;###autoload | |
99385
7b5dc2894014
(url-basepath): Add url-basepath as an alias for url-file-directory.
Chong Yidong <cyd@stupidchicken.com>
parents:
98338
diff
changeset
|
248 (defalias 'url-basepath 'url-file-directory) |
7b5dc2894014
(url-basepath): Add url-basepath as an alias for url-file-directory.
Chong Yidong <cyd@stupidchicken.com>
parents:
98338
diff
changeset
|
249 |
7b5dc2894014
(url-basepath): Add url-basepath as an alias for url-file-directory.
Chong Yidong <cyd@stupidchicken.com>
parents:
98338
diff
changeset
|
250 ;;;###autoload |
79064
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
251 (defun url-file-directory (file) |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
252 "Return the directory part of FILE, for a URL." |
54695 | 253 (cond |
254 ((null file) "") | |
255 ((string-match (eval-when-compile (regexp-quote "?")) file) | |
79064
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
256 (file-name-directory (substring file 0 (match-beginning 0)))) |
54695 | 257 (t (file-name-directory file)))) |
258 | |
259 ;;;###autoload | |
79064
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
260 (defun url-file-nondirectory (file) |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
261 "Return the nondirectory part of FILE, for a URL." |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
262 (cond |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
263 ((null file) "") |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
264 ((string-match (eval-when-compile (regexp-quote "?")) file) |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
265 (file-name-nondirectory (substring file 0 (match-beginning 0)))) |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
266 (t (file-name-nondirectory file)))) |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
267 |
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
268 ;;;###autoload |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
269 (defun url-parse-query-string (query &optional downcase allow-newlines) |
54695 | 270 (let (retval pairs cur key val) |
271 (setq pairs (split-string query "&")) | |
272 (while pairs | |
273 (setq cur (car pairs) | |
274 pairs (cdr pairs)) | |
275 (if (not (string-match "=" cur)) | |
276 nil ; Grace | |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
277 (setq key (url-unhex-string (substring cur 0 (match-beginning 0)) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
278 allow-newlines)) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
279 (setq val (url-unhex-string (substring cur (match-end 0) nil) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
280 allow-newlines)) |
54695 | 281 (if downcase |
282 (setq key (downcase key))) | |
283 (setq cur (assoc key retval)) | |
284 (if cur | |
285 (setcdr cur (cons val (cdr cur))) | |
286 (setq retval (cons (list key val) retval))))) | |
287 retval)) | |
288 | |
289 (defun url-unhex (x) | |
290 (if (> x ?9) | |
291 (if (>= x ?a) | |
292 (+ 10 (- x ?a)) | |
293 (+ 10 (- x ?A))) | |
294 (- x ?0))) | |
295 | |
54803
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
296 ;; Fixme: Is this definition better, and does it ever matter? |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
297 |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
298 ;; (defun url-unhex-string (str &optional allow-newlines) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
299 ;; "Remove %XX, embedded spaces, etc in a url. |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
300 ;; If optional second argument ALLOW-NEWLINES is non-nil, then allow the |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
301 ;; decoding of carriage returns and line feeds in the string, which is normally |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
302 ;; forbidden in URL encoding." |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
303 ;; (setq str (or str "")) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
304 ;; (setq str (replace-regexp-in-string "%[[:xdigit:]]\\{2\\}" |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
305 ;; (lambda (match) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
306 ;; (string (string-to-number |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
307 ;; (substring match 1) 16))) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
308 ;; str t t)) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
309 ;; (if allow-newlines |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
310 ;; (replace-regexp-in-string "[\n\r]" (lambda (match) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
311 ;; (format "%%%.2X" (aref match 0))) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
312 ;; str t t) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
313 ;; str)) |
a78c94aa182d
(url-hexify-string): Don't give multibyte error for char <16.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
314 |
54695 | 315 ;;;###autoload |
316 (defun url-unhex-string (str &optional allow-newlines) | |
96486
7369ded3b436
Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
94668
diff
changeset
|
317 "Remove %XX embedded spaces, etc in a URL. |
54695 | 318 If optional second argument ALLOW-NEWLINES is non-nil, then allow the |
319 decoding of carriage returns and line feeds in the string, which is normally | |
320 forbidden in URL encoding." | |
321 (setq str (or str "")) | |
322 (let ((tmp "") | |
323 (case-fold-search t)) | |
324 (while (string-match "%[0-9a-f][0-9a-f]" str) | |
325 (let* ((start (match-beginning 0)) | |
326 (ch1 (url-unhex (elt str (+ start 1)))) | |
327 (code (+ (* 16 ch1) | |
328 (url-unhex (elt str (+ start 2)))))) | |
329 (setq tmp (concat | |
330 tmp (substring str 0 start) | |
331 (cond | |
332 (allow-newlines | |
108663
a224d29f3386
* url-util.el (url-unhex-string): Don't accidentally decode as latin-1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106965
diff
changeset
|
333 (byte-to-string code)) |
54695 | 334 ((or (= code ?\n) (= code ?\r)) |
335 " ") | |
108663
a224d29f3386
* url-util.el (url-unhex-string): Don't accidentally decode as latin-1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106965
diff
changeset
|
336 (t (byte-to-string code)))) |
54695 | 337 str (substring str (match-end 0))))) |
338 (setq tmp (concat tmp str)) | |
339 tmp)) | |
340 | |
341 (defconst url-unreserved-chars | |
342 '( | |
343 ?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z | |
344 ?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z | |
345 ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 | |
346 ?- ?_ ?. ?! ?~ ?* ?' ?\( ?\)) | |
347 "A list of characters that are _NOT_ reserved in the URL spec. | |
348 This is taken from RFC 2396.") | |
349 | |
350 ;;;###autoload | |
72196
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
351 (defun url-hexify-string (string) |
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
352 "Return a new string that is STRING URI-encoded. |
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
353 First, STRING is converted to utf-8, if necessary. Then, for each |
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
354 character in the utf-8 string, those found in `url-unreserved-chars' |
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
355 are left as-is, all others are represented as a three-character |
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
356 string: \"%\" followed by two lowercase hex digits." |
72218
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
357 ;; To go faster and avoid a lot of consing, we could do: |
96486
7369ded3b436
Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
94668
diff
changeset
|
358 ;; |
72218
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
359 ;; (defconst url-hexify-table |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
360 ;; (let ((map (make-vector 256 nil))) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
361 ;; (dotimes (byte 256) (aset map byte |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
362 ;; (if (memq byte url-unreserved-chars) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
363 ;; (char-to-string byte) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
364 ;; (format "%%%02x" byte)))) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
365 ;; map)) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
366 ;; |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
367 ;; (mapconcat (curry 'aref url-hexify-table) ...) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
368 (mapconcat (lambda (byte) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
369 (if (memq byte url-unreserved-chars) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
370 (char-to-string byte) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
371 (format "%%%02x" byte))) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
372 (if (multibyte-string-p string) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
373 (encode-coding-string string 'utf-8) |
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
374 string) |
72196
5b336ff592bb
(url-hexify-string): Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68640
diff
changeset
|
375 "")) |
54695 | 376 |
377 ;;;###autoload | |
378 (defun url-file-extension (fname &optional x) | |
379 "Return the filename extension of FNAME. | |
96486
7369ded3b436
Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
94668
diff
changeset
|
380 If optional argument X is t, then return the basename |
7369ded3b436
Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
94668
diff
changeset
|
381 of the file with the extension stripped off." |
54695 | 382 (if (and fname |
79064
5299839279f5
(url-basepath): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
78850
diff
changeset
|
383 (setq fname (url-file-nondirectory fname)) |
54695 | 384 (string-match "\\.[^./]+$" fname)) |
385 (if x (substring fname 0 (match-beginning 0)) | |
386 (substring fname (match-beginning 0) nil)) | |
387 ;; | |
388 ;; If fname has no extension, and x then return fname itself instead of | |
389 ;; nothing. When caching it allows the correct .hdr file to be produced | |
390 ;; for filenames without extension. | |
391 ;; | |
392 (if x | |
393 fname | |
394 ""))) | |
395 | |
396 ;;;###autoload | |
397 (defun url-truncate-url-for-viewing (url &optional width) | |
101145
b375012e7a7a
* url-util.el (url-truncate-url-for-viewing): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
100908
diff
changeset
|
398 "Return a shortened version of URL that is WIDTH characters wide or less. |
54695 | 399 WIDTH defaults to the current frame width." |
400 (let* ((fr-width (or width (frame-width))) | |
401 (str-width (length url)) | |
402 (fname nil) | |
403 (modified 0) | |
404 (urlobj nil)) | |
405 ;; The first thing that can go are the search strings | |
406 (if (and (>= str-width fr-width) | |
407 (string-match "?" url)) | |
408 (setq url (concat (substring url 0 (match-beginning 0)) "?...") | |
72218
23d71f51857b
(url-hexify-string): Only utf-8 encode if it's a multibyte string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72196
diff
changeset
|
409 str-width (length url))) |
54695 | 410 (if (< str-width fr-width) |
411 nil ; Hey, we are done! | |
412 (setq urlobj (url-generic-parse-url url) | |
413 fname (url-filename urlobj) | |
414 fr-width (- fr-width 4)) | |
415 (while (and (>= str-width fr-width) | |
416 (string-match "/" fname)) | |
417 (setq fname (substring fname (match-end 0) nil) | |
418 modified (1+ modified)) | |
83823
dd2bcc6758a0
* url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78222
diff
changeset
|
419 (setf (url-filename urlobj) fname) |
54695 | 420 (setq url (url-recreate-url urlobj) |
421 str-width (length url))) | |
422 (if (> modified 1) | |
423 (setq fname (concat "/.../" fname)) | |
424 (setq fname (concat "/" fname))) | |
83823
dd2bcc6758a0
* url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78222
diff
changeset
|
425 (setf (url-filename urlobj) fname) |
54695 | 426 (setq url (url-recreate-url urlobj))) |
427 url)) | |
428 | |
429 ;;;###autoload | |
430 (defun url-view-url (&optional no-show) | |
431 "View the current document's URL. | |
432 Optional argument NO-SHOW means just return the URL, don't show it in | |
433 the minibuffer. | |
434 | |
435 This uses `url-current-object', set locally to the buffer." | |
436 (interactive) | |
437 (if (not url-current-object) | |
438 nil | |
439 (if no-show | |
440 (url-recreate-url url-current-object) | |
441 (message "%s" (url-recreate-url url-current-object))))) | |
442 | |
443 (eval-and-compile | |
444 (defvar url-get-url-filename-chars "-%.?@a-zA-Z0-9()_/:~=&" | |
96486
7369ded3b436
Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
94668
diff
changeset
|
445 "Valid characters in a URL.") |
54695 | 446 ) |
447 | |
448 (defun url-get-url-at-point (&optional pt) | |
449 "Get the URL closest to point, but don't change position. | |
450 Has a preference for looking backward when not directly on a symbol." | |
451 ;; Not at all perfect - point must be right in the name. | |
452 (save-excursion | |
453 (if pt (goto-char pt)) | |
454 (let (start url) | |
455 (save-excursion | |
456 ;; first see if you're just past a filename | |
457 (if (not (eobp)) | |
458 (if (looking-at "[] \t\n[{}()]") ; whitespace or some parens | |
459 (progn | |
460 (skip-chars-backward " \n\t\r({[]})") | |
461 (if (not (bobp)) | |
462 (backward-char 1))))) | |
463 (if (and (char-after (point)) | |
464 (string-match (eval-when-compile | |
465 (concat "[" url-get-url-filename-chars "]")) | |
466 (char-to-string (char-after (point))))) | |
467 (progn | |
468 (skip-chars-backward url-get-url-filename-chars) | |
469 (setq start (point)) | |
470 (skip-chars-forward url-get-url-filename-chars)) | |
471 (setq start (point))) | |
472 (setq url (buffer-substring-no-properties start (point)))) | |
473 (if (and url (string-match "^(.*)\\.?$" url)) | |
474 (setq url (match-string 1 url))) | |
475 (if (and url (string-match "^URL:" url)) | |
476 (setq url (substring url 4 nil))) | |
477 (if (and url (string-match "\\.$" url)) | |
478 (setq url (substring url 0 -1))) | |
479 (if (and url (string-match "^www\\." url)) | |
480 (setq url (concat "http://" url))) | |
481 (if (and url (not (string-match url-nonrelative-link url))) | |
482 (setq url nil)) | |
483 url))) | |
484 | |
485 (defun url-generate-unique-filename (&optional fmt) | |
486 "Generate a unique filename in `url-temporary-directory'." | |
101912
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
487 ;; This variable is obsolete, but so is this function. |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
488 (let ((tempdir (with-no-warnings url-temporary-directory))) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
489 (if (not fmt) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
490 (let ((base (format "url-tmp.%d" (user-real-uid))) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
491 (fname "") |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
492 (x 0)) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
493 (setq fname (format "%s%d" base x)) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
494 (while (file-exists-p |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
495 (expand-file-name fname tempdir)) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
496 (setq x (1+ x) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
497 fname (concat base (int-to-string x)))) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
498 (expand-file-name fname tempdir)) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
499 (let ((base (concat "url" (int-to-string (user-real-uid)))) |
54695 | 500 (fname "") |
501 (x 0)) | |
101912
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
502 (setq fname (format fmt (concat base (int-to-string x)))) |
54695 | 503 (while (file-exists-p |
101912
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
504 (expand-file-name fname tempdir)) |
54695 | 505 (setq x (1+ x) |
101912
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
506 fname (format fmt (concat base (int-to-string x))))) |
c28ecc931e8c
(url-generate-unique-filename): Silence compiler.
Glenn Morris <rgm@gnu.org>
parents:
101887
diff
changeset
|
507 (expand-file-name fname tempdir))))) |
101887
3a192c2f3ada
(url-generate-unique-filename): Mark as obsolete.
Chong Yidong <cyd@stupidchicken.com>
parents:
101145
diff
changeset
|
508 (make-obsolete 'url-generate-unique-filename 'make-temp-file "23.1") |
54695 | 509 |
510 (defun url-extract-mime-headers () | |
511 "Set `url-current-mime-headers' in current buffer." | |
512 (save-excursion | |
513 (goto-char (point-min)) | |
514 (unless url-current-mime-headers | |
515 (set (make-local-variable 'url-current-mime-headers) | |
516 (mail-header-extract))))) | |
517 | |
79558
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
518 (defun url-make-private-file (file) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
519 "Make FILE only readable and writable by the current user. |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
520 Creates FILE and its parent directories if they do not exist." |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
521 (let ((dir (file-name-directory file))) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
522 (when dir |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
523 ;; For historical reasons. |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
524 (make-directory dir t))) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
525 ;; Based on doc-view-make-safe-dir. |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
526 (condition-case nil |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
527 (let ((umask (default-file-modes))) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
528 (unwind-protect |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
529 (progn |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
530 (set-default-file-modes #o0600) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
531 (with-temp-buffer |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
532 (write-region (point-min) (point-max) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
533 file nil 'silent nil 'excl))) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
534 (set-default-file-modes umask))) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
535 (file-already-exists |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
536 (if (file-symlink-p file) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
537 (error "Danger: `%s' is a symbolic link" file)) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
538 (set-file-modes file #o0600)))) |
ba4da6f08090
(url-make-private-file): New function.
Glenn Morris <rgm@gnu.org>
parents:
79064
diff
changeset
|
539 |
54695 | 540 (provide 'url-util) |
54699 | 541 |
54935
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
542 ;; arch-tag: 24352abc-5a5a-412e-90cd-313b26bed5c9 |
efddc239393d
(url-debug): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54803
diff
changeset
|
543 ;;; url-util.el ends here |