David Krentzlin avatar David Krentzlin committed 2bc884c Draft

initial import

Comments (0)

Files changed (8)

+syntax: glob
+
+*.so
+*.import.*
+
+open-uri for chicken scheme
+============================
+
+Examples
+========
+
+       (use open-uri)
+    
+       (display (open-uri "http://call-cc.org"))
+       (open-uri "http://wiki.call-cc.org" (lambda (port) (read-line port)))
+
+
+Implement your own openers
+==========================
+
+       (use open-uri-base)
+       
+       (define (my-opener uri proc #!rest args)
+         ;; implement it
+         )
+
+       ;;register it
+       (register-uri-opener! 'frooble my-opener)
+
+       ;;register multiple schemes
+       (register-uri-opener! '(frooble barbaz) my-opener)

open-uri-base.scm

+(module open-uri-base
+(register-uri-opener! uri-opener-ref)
+(import chicken scheme)
+
+(require-library srfi-69)
+(import (only srfi-69 make-hash-table hash-table-ref/default hash-table-set!))
+
+(define uri-openers (make-hash-table))
+
+(define (uri-opener-ref scheme)
+  (hash-table-ref/default uri-openers scheme #f))
+
+(define (register-uri-opener! name-or-names proc)
+  (let ((names (if (list? name-or-names) name-or-names (list name-or-names))))
+    (for-each (lambda (name)
+                (hash-table-set! uri-openers name proc))
+              names)))
+
+)
+(module open-uri-ftp
+()
+(import chicken scheme)
+(require-library ftp)
+(import ftp)
+
+)

open-uri-http.scm

+(module open-uri-http
+ ()
+ (import chicken scheme)
+ (require-library open-uri-base http-client)
+ (import open-uri-base http-client)
+
+(define (open-uri-http uri proc #!rest args)
+  (if (null? args)
+      (call-with-input-request uri #f proc)
+      (call-with-input-request uri (car args) proc)))
+
+(register-uri-opener! '(http https) open-uri-http)
+
+
+)
+((egg "open-uri"
+  (author "David Krentzlin")
+  (synopsis "Simlify the work with uri referencable resources")
+  (category net)
+  (license "MIT")
+  (needs uri-common http-client)
+  (test-depends test)))
+  
+(module open-uri
+(open-uri)
+(import chicken scheme)
+(require-library uri-common open-uri-base open-uri-http)
+
+(import open-uri-base
+        open-uri-http
+        (only uri-common uri-reference uri-scheme)
+        (only utils read-all))
+
+
+(define (complain kind message)
+  (signal
+   (make-composite-condition
+    (make-property-condition 'exn 'message message)
+    (make-property-condition kind
+                             'message message))))
+
+(define (open-uri uri #!optional (proc (lambda (p) (read-all p))) #!rest opener-args)
+  (let* ((uri-parsed (uri-reference uri))
+         (opener (uri-opener-ref (uri-scheme uri-parsed))))
+    (unless opener
+      (complain 'uri-scheme-unsupported
+                (sprintf "The uri-scheme '~A' is unsupported by open-uri" (uri-scheme uri-parsed))))
+    (apply opener uri-parsed proc opener-args)))
+)
+(define version "0.0.1")
+
+(define (add-extension lib extension)
+  (string->symbol (string-append (symbol->string lib) extension)))
+
+(for-each (lambda (ext)
+  (compile -s -d0 -O3 ,(add-extension ext ".scm") -j ,ext)
+  (compile -s -d0 -O3 ,(add-extension ext ".import.scm")) 
+
+  (install-extension
+   ext
+   `(,(symbol->string (add-extension ext ".import.scm")) ,(symbol->string (add-extension ext ".so")))
+   `((version ,version))))
+
+   '(open-uri-base open-uri-http open-uri))
+
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.