Coder Social home page Coder Social logo

ItemsView behavior about multidict HOT 6 CLOSED

aio-libs avatar aio-libs commented on June 28, 2024
ItemsView behavior

from multidict.

Comments (6)

webknjaz avatar webknjaz commented on June 28, 2024

There's MultiDict.getall(key, default=_marker) for pulling all key's values.

Getting a single value by its key should remain the same regardless of how many times you called it.

from multidict.

asvetlov avatar asvetlov commented on June 28, 2024

Also you could iterate over key/value pairs:

In [3]: d = MultiDict([('1', 'foo'), ('2', 'bar'), ('1', 'baz')])

In [4]: for k, v in d.items():
   ...:     print(k, v)
   ...:     
1 foo
2 bar
1 baz

__getitem__ is and alias for getone() which returns a first found value.

from multidict.

asvetlov avatar asvetlov commented on June 28, 2024

Internally multidict is a sequence of key/value pairs.
This is very important: HTTP headers are ordered and sometimes, in very rare cases, it is crucial.
The order should be not changed after serializing headers back.

from multidict.

akhomchenko avatar akhomchenko commented on June 28, 2024

I know about items and getall. Just wanted to clarify that you are aware of this behavior. Thank you a lot.

Offtopic question not to raise another issue:
Is it crucial to have an order not changed only for a specific header or for a sequence of headers also?

I just want to understand if it makes sense trying to implement it on top of regular dicts. With OrderedDict prior python 3.6 and regular dict on 3.6 we can achieve order for values for a specific header, but not for a headers themselves. I've seen #68 (comment)

from multidict.

asvetlov avatar asvetlov commented on June 28, 2024

Yes, I understand.
It's a subtle matter but for example Forwarded and X-Forwarded-* headers might overlap.
I thought about keeping order for values inside a key only.
Moreover early multidict implementations was built in this way.
But later I've switched to linear key-value pairs sequence because people was confused at least.

from multidict.

webknjaz avatar webknjaz commented on June 28, 2024

@gagoman I consider the question answered. Feel free to reopen it if you have any further questions.

from multidict.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.