seq_to_kv (OpenID::Util)

    # File lib/openid/kvform.rb, line 6
        def Util.seq_to_kv(seq, strict=false)
          # Represent a sequence of pairs of strings as newline-terminated
          # key:value pairs. The pairs are generated in the order given.
          #
          # @param seq: The pairs
          #
          # returns a string representation of the sequence
          err = lambda { |msg|
            msg = "seq_to_kv warning: #{msg}: #{seq.inspect}"
            if strict
              raise ArgumentError, msg
            else
              Util.log(msg)
            end
          }

          lines = []
          seq.each { |k, v|
            if !k.is_a?(String)
              err.call("Converting key to string: #{k.inspect}")
              k = k.to_s
            end

            if !k.index("\n").nil?
              raise ArgumentError, "Invalid input for seq_to_kv: key contains newline: #{k.inspect}"
            end

            if !k.index(":").nil?
              raise ArgumentError, "Invalid input for seq_to_kv: key contains colon: #{k.inspect}"
            end

            if k.strip() != k
              err.call("Key has whitespace at beginning or end: #{k.inspect}")
            end

            if !v.is_a?(String)
              err.call("Converting value to string: #{v.inspect}")
              v = v.to_s
            end

            if !v.index("\n").nil?
              raise ArgumentError, "Invalid input for seq_to_kv: value contains newline: #{v.inspect}"
            end

            if v.strip() != v
              err.call("Value has whitespace at beginning or end: #{v.inspect}")
            end

            lines << k + ":" + v + "\n"
          }

          return lines.join("")
        end