cookie

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ajay

    #1

    cookie

    hi!

    i am printing a simple cookie, but instead of printing
    um=name:blah&ac cess:admin&exp: 2312390.909

    its printing
    um="name:blah&a ccess:admin&exp :2312390.909"

    why the quotes?

    i am creating the cookie as follows:
    data = "user:" + username + "&access:" + access + "&expiry:" + str(expTime)
    cookie_digest = hmac.new(key, data).digest()
    cookie = Cookie.SimpleCo okie()
    cookie_data = data + "&digest:" + cookie_digest
    cookie["um_cookie"] = cookie_data
    cookie["um_cookie"]["path"] = "/~abrar1/hons/interface/admin/"
    print cookie

    thanks
    cheers



    ----------------------------------------------------------------
    This message was sent using IMP, the Internet Messaging Program.
  • John J. Lee

    #2
    Re: cookie

    Ajay <abra9823@mail. usyd.edu.au> writes:
    [color=blue]
    > hi!
    >
    > i am printing a simple cookie, but instead of printing
    > um=name:blah&ac cess:admin&exp: 2312390.909
    >
    > its printing
    > um="name:blah&a ccess:admin&exp :2312390.909"
    >
    > why the quotes?[/color]

    Why not?

    I don't see how they'd cause any harm.


    John

    Comment

    • Ajay

      #3
      Re: cookie

      they dont cause any harm, except for a an extra statement removing those
      quotes when i read the cookie, parse it and authenticate the session.
      the question is - is that normal cookie behaviour?
      cookie["test"]="blah"
      print cookie

      prints test=blah and not test="blah"
      so why the quotes when i do the same thing, but use a variable instead of a
      string literal?

      cheers


      Quoting "John J. Lee" <jjl@pobox.com> :
      [color=blue]
      > Ajay <abra9823@mail. usyd.edu.au> writes:
      >[color=green]
      > > hi!
      > >
      > > i am printing a simple cookie, but instead of printing
      > > um=name:blah&ac cess:admin&exp: 2312390.909
      > >
      > > its printing
      > > um="name:blah&a ccess:admin&exp :2312390.909"
      > >
      > > why the quotes?[/color]
      >
      > Why not?
      >
      > I don't see how they'd cause any harm.
      >
      >
      > John
      > --
      > http://mail.python.org/mailman/listinfo/python-list
      >[/color]


      ----------------------------------------------------------------
      This message was sent using IMP, the Internet Messaging Program.

      Comment

      • John J. Lee

        #4
        Re: cookie

        Ajay <abra9823@mail. usyd.edu.au> writes:[color=blue]
        > Quoting "John J. Lee" <jjl@pobox.com> :[color=green]
        > > Ajay <abra9823@mail. usyd.edu.au> writes:[/color][/color]
        [...][color=blue][color=green][color=darkred]
        > > > i am printing a simple cookie, but instead of printing
        > > > um=name:blah&ac cess:admin&exp: 2312390.909
        > > >
        > > > its printing
        > > > um="name:blah&a ccess:admin&exp :2312390.909"
        > > >
        > > > why the quotes?[/color]
        > >
        > > Why not?
        > >
        > > I don't see how they'd cause any harm.
        > >[/color]
        > they dont cause any harm, except for a an extra statement removing those
        > quotes when i read the cookie, parse it and authenticate the session.
        > the question is - is that normal cookie behaviour?
        > cookie["test"]="blah"
        > print cookie
        >
        > prints test=blah and not test="blah"
        > so why the quotes when i do the same thing, but use a variable instead of a
        > string literal?[/color]

        You've lost me, but on the basis of a very quick test, the Cookie
        module preserves quotes across the parse->output cycle:
        [color=blue][color=green][color=darkred]
        >>> import Cookie
        >>> c = Cookie.SimpleCo okie()
        >>> c.load('foo=bar ')
        >>> print c[/color][/color][/color]
        Set-Cookie: foo=bar;[color=blue][color=green][color=darkred]
        >>> c.load('foo="ba r"')
        >>> print c[/color][/color][/color]
        Set-Cookie: foo="bar";[color=blue][color=green][color=darkred]
        >>>[/color][/color][/color]

        That seems sensible behaviour to me, since quotes around cookie values
        are significant for Netscape cookies (ie. regular, vanilla, internet
        cookies).

        I can categorically state that using a variable name instead of a
        string literal will make no difference whatsoever. I think you're
        actually confused about Python syntax rather than the workings of the
        Cookie module. Try reading the Python language tutorial at
        www.python.org.


        John

        Comment

        • Ajay

          #5
          Re: cookie


          Quoting "John J. Lee" <jjl@pobox.com> :
          [color=blue]
          > Ajay <abra9823@mail. usyd.edu.au> writes:[color=green]
          > > Quoting "John J. Lee" <jjl@pobox.com> :[color=darkred]
          > > > Ajay <abra9823@mail. usyd.edu.au> writes:[/color][/color]
          > [...][color=green][color=darkred]
          > > > > i am printing a simple cookie, but instead of printing
          > > > > um=name:blah&ac cess:admin&exp: 2312390.909
          > > > >
          > > > > its printing
          > > > > um="name:blah&a ccess:admin&exp :2312390.909"
          > > > >
          > > > > why the quotes?
          > > >
          > > > Why not?
          > > >
          > > > I don't see how they'd cause any harm.
          > > >[/color]
          > > they dont cause any harm, except for a an extra statement removing[/color]
          > those[color=green]
          > > quotes when i read the cookie, parse it and authenticate the session.
          > > the question is - is that normal cookie behaviour?
          > > cookie["test"]="blah"
          > > print cookie
          > >
          > > prints test=blah and not test="blah"
          > > so why the quotes when i do the same thing, but use a variable instead[/color]
          > of a[color=green]
          > > string literal?[/color]
          >
          > You've lost me, but on the basis of a very quick test, the Cookie
          > module preserves quotes across the parse->output cycle:
          >[color=green][color=darkred]
          > >>> import Cookie
          > >>> c = Cookie.SimpleCo okie()
          > >>> c.load('foo=bar ')
          > >>> print c[/color][/color]
          > Set-Cookie: foo=bar;[color=green][color=darkred]
          > >>> c.load('foo="ba r"')
          > >>> print c[/color][/color]
          > Set-Cookie: foo="bar";[color=green][color=darkred]
          > >>>[/color][/color]
          >
          > That seems sensible behaviour to me, since quotes around cookie values
          > are significant for Netscape cookies (ie. regular, vanilla, internet
          > cookies).
          >
          > I can categorically state that using a variable name instead of a
          > string literal will make no difference whatsoever.[/color]

          i believe you. i didn't think it would make a difference. and i agree that
          the Cookie module preserves quotes across the parse->output cycle
          my question is[color=blue][color=green][color=darkred]
          >>> import Cookie
          >>> c = Cookie.SimpleCo okie()
          >>> c["test"]= "blah"
          >>> print c[/color][/color][/color]
          Set-Cookie: test=blah;[color=blue][color=green][color=darkred]
          >>> c["test"] = "blah" + "testing"
          >>> print c[/color][/color][/color]
          Set-Cookie: test=blahtestin g;[color=blue][color=green][color=darkred]
          >>> str = "testing blah"
          >>> c["test"] = str
          >>> print c[/color][/color][/color]
          Set-Cookie: test="testing blah";

          why does the final print statement have the quotes. Note i haven't put
          str='"testing blah"'. if i had done that i would understand the quotes
          there.
          [color=blue]
          >I think you're
          > actually confused about Python syntax rather than the workings of the
          > Cookie module. Try reading the Python language tutorial at
          > www.python.org.
          >[/color]
          yes i should probably read that :)
          it doesn't though mention anything about the above behaviour

          cheers
          [color=blue]
          >
          > John
          > --
          > http://mail.python.org/mailman/listinfo/python-list
          >[/color]


          ----------------------------------------------------------------
          This message was sent using IMP, the Internet Messaging Program.

          Comment

          • John J. Lee

            #6
            Re: cookie

            Ajay <abra9823@mail. usyd.edu.au> writes:
            [...][color=blue]
            > i believe you. i didn't think it would make a difference. and i agree that
            > the Cookie module preserves quotes across the parse->output cycle
            > my question is[color=green][color=darkred]
            > >>> import Cookie
            > >>> c = Cookie.SimpleCo okie()
            > >>> c["test"]= "blah"
            > >>> print c[/color][/color]
            > Set-Cookie: test=blah;[color=green][color=darkred]
            > >>> c["test"] = "blah" + "testing"
            > >>> print c[/color][/color]
            > Set-Cookie: test=blahtestin g;[color=green][color=darkred]
            > >>> str = "testing blah"
            > >>> c["test"] = str
            > >>> print c[/color][/color]
            > Set-Cookie: test="testing blah";
            >
            > why does the final print statement have the quotes. Note i haven't put
            > str='"testing blah"'. if i had done that i would understand the quotes
            > there.[/color]

            Does the following help?

            Python 2.4a2 (#5, Aug 5 2004, 22:07:01)
            [GCC 2.95.4 20011002 (Debian prerelease)] on linux2
            Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
            >>> import Cookie
            >>> c = Cookie.SimpleCo okie()
            >>> c["test"] = "testingbla h"
            >>> print c[/color][/color][/color]
            Set-Cookie: test=testingbla h;[color=blue][color=green][color=darkred]
            >>> c["test"] = "testing blah"
            >>> print c[/color][/color][/color]
            Set-Cookie: test="testing blah";[color=blue][color=green][color=darkred]
            >>>[/color][/color][/color]


            John

            Comment

            • Marc 'BlackJack' Rintsch

              #7
              Re: cookie

              In <mailman.2553.1 093667904.5135. python-list@python.org >, Ajay wrote:
              [color=blue]
              > my question is[color=green][color=darkred]
              >>>> import Cookie
              >>>> c = Cookie.SimpleCo okie()
              >>>> c["test"]= "blah"
              >>>> print c[/color][/color]
              > Set-Cookie: test=blah;[color=green][color=darkred]
              >>>> c["test"] = "blah" + "testing"
              >>>> print c[/color][/color]
              > Set-Cookie: test=blahtestin g;[color=green][color=darkred]
              >>>> str = "testing blah"
              >>>> c["test"] = str
              >>>> print c[/color][/color]
              > Set-Cookie: test="testing blah";
              >
              > why does the final print statement have the quotes. Note i haven't put
              > str='"testing blah"'. if i had done that i would understand the quotes
              > there.[/color]

              It's no difference if you bind the string to a name or assign it directly,
              it's the contents of the string:
              [color=blue][color=green][color=darkred]
              >>> import Cookie
              >>> c = Cookie.SimpleCo okie()
              >>> c["test"] = "spaceless"
              >>> print c[/color][/color][/color]
              Set-Cookie: test=spaceless;[color=blue][color=green][color=darkred]
              >>> c["test"] = "not spaceless"
              >>> print c[/color][/color][/color]
              Set-Cookie: test="not spaceless";

              Ciao,
              Marc 'BlackJack' Rintsch

              Comment

              Working...