From b32df2100a02c74df2948a16a2f4f53ed5fd4625 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 30 Mar 2009 20:45:55 -0500 Subject: [PATCH 1/2] Fix parse-feed for byte arrays --- basis/syndication/syndication-docs.factor | 8 ++++---- basis/syndication/syndication-tests.factor | 4 ++-- basis/syndication/syndication.factor | 21 ++++++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/basis/syndication/syndication-docs.factor b/basis/syndication/syndication-docs.factor index 5604a94dbd..47bdc3bb36 100644 --- a/basis/syndication/syndication-docs.factor +++ b/basis/syndication/syndication-docs.factor @@ -35,9 +35,9 @@ HELP: download-feed { $values { "url" url } { "feed" feed } } { $description "Downloads a feed from a URL using the " { $link "http.client" } "." } ; -HELP: string>feed -{ $values { "string" string } { "feed" feed } } -{ $description "Parses a feed in string form." } ; +HELP: parse-feed +{ $values { "sequence" "a string or a byte array" } { "feed" feed } } +{ $description "Parses a feed." } ; HELP: xml>feed { $values { "xml" xml } { "feed" feed } } @@ -58,7 +58,7 @@ $nl { $subsection } "Reading feeds:" { $subsection download-feed } -{ $subsection string>feed } +{ $subsection parse-feed } { $subsection xml>feed } "Writing feeds:" { $subsection feed>xml } diff --git a/basis/syndication/syndication-tests.factor b/basis/syndication/syndication-tests.factor index 616ce2723a..3ea037352c 100644 --- a/basis/syndication/syndication-tests.factor +++ b/basis/syndication/syndication-tests.factor @@ -1,4 +1,4 @@ -USING: syndication io kernel io.files tools.test io.encodings.utf8 +USING: syndication io kernel io.files tools.test io.encodings.binary calendar urls xml.writer ; IN: syndication.tests @@ -8,7 +8,7 @@ IN: syndication.tests : load-news-file ( filename -- feed ) #! Load an news syndication file and process it, returning #! it as an feed tuple. - utf8 file-contents string>feed ; + binary file-contents parse-feed ; [ T{ feed diff --git a/basis/syndication/syndication.factor b/basis/syndication/syndication.factor index 9901fd4ce4..3bfc95fe3a 100755 --- a/basis/syndication/syndication.factor +++ b/basis/syndication/syndication.factor @@ -1,11 +1,11 @@ ! Copyright (C) 2006 Chris Double, Daniel Ehrenberg. -! Portions copyright (C) 2008 Slava Pestov. +! Portions copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: xml.traversal kernel assocs math.order - strings sequences xml.data xml.writer - io.streams.string combinators xml xml.entities.html io.files io - http.client namespaces make xml.syntax hashtables - calendar.format accessors continuations urls present ; +USING: xml.traversal kernel assocs math.order strings sequences +xml.data xml.writer io.streams.string combinators xml +xml.entities.html io.files io http.client namespaces make +xml.syntax hashtables calendar.format accessors continuations +urls present byte-arrays ; IN: syndication : any-tag-named ( tag names -- tag-inside ) @@ -106,12 +106,15 @@ TUPLE: entry title url description date ; { "feed" [ atom1.0 ] } } case ; -: string>feed ( string -- feed ) - [ string>xml xml>feed ] with-html-entities ; +GENERIC: parse-feed ( string -- feed ) + +M: string parse-feed [ string>xml xml>feed ] with-html-entities ; + +M: byte-array parse-feed [ bytes>xml xml>feed ] with-html-entities ; : download-feed ( url -- feed ) #! Retrieve an news syndication file, return as a feed tuple. - http-get nip string>feed ; + http-get nip parse-feed ; ! Atom generation From 65cb08c3550962672a03d14ae76ae23da6d224c4 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 31 Mar 2009 11:12:05 -0500 Subject: [PATCH 2/2] fix help-lint for syndication --- basis/syndication/syndication.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/syndication/syndication.factor b/basis/syndication/syndication.factor index 3bfc95fe3a..75c1824c78 100755 --- a/basis/syndication/syndication.factor +++ b/basis/syndication/syndication.factor @@ -106,7 +106,7 @@ TUPLE: entry title url description date ; { "feed" [ atom1.0 ] } } case ; -GENERIC: parse-feed ( string -- feed ) +GENERIC: parse-feed ( sequence -- feed ) M: string parse-feed [ string>xml xml>feed ] with-html-entities ;