Re: Pipe and http

2008-12-12 Thread Alexander Burger
Sorry friends, it was STILL not completely correct! :-(

On Mon, Oct 20, 2008 at 07:09:06AM +0200, Alexander Burger wrote:
> Fixed! I uploaded a new "testing" version.
> 
> Both effects were a result of the fact that 'pipe' did not write to the
> process' standard output as it should. Instead, it used the parent
> process' current output channel, causing the conflicts. Fixing that
> involved only inserting some output channel initialization.

It was still wrong when the child process nested another output channel.

But now I believe it is right. It is fixed in the latest "testing".

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe


Re: Pipe and http

2008-10-19 Thread Alexander Burger
Hi all,

On Sun, Oct 19, 2008 at 04:15:15PM +0200, Alexander Burger wrote:
> it seems that there is still another problem with 'pipe'. If I try:

Fixed! I uploaded a new "testing" version.

Both effects were a result of the fact that 'pipe' did not write to the
process' standard output as it should. Instead, it used the parent
process' current output channel, causing the conflicts. Fixing that
involved only inserting some output channel initialization.

Now both Tomas' length measurements as Henrik's XML output are working.

Many thanks to both of you!

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Alexander Burger
Hi all,

it seems that there is still another problem with 'pipe'. If I try:

   (out (tmp "a") (println (pipe (prinl "abc") (line T

Then "tmp//a" should contain a single line with 'abc'. However, it
also contains another line with 'NIL'. So it looks like that 'pipe'
interferes with the output channel of the parent process.

I noticed this problem when I modified Tomas's 'prinLength1' function to

   (length (pipe (out NIL (prin X)) (line T)))

i.e. put in an artificial 'out', to repair the modified output from
'ht:Out'. Though 'prinLength1' now returned the correct value, the HTML
output still did not work properly.

Let me investigate this a little more during the next days.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Alexander Burger
Henrik, Thomas, you are right!

On Sun, Oct 19, 2008 at 06:10:37PM +0700, Henrik Sarvell wrote:
> The pipe call in question is being made in articlesByFeed>, could
> first calling httpHead and or ht:Out be a problem?

Bingo! 'ht:Out' is the reason. When in chunked mode, it modifies the
output stream handler. This is then inherited by the forked process in
'pipe', so that any printing there will also be chunked.

I would indeed call this a bug. It causes an unexpected side effect
inside 'pipe' :-(

But how to solve it? 'ht:Out' is probably not a clean solution, it was
an afterthought to support chunked transfers, but I do not see a better
way at the moment.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Tomas Hlavaty
Hi Alex,

>> 'pipe' worked fine except when run in a server which returned NIL.
>
> This would indeed be a bug in the PicoLisp kernel. Do you think you can
> construct a simple, stand-alone example that demonstrates this effect?

the following script shows the bug:



#!bin/picolisp lib.l

(load "@ext.l" "@lib/http.l" "@lib/xhtml.l")

(de prinLength1 (X)
#   (length X))
   (length (pipe (prin X) (line T

#(test 2 (prinLength1 "hi"))
#(test 5 (prinLength1 'hello))
#(test 9 (prinLength1 '(1 2 3 4 56 789)))

(de start1 ()
   (for X (mapcar prinLength1 '("hi" "hello" (1 2 3 4 56 789)))
  (html 0 "Hello" "lib.css" NIL
 ( (ht:Prin X)

(de start2 ()
   (msg "start2")
   (msg (prinLength1 "bug"))
   (msg (length "bug"))
   (html 0 "Hello" "lib.css" NIL
  (for X '("hi" "hello" (1 2 3 4 56 789))
 ( NIL (ht:Prin X) " " (ht:Prin (prinLength1 X))

(server 8080 "@start2")



It works with

(de prinLength1 (X)
   (length X))

but breaks with

(de prinLength1 (X)
   (length (pipe (prin X) (line T

(msg ...) show prinLength1 0 for the server version.

However, the tests

(test 2 (prinLength1 "hi"))
(test 5 (prinLength1 'hello))
(test 9 (prinLength1 '(1 2 3 4 56 789)))

pass when not run in a server.

Also, when using pipe version, the http output is messed up...

Cheers,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Henrik Sarvell
I'm trying to output a nested list to text, see the (trace 'pipe)
output I copy pasted.

Why do you think there might be a bug in the kernel? Obviously
everything is working fine when we work in a non server context and as
far as I know the http server is not a part of the kernel?

Note also that my pipe xml combination is called after first calling
ht:Out for instance, here is the calling function:

(de readFeed ()
  (usrQuit)
  (httpHead "text/plain; charset=utf-8")
  (let Feed (db 'xmlUrl '+Feed (get 'xmlUrl 'http))
 (ht:Out T
( 'feed_headline (ht:Prin (; Feed title)))
(renderArticles (articlesByFeed> '+Rss Feed)

The pipe call in question is being made in articlesByFeed>, could
first calling httpHead and or ht:Out be a problem?

/Henrik
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Alexander Burger
Hi Tomas,

> 'pipe' worked fine except when run in a server which returned NIL.

This would indeed be a bug in the PicoLisp kernel. Do you think you can
construct a simple, stand-alone example that demonstrates this effect?

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Alexander Burger
On Sun, Oct 19, 2008 at 12:04:12PM +0200, Alexander Burger wrote:
> > Trying (trace 'pipe) in the server
> 
> Ah, this does not work. Only "normal" functions (that evaluate all their
> arguments) can be traced. 'trace' is not intelligent enough to know how
> built-in functions evaluate their arguments.

What would work and make sense in your case, however, is

   (trace 'xml)
   (trace 'line)

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Alexander Burger
Hi Henrik,

> (pipe (xml Html) (till NIL T))

What is the value of the variable 'Html' here? When 'xml' is called with
an argument, it expects a nested list, i.e. it outputs the structures in
that list as XML text.

>From what you write I'm not sure whether you want to convert list
structures to XML text (then the above 'pipe' call would be correct) or
vice versa.


> This works fine when I try the "raw" functionality without using the
> http server. However, when exactly the same code is called in the real
> application (within the context of the http server) the above results
> in NIL instead of the HTML.

The above 'pipe' call should be completely self-consistent. It does not
matter in which context it is running.

If, however, 'Html' is NIL (i.e. you intend to convert XML text to list
structures), then 'xml' would try to read from the current input channel
and would indeed depend on the input context.



> Trying (trace 'pipe) in the server

Ah, this does not work. Only "normal" functions (that evaluate all their
arguments) can be traced. 'trace' is not intelligent enough to know how
built-in functions evaluate their arguments.


> I've had exactly the same behavior happen to me when calling a ruby
> script through (call), It was resolved by using (in) instead, like
> this (which works):
> 
> (in (list 'ruby "projects/rss-reader/htmldecode.rb" Str) (till))

Yes. For a pipe from some external process 'in' is the best solution.
Only when you need a pipe from one part in your program to another,
'pipe' is appropriate.


> Could the problem be that xml is outputting unchunked to pipe and the
> http server chokes on this?

This cannot happen, because (pipe (somePrinting) (someReading)) does not
know nor interfer with the http server. It just sends the output from
'somePrinting' to the input of 'someReading'.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Pipe and http

2008-10-19 Thread Tomas Hlavaty
Hi Henrik,

> to convert the HTML parts back to HTML through the use of the xml
> library, to store the text in the database as is. I do not want to
> output the result of course so I use pipe to grab it instead, like so:

Using lib/xml.l for parsing html/sgml is not reliable unless the
html/xhtml you are trying to parse is well formed xml (which is quite
rare on the web usualy).

> (pipe (xml Html) (till NIL T))
>
> This works fine when I try the "raw" functionality without using the
> http server. However, when exactly the same code is called in the real
> application (within the context of the http server) the above results
> in NIL instead of the HTML. Trying (trace 'pipe) in the server
> application just locks up the whole process, doing it in the testcode
> gives me this example though:
>
> I've had exactly the same behavior happen to me when calling a ruby
> script through (call), It was resolved by using (in) instead, like
> this (which works):
>
> (in (list 'ruby "projects/rss-reader/htmldecode.rb" Str) (till))

I found the same problem when using bcrypt for password protection as
discussed in
http://www.mail-archive.com/picolisp@software-lab.de/msg00214.html

   (unless (<= 8 (length (pipe (prin Salt) (line T))) 56)
  (quit "Length of Salt must be from 8 to 56" Salt))

'pipe' worked fine except when run in a server which returned NIL.

> Why is this happening and how can it be resolved, any ideas?
>
> Could the problem be that xml is outputting unchunked to pipe and the
> http server chokes on this?

I am curious too.  I guess it has something to do with the way
picolisp handles files during pipe or call?

Cheers,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Pipe and http

2008-10-19 Thread Henrik Sarvell
I currently have a section of code that is loading a remote XML (RSS2
or Atom) and then loads all articles. Since we are talking about HTML
inside XML here there is no way for the xml library to realize this,
and there should be no reason for it either.

In any case because of this I find myself in a situation where I have
to convert the HTML parts back to HTML through the use of the xml
library, to store the text in the database as is. I do not want to
output the result of course so I use pipe to grab it instead, like so:

(pipe (xml Html) (till NIL T))

This works fine when I try the "raw" functionality without using the
http server. However, when exactly the same code is called in the real
application (within the context of the http server) the above results
in NIL instead of the HTML. Trying (trace 'pipe) in the server
application just locks up the whole process, doing it in the testcode
gives me this example though:

 pipe : ">" NIL
 pipe = NIL
http://www.w3.org/1999/xhtml";>
   
  Last night, after the Canadian election
  http://www.cbc.ca/news/canadavotes/debate-english/comments-video.html";>
 party leaders'
 debate
  
..
   



I've had exactly the same behavior happen to me when calling a ruby
script through (call), It was resolved by using (in) instead, like
this (which works):

(in (list 'ruby "projects/rss-reader/htmldecode.rb" Str) (till))

Why is this happening and how can it be resolved, any ideas?

Could the problem be that xml is outputting unchunked to pipe and the
http server chokes on this?

/Henrik
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]