You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by mx...@apache.org on 2012/05/09 01:23:54 UTC
svn commit: r1335822 - in /tcl/rivet/trunk: ChangeLog doc/rivet.xml
doc/xml/calendar.xml doc/xml/commands.xml doc/xml/entities.xml
rivet/rivet-tcl/http_accept.tcl rivet/rivet-tcl/tclIndex
Author: mxmanghi
Date: Tue May 8 23:23:53 2012
New Revision: 1335822
URL: http://svn.apache.org/viewvc?rev=1335822&view=rev
Log:
* rivet/rivet-tcl/http_accept.tcl: new command ::rivet::http_accept
* doc/xml/commands.xml: new manual entry for ::rivet::http_accept
* doc/rivet.xml: Add new file entities.xml describing package 'RivetEntities'
(only a stub, to be elaborated)
* doc/xml/entities.xml: New manual page for package 'RivetEntities'
Added:
tcl/rivet/trunk/doc/xml/entities.xml
tcl/rivet/trunk/rivet/rivet-tcl/http_accept.tcl (with props)
Modified:
tcl/rivet/trunk/ChangeLog
tcl/rivet/trunk/doc/rivet.xml
tcl/rivet/trunk/doc/xml/calendar.xml
tcl/rivet/trunk/doc/xml/commands.xml
tcl/rivet/trunk/rivet/rivet-tcl/tclIndex
Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1335822&r1=1335821&r2=1335822&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Tue May 8 23:23:53 2012
@@ -1,3 +1,10 @@
+2012-05-09 Massimo Manghi <mx...@apache.org>
+ * rivet/rivet-tcl/http_accept.tcl: new command ::rivet::http_accept
+ * doc/xml/commands.xml: new manual entry for ::rivet::http_accept
+ * doc/rivet.xml: Add new file entities.xml describing package 'RivetEntities'
+ (only a stub, to be elaborated)
+ * doc/xml/entities.xml: New manual page for package 'RivetEntities'
+
2012-05-08 Massimo Manghi <mx...@apache.org>
* src/rivetPkgInit.c: reinstated safe interpreters initialization
* doc/xml/install.xml: corrections and further elaboration of explanation for
Modified: tcl/rivet/trunk/doc/rivet.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/rivet.xml?rev=1335822&r1=1335821&r2=1335822&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/rivet.xml (original)
+++ tcl/rivet/trunk/doc/rivet.xml Tue May 8 23:23:53 2012
@@ -25,6 +25,7 @@
<!ENTITY internals.xml SYSTEM "xml/internals.xml" >
<!ENTITY upgrade.xml SYSTEM "xml/upgrade.xml" >
<!ENTITY request.xml SYSTEM "xml/request.xml" >
+ <!ENTITY entities.xml SYSTEM "xml/entities.xml" >
]>
<!--
@@ -59,6 +60,7 @@
<year>2009</year>
<year>2010</year>
<year>2011</year>
+ <year>2012</year>
<holder>Apache Software Foundation</holder>
</copyright>
<author>
@@ -118,6 +120,9 @@
<!-- Calendar -->
&calendar.xml;
+ <!-- Entities -->
+ &entities.xml;
+
<!-- Help -->
&help.xml;
Modified: tcl/rivet/trunk/doc/xml/calendar.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/calendar.xml?rev=1335822&r1=1335821&r2=1335822&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/calendar.xml (original)
+++ tcl/rivet/trunk/doc/xml/calendar.xml Tue May 8 23:23:53 2012
@@ -20,13 +20,13 @@
<ulink url="http://wiki.tcl.tk">Tcl Wiki</ulink>
</para>
<note>
- The Calendar package uses Tcl <command>dict</command> command to manage markup
- information. Hence either Tcl8.5 or Tcl8.4 with
- <ulink url="http://wiki.tcl.tk/5042">package dict</ulink> are required.
+ The Calendar package uses Tcl <command>dict</command> command to manage markup
+ information. Hence either Tcl8.5 or Tcl8.4 with
+ <ulink url="http://wiki.tcl.tk/5042">package dict</ulink> are required.
</note>
</section>
<refentry id="calendar">
- <refnamediv>
+ <refnamediv>
<refname>Calendar</refname>
<refpurpose>Utility class the builds and prints a calendar table</refpurpose>
</refnamediv>
Modified: tcl/rivet/trunk/doc/xml/commands.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/commands.xml?rev=1335822&r1=1335821&r2=1335822&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/commands.xml (original)
+++ tcl/rivet/trunk/doc/xml/commands.xml Tue May 8 23:23:53 2012
@@ -672,6 +672,63 @@
</refsect1>
</refentry>
+ <refentry id="http_accept">
+ <refnamediv>
+ <refname>http_accept</refname>
+ <refpurpose>Parse HTTP Accept header lines</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>::rivet::http_accept
+ <arg><replaceable>-zeroweight</replaceable></arg>
+ <arg><replaceable>-default</replaceable></arg>
+ <arg><replaceable>-list</replaceable></arg>
+ http_accept_line</command>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ Command for parsing HTTP Accept header lines that tell the
+ server about preferences and/or capabilities of the browser
+ (e.g. content language,media type, etc.). The following
+ script
+ </para>
+ <para>
+ <command>::rivet::http_accept</command> returns a dictionary
+ value in which every content preference is matched to its
+ precedence value
+ </para>
+ <programlisting>load_headers
+set language_precedence [::rivet::http_accept $headers(Accept-Language)]
+foreach lan [dict keys $language_precedence] {
+ puts "$lan -> [dict get $language_precedence $lan]"
+}</programlisting>
+ <para>
+ when run from a browser where 5 languages were chosen
+ would output
+ </para>
+ <programlisting>en-us -> 1
+en -> 0.8
+it -> 0.6
+de-de -> 0.4
+fr-fr -> 0.2</programlisting>
+ <para>
+ The <replaceable>-list</replaceable> switch would suppress
+ the precedence values and the accepted fields
+ are returned listed with decreasing precedence order.
+ </para>
+ <programlisting> puts [::rivet::http_accept -list $headers(Accept-Language)]
+text/html application/xhtml+xml application/xml */*
+ </programlisting>
+ <para>
+
+ </para>
+ </refsect1>
+
+ </refentry>
+
<refentry id="import_keyvalue_pairs">
<refnamediv>
<refname>import_keyvalue_pairs</refname>
@@ -761,7 +818,7 @@ keyvalue_map(args) = 1 2 3 4 5</programl
</refsect1>
</refentry>
- <refentry id="lassign">
+ <!-- refentry id="lassign">
<refnamediv>
<refname>lassign</refname>
<refpurpose>Assign a list of values to a list of variables</refpurpose>
@@ -790,7 +847,7 @@ keyvalue_map(args) = 1 2 3 4 5</programl
3</programlisting>
</para>
</refsect1>
- </refentry>
+ </refentry -->
<refentry id="lempty">
<refnamediv>
Added: tcl/rivet/trunk/doc/xml/entities.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/entities.xml?rev=1335822&view=auto
==============================================================================
--- tcl/rivet/trunk/doc/xml/entities.xml (added)
+++ tcl/rivet/trunk/doc/xml/entities.xml Tue May 8 23:23:53 2012
@@ -0,0 +1,33 @@
+<section id="entities">
+ <title>Entities Package</title>
+ <section>
+ <title>Introduction</title>
+ <para>
+
+ </para>
+
+ </section>
+ <refentry id="entities">
+ <refnamediv>
+ <refname>Entities</refname>
+ <refpurpose></refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command></command>
+ <arg choice="plain"><replaceable></replaceable></arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title></title>
+ <para>
+
+ </para>
+ </refsect1>
+ <refsect1>
+ <variablelist>
+
+ </variablelist>
+ </refsect1>
+ </refentry>
+</section>
Added: tcl/rivet/trunk/rivet/rivet-tcl/http_accept.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/rivet-tcl/http_accept.tcl?rev=1335822&view=auto
==============================================================================
--- tcl/rivet/trunk/rivet/rivet-tcl/http_accept.tcl (added)
+++ tcl/rivet/trunk/rivet/rivet-tcl/http_accept.tcl Tue May 8 23:23:53 2012
@@ -0,0 +1,93 @@
+# -- http_accept
+#
+# function for parsing Accept-* HTTP headers lines.
+#
+# http_accept parses an HTTP header line (as in the case
+# for language or media type negoziation) and returns a dictionary
+# where fields are associated to their precedence
+#
+# Output can be controlled with the following switches
+#
+# -zeroweight: appends also fiels with 0 precedence
+# -default: set default weight value to unset fields
+# -list: returns a list of the fields in the header line
+# in descending order of precedence
+#
+# This function was contributed by Harald Oehlmann
+#
+# $Id$
+#
+
+namespace eval ::rivet {
+
+ proc ::rivet::http_accept {args} {
+ set lqValues {}
+ set lItems {}
+
+ # parameter
+ while { [llength $args] > 1 } {
+ set args [lassign $args argCur]
+ switch -exact -- $argCur {
+ -zeroweight { set fZeroWeight 1 }
+ -list {set oList 1}
+ -default { set fDefault 1 }
+ -- {}
+ default { return -code error "Unknown argument '$argCur'" }
+ }
+ }
+ # loop over comma-separated items
+ foreach itemCur [split [lindex $args 0] ,] {
+ # Find q value as last element separated by ;
+ set qCur 1
+ if {[regexp {^(.*); *q=([^;]*)$} $itemCur match itemCur qString]} {
+ if { 1 == [scan $qString %f qVal] && $qVal >= 0 && $qVal <= 1 } {
+ set qCur $qVal
+ }
+ }
+ set itemCur [string trim $itemCur]
+ if { $itemCur in {"*" "*/*" "*-*"} } {
+ unset -nocomplain fDefault
+ }
+ if { [info exists fZeroWeight] || $qCur > 0 } {
+ lappend lqValues $qCur
+ lappend lItems $itemCur
+ }
+ }
+ # build output dict in decreasing q order
+ set dOut {}
+
+ # we are going to keep a list of keys in order of decresing precedence,
+ # in case the list has to be returned.
+
+ # we return a list if oList was set otherwise a dictionary is build
+ # and returned
+
+ if {[info exists oList]} {
+
+ set sorted_keys {}
+ foreach indexCur [lsort -real -decreasing -indices $lqValues] {
+ lappend sorted_keys [lindex $lItems $indexCur]
+ }
+ return $sorted_keys
+
+ } else {
+ foreach indexCur [lsort -real -decreasing -indices $lqValues] {
+ set qCur [lindex $lqValues $indexCur]
+ if {$qCur == 0 && [info exists fDefault]} {
+ dict set dOut * 0.01
+ unset fDefault
+ }
+ set item_key [lindex $lItems $indexCur]
+
+ dict set dOut $item_key $qCur
+ }
+
+ if { [info exists fDefault] } {
+ dict set dOut * 0.01
+ }
+
+ return $dOut
+ }
+ }
+
+}
Propchange: tcl/rivet/trunk/rivet/rivet-tcl/http_accept.tcl
------------------------------------------------------------------------------
svn:keywords = Id
Modified: tcl/rivet/trunk/rivet/rivet-tcl/tclIndex
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/rivet-tcl/tclIndex?rev=1335822&r1=1335821&r2=1335822&view=diff
==============================================================================
--- tcl/rivet/trunk/rivet/rivet-tcl/tclIndex (original)
+++ tcl/rivet/trunk/rivet/rivet-tcl/tclIndex Tue May 8 23:23:53 2012
@@ -7,7 +7,6 @@
# a script that loads the command.
set auto_index(::rivet::html) [list source [file join $dir html.tcl]]
-set auto_index(::rivet::lassign) [list source [file join $dir lassign.tcl]]
set auto_index(::rivet::random) [list source [file join $dir random.tcl]]
set auto_index(::rivet::rivet_command_document) [list source [file join $dir rivet_command_document.tcl]]
set auto_index(::rivet::putsnnl) [list source [file join $dir putsnnl.tcl]]
@@ -26,3 +25,4 @@ set auto_index(::rivet::wrap) [list sour
set auto_index(::rivet::wrapline) [list source [file join $dir wrap.tcl]]
set auto_index(::rivet::parray_table) [list source [file join $dir parray_table.tcl]]
set auto_index(::rivet::load_cookies) [list source [file join $dir load_cookies.tcl]]
+set auto_index(::rivet::http_accept) [list source [file join $dir http_accept.tcl]]
---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-cvs-help@tcl.apache.org