<!-- google_ad_section_start -->planet mars<!-- google_ad_section_end -->
Health Forums

Go Back   Health Forums > Mental Health > Schizophrenia > alt.support.schizophrenia

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-11-2008, 02:10 AM
Judy
Guest
 
Posts: n/a
Default planet mars


http://www.intertwingly.net/code/mars/planet/sift.rb


require 'planet/fido'
require 'planet/log'
require 'html5'
require 'html5/sanitizer'

module Planet
def Planet.sift node, fido
unique = {}

node.elements.each do |child|
next unless child.namespace == 'http://www.w3.org/2005/Atom'
child.name = child.name # remove prefix

# remove, merge, or allow through duplicate children
if unique.has_key? child.name
case child.name
when 'author'
unique['author'].elements.each {|prevnode|
next unless prevnode.text
curnode = child.elements[prevnode.name]
if not curnode
child.add prevnode
elsif not curnode.text
curno

de.text = prevnode.texts.map {|t| t.value}.join
end
}
unique[child.name].remove
when 'entry', 'category', 'contributor', 'link'
else
unique[child.name].remove
end
end

unique[child.name] = child

# node specific canonicalization
case child.name
when 'content', 'rights', 'subtitle', 'summary', 'title'
make_absolute child, 'src'

if child.attributes['type'] == 'html'
text = child.texts.map {|t| t.value}.join.strip
child.children.each {|text_node| text_node.remove}
div = child.add_element('div')
div.add_namespace 'http://www.w3.org/1999/xhtml'
HTML5.parse_fragment(text, :encoding => 'UTF-8').each do |
frag|
div.add(frag)
end
child.attributes['type'] = 'xhtml'
end

if child.attributes['type'] == 'xhtml'
child.elements.each {|xhtml_element| sanitize xhtml_element,
fido}
end

when 'category'
make_absolute child, 'scheme'
when 'link'
make_absolute child, 'href'
child.attributes['rel'] = 'alternate' unless
child.attribute('rel')
when 'icon', 'logo', 'uri'
value = child.texts.map {|t| t.value}.join
if !value.empty? and value != 'http://'
value = uri_norm(child.xmlbase, value)
child.children {|text_node| text_node.remove}
child.text = value
else
child.remove
end
when 'generator'
make_absolute child, 'uri'
when 'published', 'updated'
if child.text
text = child.texts.map {|t| t.value}.join
child.children.each {|text_node| text_node.remove}
child.text = DateTime.parse(text).to_s
end
when 'author', 'email', 'entry', 'feed', 'id', 'name', 'source'
else
child.add_namespace('http://planet.intertwingly.net/unknown')
end

sift child, fido

end

# ensure required elements are present
if %w(entry feed source).include? node.name
if !unique.has_key? 'title'
node << REXML::Element.new('title')
end

if !unique.has_key? 'id'
link = node.elements['link[@rel="alternate"]/@href']
if link
id = node.add_element('id')
id.text = link.value
end
end
end
end

# resolve a relative URI attribute
def Planet.make_absolute node, attr_name
value = node.attributes[attr_name]
return unless value
value = uri_norm(node.xmlbase, value) rescue value
node.attributes[attr_name] = value
end

# remove suspect markup, styles, uris
include HTML5::HTMLSanitizeModule
@sanitizer = HTML5::HTMLSanitizer.new ''
def Planet.sanitize node, fido
node.elements.each {|child| sanitize child, fido}

if node.namespace == 'http://www.w3.org/1999/xhtml'
elist = ACCEPTABLE_ELEMENTS
alist = ACCEPTABLE_ATTRIBUTES
elsif node.namespace == 'http://www.w3.org/2000/svg'
elist = SVG_ELEMENTS
alist = SVG_ATTRIBUTES
elsif node.namespace == 'http://www.w3.org/1998/Math/MathML'
elist = MATHML_ELEMENTS
alist = MATHML_ATTRIBUTES
else
elist = []
alist = []
end

if !elist.include? node.name

# inline svg objects
if node.name=='object' and node.attributes['type']=='image/svg
+xml'
begin
uri = Planet::uri_norm(node.attributes['data'])
response = fido.fetch(uri)
response = fido.read_from_cache(uri) if response.code ==
'304'
svg = REXML:ocument.new(response.body).root
node.parent.insert_after node, svg
svg.elements.each {|child| sanitize child, fido}
fido.write_to_cache node.attributes['data'], response
node.name = 'script' # make sure that children are eaten
rescue Exception => e
Planet.log.error e.inspect
Planet.log.error uri
e.backtrace.each {|line| Planet.log.error line}
end
end

# retain children from bogus elements, except for truly evil
ones
if !%w[script applet style].include? node.name
node.children.reverse.each {|child| node.next_sibling=child}
end

node.remove
else
node.attributes.each_value do |attribute|
if !alist.include? attribute.expanded_name
if attribute.expanded_name == 'style'
node.add_attribute attribute.expanded_name,
@sanitizer.sanitize_css(attribute.value)
elsif attribute.name != 'xmlns'
attribute.remove
end
elsif ATTR_VAL_IS_URI.include? attribute.expanded_name
begin
value = Addressable::URI.join(node.xmlbase,
attribute.value)
if ACCEPTABLE_PROTOCOLS.include? value.scheme
node.add_attribute attribute.expanded_name,
value.normalize.to_s
else
attribute.remove
end
rescue
attribute.remove
end
end
end
end
end

# add a convenience method for computing the xml:base for any given
Element
if not REXML::Element.public_instance_methods.include? "xmlbase"
class REXML::Element
def xmlbase
if not attribute('xml:base')
parent.xmlbase
elsif parent
Planet::uri_norm(parent.xmlbase,
attribute('xml:base').value)
else
attribute('xml:base').value || ''
end
end
end
end

end
Reply With Quote
  #2  
Old 03-11-2008, 03:25 AM
Judy
Guest
 
Posts: n/a
Default Re: planet mars

On 11 Mar, 01:44, Judy <jal...@easynet.co.uk> wrote:
> http://www.intertwingly.net/code/mars/planet/sift.rb


something I found on the web.


Best wishes

Judy

Remember " When I die I would like to die like my grandfather,
peacefully, and in his sleep. Not screaming in terror like the
passengers on his bus." ?

Somebody wanted to go out in a blaze of glory,
and ended up being comforted, in the midst of all their victims.

It is ALWAYS of great importance to remember where your feet are.
Reply With Quote
  #3  
Old 03-11-2008, 07:52 AM
Quiet Neighbor
Guest
 
Posts: n/a
Default Re: planet mars


"Judy" <jalees@easynet.co.uk> wrote in message
news:73dcdfba-2698-4721-94bb-0c17a8337431@59g2000hsb.googlegroups.com...
> On 11 Mar, 01:44, Judy <jal...@easynet.co.uk> wrote:
>> http://www.intertwingly.net/code/mars/planet/sift.rb

>
> something I found on the web.
>
>
> Best wishes
>
> Judy
>
> Remember " When I die I would like to die like my grandfather,
> peacefully, and in his sleep. Not screaming in terror like the
> passengers on his bus." ?
>
> Somebody wanted to go out in a blaze of glory,
> and ended up being comforted, in the midst of all their victims.
>
> It is ALWAYS of great importance to remember where your feet are.


I want to know why I'm dying. The idea of croaking in my sleep is
disturbing.

I refuse to go peacefully.





Reply With Quote
  #4  
Old 03-11-2008, 07:52 AM
zerosky
Guest
 
Posts: n/a
Default Re: planet mars



"Judy" <jal...@easynet.co.uk> wrote in message
news:1226f072-7564-40b3-9884-a5b2a0483a4e@y77g2000hsy.googlegroups.com...
>
> http://www.intertwingly.net/code/mars/planet/sift.rb
>
>
> require 'planet/fido'
> require 'planet/log'
> require 'html5'
> require 'html5/sanitizer'
>
> module Planet
> def Planet.sift node, fido
> unique = {}
>
> node.elements.each do |child|
> next unless child.namespace == 'http://www.w3.org/2005/Atom'
> child.name = child.name # remove prefix
>
> # remove, merge, or allow through duplicate children
> if unique.has_key? child.name
> case child.name
> when 'author'
> unique['author'].elements.each {|prevnode|
> next unless prevnode.text
> curnode = child.elements[prevnode.name]
> if not curnode
> child.add prevnode
> elsif not curnode.text
> curno
>
> de.text = prevnode.texts.map {|t| t.value}.join
> end
> }
> unique[child.name].remove
> when 'entry', 'category', 'contributor', 'link'
> else
> unique[child.name].remove
> end
> end
>
> unique[child.name] = child
>
> # node specific canonicalization
> case child.name
> when 'content', 'rights', 'subtitle', 'summary', 'title'
> make_absolute child, 'src'
>
> if child.attributes['type'] == 'html'
> text = child.texts.map {|t| t.value}.join.strip
> child.children.each {|text_node| text_node.remove}
> div = child.add_element('div')
> div.add_namespace 'http://www.w3.org/1999/xhtml'
> HTML5.parse_fragment(text, :encoding => 'UTF-8').each do |
> frag|
> div.add(frag)
> end
> child.attributes['type'] = 'xhtml'
> end
>
> if child.attributes['type'] == 'xhtml'
> child.elements.each {|xhtml_element| sanitize xhtml_element,
> fido}
> end
>
> when 'category'
> make_absolute child, 'scheme'
> when 'link'
> make_absolute child, 'href'
> child.attributes['rel'] = 'alternate' unless
> child.attribute('rel')
> when 'icon', 'logo', 'uri'
> value = child.texts.map {|t| t.value}.join
> if !value.empty? and value != 'http://'
> value = uri_norm(child.xmlbase, value)
> child.children {|text_node| text_node.remove}
> child.text = value
> else
> child.remove
> end
> when 'generator'
> make_absolute child, 'uri'
> when 'published', 'updated'
> if child.text
> text = child.texts.map {|t| t.value}.join
> child.children.each {|text_node| text_node.remove}
> child.text = DateTime.parse(text).to_s
> end
> when 'author', 'email', 'entry', 'feed', 'id', 'name', 'source'
> else
> child.add_namespace('http://planet.intertwingly.net/unknown')
> end
>
> sift child, fido
>
> end
>
> # ensure required elements are present
> if %w(entry feed source).include? node.name
> if !unique.has_key? 'title'
> node << REXML::Element.new('title')
> end
>
> if !unique.has_key? 'id'
> link = node.elements['link[@rel="alternate"]/@href']
> if link
> id = node.add_element('id')
> id.text = link.value
> end
> end
> end
> end
>
> # resolve a relative URI attribute
> def Planet.make_absolute node, attr_name
> value = node.attributes[attr_name]
> return unless value
> value = uri_norm(node.xmlbase, value) rescue value
> node.attributes[attr_name] = value
> end
>
> # remove suspect markup, styles, uris
> include HTML5::HTMLSanitizeModule
> @sanitizer = HTML5::HTMLSanitizer.new ''
> def Planet.sanitize node, fido
> node.elements.each {|child| sanitize child, fido}
>
> if node.namespace == 'http://www.w3.org/1999/xhtml'
> elist = ACCEPTABLE_ELEMENTS
> alist = ACCEPTABLE_ATTRIBUTES
> elsif node.namespace == 'http://www.w3.org/2000/svg'
> elist = SVG_ELEMENTS
> alist = SVG_ATTRIBUTES
> elsif node.namespace == 'http://www.w3.org/1998/Math/MathML'
> elist = MATHML_ELEMENTS
> alist = MATHML_ATTRIBUTES
> else
> elist = []
> alist = []
> end
>
> if !elist.include? node.name
>
> # inline svg objects
> if node.name=='object' and node.attributes['type']=='image/svg
> +xml'
> begin
> uri = Planet::uri_norm(node.attributes['data'])
> response = fido.fetch(uri)
> response = fido.read_from_cache(uri) if response.code ==
> '304'
> svg = REXML:ocument.new(response.body).root
> node.parent.insert_after node, svg
> svg.elements.each {|child| sanitize child, fido}
> fido.write_to_cache node.attributes['data'], response
> node.name = 'script' # make sure that children are eaten
> rescue Exception => e
> Planet.log.error e.inspect
> Planet.log.error uri
> e.backtrace.each {|line| Planet.log.error line}
> end
> end
>
> # retain children from bogus elements, except for truly evil
> ones
> if !%w[script applet style].include? node.name
> node.children.reverse.each {|child| node.next_sibling=child}
> end
>
> node.remove
> else
> node.attributes.each_value do |attribute|
> if !alist.include? attribute.expanded_name
> if attribute.expanded_name == 'style'
> node.add_attribute attribute.expanded_name,
> @sanitizer.sanitize_css(attribute.value)
> elsif attribute.name != 'xmlns'
> attribute.remove
> end
> elsif ATTR_VAL_IS_URI.include? attribute.expanded_name
> begin
> value = Addressable::URI.join(node.xmlbase,
> attribute.value)
> if ACCEPTABLE_PROTOCOLS.include? value.scheme
> node.add_attribute attribute.expanded_name,
> value.normalize.to_s
> else
> attribute.remove
> end
> rescue
> attribute.remove
> end
> end
> end
> end
> end
>
> # add a convenience method for computing the xml:base for any given
> Element
> if not REXML::Element.public_instance_methods.include? "xmlbase"
> class REXML::Element
> def xmlbase
> if not attribute('xml:base')
> parent.xmlbase
> elsif parent
> Planet::uri_norm(parent.xmlbase,
> attribute('xml:base').value)
> else
> attribute('xml:base').value || ''
> end
> end
> end
> end
>
> end





Stockhausen was quoted as saying that the events of 9/11 were..

'Lucifer's greatest work of art'

I suspect Madame Sosostris would not have remained so silent
had she but known...

zerosky


















Reply With Quote
  #5  
Old 03-11-2008, 07:52 AM
zerosky
Guest
 
Posts: n/a
Default Re: planet mars



"Judy" <jal...@easynet.co.uk> wrote in message
news:1226f072-7564-40b3-9884-a5b2a0483a4e@y77g2000hsy.googlegroups.com...
>
> http://www.intertwingly.net/code/mars/planet/sift.rb
>
>
> require 'planet/fido'
> require 'planet/log'
> require 'html5'
> require 'html5/sanitizer'
>
> module Planet
> def Planet.sift node, fido
> unique = {}
>
> node.elements.each do |child|
> next unless child.namespace == 'http://www.w3.org/2005/Atom'
> child.name = child.name # remove prefix
>
> # remove, merge, or allow through duplicate children
> if unique.has_key? child.name
> case child.name
> when 'author'
> unique['author'].elements.each {|prevnode|
> next unless prevnode.text
> curnode = child.elements[prevnode.name]
> if not curnode
> child.add prevnode
> elsif not curnode.text
> curno
>
> de.text = prevnode.texts.map {|t| t.value}.join
> end
> }
> unique[child.name].remove
> when 'entry', 'category', 'contributor', 'link'
> else
> unique[child.name].remove
> end
> end
>
> unique[child.name] = child
>
> # node specific canonicalization
> case child.name
> when 'content', 'rights', 'subtitle', 'summary', 'title'
> make_absolute child, 'src'
>
> if child.attributes['type'] == 'html'
> text = child.texts.map {|t| t.value}.join.strip
> child.children.each {|text_node| text_node.remove}
> div = child.add_element('div')
> div.add_namespace 'http://www.w3.org/1999/xhtml'
> HTML5.parse_fragment(text, :encoding => 'UTF-8').each do |
> frag|
> div.add(frag)
> end
> child.attributes['type'] = 'xhtml'
> end
>
> if child.attributes['type'] == 'xhtml'
> child.elements.each {|xhtml_element| sanitize xhtml_element,
> fido}
> end
>
> when 'category'
> make_absolute child, 'scheme'
> when 'link'
> make_absolute child, 'href'
> child.attributes['rel'] = 'alternate' unless
> child.attribute('rel')
> when 'icon', 'logo', 'uri'
> value = child.texts.map {|t| t.value}.join
> if !value.empty? and value != 'http://'
> value = uri_norm(child.xmlbase, value)
> child.children {|text_node| text_node.remove}
> child.text = value
> else
> child.remove
> end
> when 'generator'
> make_absolute child, 'uri'
> when 'published', 'updated'
> if child.text
> text = child.texts.map {|t| t.value}.join
> child.children.each {|text_node| text_node.remove}
> child.text = DateTime.parse(text).to_s
> end
> when 'author', 'email', 'entry', 'feed', 'id', 'name', 'source'
> else
> child.add_namespace('http://planet.intertwingly.net/unknown')
> end
>
> sift child, fido
>
> end
>
> # ensure required elements are present
> if %w(entry feed source).include? node.name
> if !unique.has_key? 'title'
> node << REXML::Element.new('title')
> end
>
> if !unique.has_key? 'id'
> link = node.elements['link[@rel="alternate"]/@href']
> if link
> id = node.add_element('id')
> id.text = link.value
> end
> end
> end
> end
>
> # resolve a relative URI attribute
> def Planet.make_absolute node, attr_name
> value = node.attributes[attr_name]
> return unless value
> value = uri_norm(node.xmlbase, value) rescue value
> node.attributes[attr_name] = value
> end
>
> # remove suspect markup, styles, uris
> include HTML5::HTMLSanitizeModule
> @sanitizer = HTML5::HTMLSanitizer.new ''
> def Planet.sanitize node, fido
> node.elements.each {|child| sanitize child, fido}
>
> if node.namespace == 'http://www.w3.org/1999/xhtml'
> elist = ACCEPTABLE_ELEMENTS
> alist = ACCEPTABLE_ATTRIBUTES
> elsif node.namespace == 'http://www.w3.org/2000/svg'
> elist = SVG_ELEMENTS
> alist = SVG_ATTRIBUTES
> elsif node.namespace == 'http://www.w3.org/1998/Math/MathML'
> elist = MATHML_ELEMENTS
> alist = MATHML_ATTRIBUTES
> else
> elist = []
> alist = []
> end
>
> if !elist.include? node.name
>
> # inline svg objects
> if node.name=='object' and node.attributes['type']=='image/svg
> +xml'
> begin
> uri = Planet::uri_norm(node.attributes['data'])
> response = fido.fetch(uri)
> response = fido.read_from_cache(uri) if response.code ==
> '304'
> svg = REXML:ocument.new(response.body).root
> node.parent.insert_after node, svg
> svg.elements.each {|child| sanitize child, fido}
> fido.write_to_cache node.attributes['data'], response
> node.name = 'script' # make sure that children are eaten
> rescue Exception => e
> Planet.log.error e.inspect
> Planet.log.error uri
> e.backtrace.each {|line| Planet.log.error line}
> end
> end
>
> # retain children from bogus elements, except for truly evil
> ones
> if !%w[script applet style].include? node.name
> node.children.reverse.each {|child| node.next_sibling=child}
> end
>
> node.remove
> else
> node.attributes.each_value do |attribute|
> if !alist.include? attribute.expanded_name
> if attribute.expanded_name == 'style'
> node.add_attribute attribute.expanded_name,
> @sanitizer.sanitize_css(attribute.value)
> elsif attribute.name != 'xmlns'
> attribute.remove
> end
> elsif ATTR_VAL_IS_URI.include? attribute.expanded_name
> begin
> value = Addressable::URI.join(node.xmlbase,
> attribute.value)
> if ACCEPTABLE_PROTOCOLS.include? value.scheme
> node.add_attribute attribute.expanded_name,
> value.normalize.to_s
> else
> attribute.remove
> end
> rescue
> attribute.remove
> end
> end
> end
> end
> end
>
> # add a convenience method for computing the xml:base for any given
> Element
> if not REXML::Element.public_instance_methods.include? "xmlbase"
> class REXML::Element
> def xmlbase
> if not attribute('xml:base')
> parent.xmlbase
> elsif parent
> Planet::uri_norm(parent.xmlbase,
> attribute('xml:base').value)
> else
> attribute('xml:base').value || ''
> end
> end
> end
> end
>
> end





Stockhausen was quoted as saying that the events of 9/11 were..

'Lucifer's greatest work of art'

I suspect Madame Sosostris would not have remained so silent had she but
known.

zerosky



















Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
And who is 'mars'? Artio alt.support.schizophrenia 0 12-25-2007 10:56 PM
planet earth ellen alt.support.menopause 0 11-10-2007 07:33 PM
we are not a stable planet K E Z ! alt.support.schizophrenia 5 06-14-2007 10:28 PM
Plonkers arriving from MARS... aperson@Treat-Cancer.nl alt.support.cancer 16 05-30-2007 11:29 PM
OTP: Jupiter, Mercury and Mars Nestle in Predawn Skies Fire Chief alt.support.arthritis 0 01-14-2007 01:35 AM


All times are GMT. The time now is 08:44 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
     
   
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41