hy/eg/debian/parse-rfc822.hy
Gergely Nagy 494bf0e8ad Remove the import-as and import-from builtins
The new and improved (import) can handle all cases import-as and
import-from did, so drop the latter two from the language. To do this,
the import builtin had to be changed a little: if there's a single
import statement to return, return it as-is, otherwise return a list of
imports.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2013-04-20 16:06:32 +02:00

41 lines
1.1 KiB
Hy

#!/usr/bin/env hy
; Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2013 under the terms
; of the Expat license, a copy of which you have should have recieved with
; the source.
(import sys)
(defn parse-rfc822-file [path]
"Parse an RFC822 file"
(with-as (open path "r") fd
(parse-rfc822-stream fd)))
(defn parse-rfc822-stream [fd]
"Parse an RFC822 stream"
(setv bits {})
(setv key null)
(for [line fd]
(if (in ":" line)
(do (setv line (.split line ":" 1))
(setv key (.strip (get line 0)))
(setv val (.strip (get line 1)))
(assoc bits key val))
(do
(if (= (.strip line) ".")
(assoc bits key (+ (get bits key) "\n"))
(assoc bits key (+ (get bits key) "\n" (.strip line)))))))
bits)
(setv block (parse-rfc822-file (get sys.argv 1)))
(setv source (get block "Source"))
(print source "is a(n)" (get block "Description"))
(import [sh [apt-cache]])
(setv archive-block (parse-rfc822-stream (.show apt-cache source)))
(print "The archive has version" (get archive-block "Version") "of" source)