emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/plz-media-type c97da04f3a 20/26: Make plz-media-type-of


From: ELPA Syncer
Subject: [elpa] externals/plz-media-type c97da04f3a 20/26: Make plz-media-type-of-response public
Date: Wed, 1 May 2024 09:59:02 -0400 (EDT)

branch: externals/plz-media-type
commit c97da04f3a870e7cb3eb24a5c6b95be162dda548
Author: Roman Scherer <roman@burningswell.com>
Commit: Roman Scherer <roman@burningswell.com>

    Make plz-media-type-of-response public
---
 plz-media-type.el            | 40 ++++++++++++++++++++--------------------
 tests/test-plz-media-type.el |  6 +++---
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/plz-media-type.el b/plz-media-type.el
index ca63ce241d..8ae963fc47 100644
--- a/plz-media-type.el
+++ b/plz-media-type.el
@@ -72,6 +72,19 @@ parameter in the content type header, or the coding-sytem of 
the
 media type.  If the coding system of a media type is nil, the
 response will not be decoded.")
 
+(cl-defgeneric plz-media-type-else (media-type error)
+  "Transform and handle the ERROR according to MEDIA-TYPE.")
+
+(cl-defgeneric plz-media-type-then (media-type response)
+  "Transform and handle the RESPONSE according to MEDIA-TYPE.")
+
+(cl-defgeneric plz-media-type-process (media-type process chunk)
+  "Process the CHUNK according to MEDIA-TYPE using PROCESS.")
+
+(cl-defmethod plz-media-type-else ((_ (eql nil)) error)
+  "Transform and handle the ERROR according to MEDIA-TYPE."
+  error)
+
 (defun plz-media-type-charset (media-type)
   "Return the character set of the MEDIA-TYPE."
   (with-slots (parameters) media-type
@@ -98,18 +111,11 @@ response will not be decoded.")
   "Return the name of the MEDIA-TYPE as a symbol."
   (intern (plz-media-type-name media-type)))
 
-(cl-defgeneric plz-media-type-else (media-type error)
-  "Transform and handle the ERROR according to MEDIA-TYPE.")
-
-(cl-defgeneric plz-media-type-then (media-type response)
-  "Transform and handle the RESPONSE according to MEDIA-TYPE.")
-
-(cl-defgeneric plz-media-type-process (media-type process chunk)
-  "Process the CHUNK according to MEDIA-TYPE using PROCESS.")
-
-(cl-defmethod plz-media-type-else ((_ (eql nil)) error)
-  "Transform and handle the ERROR according to MEDIA-TYPE."
-  error)
+(defun plz-media-type-of-response (media-types response)
+  "Lookup the content type of RESPONSE in MEDIA-TYPES."
+  (let ((media-type (plz-media-type--content-type response)))
+    (clone (plz-media-type--find media-types media-type)
+           :parameters (oref media-type parameters))))
 
 (defun plz-media-type--parse (header)
   "Parse the Content-Type HEADER and return a `plz-media-type' instance."
@@ -141,12 +147,6 @@ response will not be decoded.")
       (alist-get t media-types)
       (plz-media-type:application/octet-stream)))
 
-(defun plz-media-type--of-response (media-types response)
-  "Lookup the content type of RESPONSE in MEDIA-TYPES."
-  (let ((media-type (plz-media-type--content-type response)))
-    (clone (plz-media-type--find media-types media-type)
-           :parameters (oref media-type parameters))))
-
 (defvar-local plz-media-type--current nil
   "The media type of the process buffer.")
 
@@ -216,7 +216,7 @@ STRING which is output just received from the process."
             (goto-char (point-min))
             (when-let (chunk (plz-media-type--parse-response))
               (delete-region (point) (point-max))
-              (let ((media-type (plz-media-type--of-response media-types 
chunk)))
+              (let ((media-type (plz-media-type-of-response media-types 
chunk)))
                 (setq-local plz-media-type--current media-type)
                 (setq-local plz-media-type--response
                             (make-plz-response
@@ -506,7 +506,7 @@ parsing the HTTP response body with the
             (cond
              ((plz-error-response plzerror)
               (let ((response (plz-error-response plzerror)))
-                (if-let (media-type (plz-media-type--of-response media-types 
response))
+                (if-let (media-type (plz-media-type-of-response media-types 
response))
                     (list msg (with-temp-buffer
                                 (when-let (body (plz-response-body response))
                                   (insert body)
diff --git a/tests/test-plz-media-type.el b/tests/test-plz-media-type.el
index 4d2f4ebe88..2ded9b8a1e 100644
--- a/tests/test-plz-media-type.el
+++ b/tests/test-plz-media-type.el
@@ -132,13 +132,13 @@
   (let ((media-type (plz-media-type--parse "text/html; charset=us-ascii")))
     (should (equal 'us-ascii (plz-media-type-coding-system media-type)))))
 
-(ert-deftest test-plz-media-type--of-response ()
+(ert-deftest test-plz-media-type-of-response ()
   (let* ((response (make-plz-response :headers '((content-type . 
"text/html"))))
-         (media-type (plz-media-type--of-response plz-media-types response)))
+         (media-type (plz-media-type-of-response plz-media-types response)))
     (should (equal 'text/html (plz-media-type-symbol media-type)))
     (should (equal 'utf-8 (plz-media-type-coding-system media-type))))
   (let* ((response (make-plz-response :headers '((content-type . "text/html; 
charset=us-ascii"))))
-         (media-type (plz-media-type--of-response plz-media-types response)))
+         (media-type (plz-media-type-of-response plz-media-types response)))
     (should (equal 'text/html (plz-media-type-symbol media-type)))
     (should (equal 'us-ascii (plz-media-type-coding-system media-type)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]