Mercurial > core / lisp/lib/obj/uri/print.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
8d7aa0af2367
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; obj/uri/print.lisp --- URI printers 7 (defvar *render-include-slash-on-null-path* nil) ;; rfe11850 8 (defvar *uri-schema-print-case* :downcase) 10 (defmethod render-uri ((uri uri) stream 11 &aux (encode (uri-escaped uri)) 14 (declare (optimize (safety 0))) 15 (when (null (setq res (uri-string uri))) 16 (setf (uri-string uri) 17 (let ((scheme (uri-scheme uri)) 18 (host (%uri-host uri)) 19 (ipv6 (%uri-ipv6 uri)) 20 zone-id ;; don't compute until needed 21 (userinfo (uri-userinfo uri)) 24 (query (uri-query uri)) 25 (fragment (uri-fragment uri))) 29 (case *uri-schema-print-case* 31 (string-downcase (symbol-name scheme))) 33 (symbol-name scheme)))) 35 (when (or host ipv6 (eq :file scheme) (eq :hdfs scheme)) 39 then (percent-encode-string userinfo *userinfo-bitvector*) 43 then (if* (setq zone-id (%uri-zone-id uri)) 44 then (concatenate 'string "[" ipv6 "%25" zone-id "]") 45 else (concatenate 'string "[" ipv6 "]")) 48 then (percent-encode-string host *reg-name-bitvector*) 50 (when port (format nil ":~d" port)) 53 elseif (and *render-include-slash-on-null-path* 54 #|no path but:|# scheme host) 59 then (percent-encode-string 62 then *query-bitvector-strict* 63 else *query-bitvector-non-strict*)) 68 then (percent-encode-string 71 then *fragment-bitvector-strict* 72 else *fragment-bitvector-non-strict*)) 75 ;; calculate this cached slot 76 (uri-parsed-path uri)) 79 then (princ res stream) 82 (defmethod render-uri ((urn urn) stream 83 &aux (*print-pretty* nil)) 84 ;; This doesn't do encoding because no decoding is done for URNs when 86 (when (null (uri-string urn)) 87 (setf (uri-string urn) 88 (let ((nid (urn-nid urn)) 90 (r (urn-r-component urn)) 91 (q (urn-q-component urn)) 92 (f (urn-f-component urn))) 93 (concatenate 'string "urn:" nid ":" nss 101 then (write-string (uri-string urn) stream) 102 else (uri-string urn))) 104 (defmethod uri-to-string ((uri uri) 105 &aux (encode (uri-escaped uri)) 108 (declare (optimize (safety 0))) 109 (when (null (setq res (uri-string uri))) 110 (setf (uri-string uri) 111 (let ((scheme (uri-scheme uri)) 112 (host (%uri-host uri)) 113 (ipv6 (%uri-ipv6 uri)) 114 zone-id ;; don't compute until needed 115 (userinfo (uri-userinfo uri)) 116 (port (uri-port uri)) 117 (path (uri-path uri)) 118 (query (uri-query uri)) 119 (fragment (uri-fragment uri))) 123 (case *uri-schema-print-case* 125 (string-downcase (symbol-name scheme))) 127 (symbol-name scheme)))) 129 (when (or host ipv6 (eq :file scheme) (eq :hdfs scheme)) 133 then (percent-encode-string userinfo *userinfo-bitvector*) 137 then (if* (setq zone-id (%uri-zone-id uri)) 138 then (concatenate 'string "[" ipv6 "%25" zone-id "]") 139 else (concatenate 'string "[" ipv6 "]")) 142 then (percent-encode-string host *reg-name-bitvector*) 148 elseif (and *render-include-slash-on-null-path* 149 #|no path but:|# scheme host) 156 then (percent-encode-string 159 then *fragment-bitvector-strict* 160 else *fragment-bitvector-non-strict*)) 163 ;; calculate this cached slot 164 (uri-parsed-path uri)) 168 (defmethod iri-to-string ((iri iri)) 171 (defmethod uri-to-string ((urn urn)) 172 ;; We can use render-uri here because no decoding/encoding happens for 174 (render-uri urn nil)) 176 (defun render-parsed-path (path-list escape) 178 (first (car path-list)) 179 (pl (cdr path-list) (cdr pl)) 180 (pe (car pl) (car pl))) 182 (when res (apply #'concatenate 'string (nreverse res)))) 183 (when (or (null first) 184 (prog1 (and (eq :absolute first) 185 ;; Only happens on Windows, in the case of a path 186 ;; with a drive letter in it. The drive letter 187 ;; element is a keyword naming the drive. 192 then ;; Only happens on Windows. It's a keyword corresponding to 194 (push (format nil "~a:" pe) res) 197 then (push (percent-encode-string pe *pchar-bitvector*) 200 else ;; contains params 202 then (push (percent-encode-string (car pe) *pchar-bitvector*) 204 else (push (car pe) res)) 205 (dolist (item (cdr pe)) 208 then (push (percent-encode-string item *pchar-bitvector*) 210 else (push item res)))))) 212 (defmethod print-object ((uri uri) stream) 214 then (format stream "#<~a ~a>" 215 (class-name (class-of uri)) 216 (render-uri uri nil)) 217 else (render-uri uri stream)))