当前位置: 首页>>代码示例>>Python>>正文


Python datastructures.OrderedMultiDict类代码示例

本文整理汇总了Python中werkzeug.datastructures.OrderedMultiDict的典型用法代码示例。如果您正苦于以下问题:Python OrderedMultiDict类的具体用法?Python OrderedMultiDict怎么用?Python OrderedMultiDict使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OrderedMultiDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multidict_encoding

def test_multidict_encoding():
    d = OrderedMultiDict()
    d.add("2013-10-10T23:26:05.657975+0000", "2013-10-10T23:26:05.657975+0000")
    assert (
        urls.url_encode(d)
        == "2013-10-10T23%3A26%3A05.657975%2B0000=2013-10-10T23%3A26%3A05.657975%2B0000"
    )
开发者ID:pallets,项目名称:werkzeug,代码行数:7,代码来源:test_urls.py

示例2: get_with_data

    def get_with_data(*args, **kwargs):
        filters = kwargs.pop('filters', None)
        limit = kwargs.pop('limit', None)
        offset = kwargs.pop('offset', 0)
        order = kwargs.pop('order', Reservation.start_dt)
        limit_per_room = kwargs.pop('limit_per_room', False)
        occurs_on = kwargs.pop('occurs_on')
        if kwargs:
            raise ValueError('Unexpected kwargs: {}'.format(kwargs))

        query = Reservation.query.options(joinedload(Reservation.room))
        if filters:
            query = query.filter(*filters)
        if occurs_on:
            query = query.filter(
                Reservation.id.in_(db.session.query(ReservationOccurrence.reservation_id)
                                   .filter(ReservationOccurrence.date.in_(occurs_on),
                                           ReservationOccurrence.is_valid))
            )
        if limit_per_room and (limit or offset):
            query = limit_groups(query, Reservation, Reservation.room_id, order, limit, offset)

        query = query.order_by(order, Reservation.created_dt)

        if not limit_per_room:
            if limit:
                query = query.limit(limit)
            if offset:
                query = query.offset(offset)

        result = OrderedDict((r.id, {'reservation': r}) for r in query)

        if 'vc_equipment' in args:
            vc_id_subquery = db.session.query(EquipmentType.id) \
                .correlate(Reservation) \
                .filter_by(name='Video conference') \
                .join(RoomEquipmentAssociation) \
                .filter(RoomEquipmentAssociation.c.room_id == Reservation.room_id) \
                .as_scalar()

            # noinspection PyTypeChecker
            vc_equipment_data = dict(db.session.query(Reservation.id, static_array.array_agg(EquipmentType.name))
                                     .join(ReservationEquipmentAssociation, EquipmentType)
                                     .filter(Reservation.id.in_(result.iterkeys()))
                                     .filter(EquipmentType.parent_id == vc_id_subquery)
                                     .group_by(Reservation.id))

            for id_, data in result.iteritems():
                data['vc_equipment'] = vc_equipment_data.get(id_, ())

        if 'occurrences' in args:
            occurrence_data = OrderedMultiDict(db.session.query(ReservationOccurrence.reservation_id,
                                                                ReservationOccurrence)
                                               .filter(ReservationOccurrence.reservation_id.in_(result.iterkeys()))
                                               .order_by(ReservationOccurrence.start_dt))
            for id_, data in result.iteritems():
                data['occurrences'] = occurrence_data.getlist(id_)

        return result.values()
开发者ID:NIIF,项目名称:indico,代码行数:59,代码来源:reservations.py

示例3: __get_query_args

 def __get_query_args(req):
     d = OrderedMultiDict()
     if len(req.query_string) > 0:
         arg_list = req.query_string.split('&')
         arg_list = map(unquote, arg_list)
         for arg in arg_list:
             spl = arg.split('=', 1)
             spl.append(None)
             d.add(spl[0], spl[1])
     return d
开发者ID:Mattias-,项目名称:xor,代码行数:10,代码来源:xor.py

示例4: __get_post_args

 def __get_post_args(req):
     d = OrderedMultiDict()
     if req.method == 'POST':
         content = req.environ['wsgi.input']
         post_data = content.read(req.content_length)
         arg_list = post_data.split('&')
         arg_list = map(unquote, arg_list)
         for arg in arg_list:
             spl = arg.split('=', 1)
             spl.append(None)
             d.add(spl[0], spl[1])
     return d
开发者ID:Mattias-,项目名称:xor,代码行数:12,代码来源:xor.py

示例5: test_ordered_multidict_encoding

 def test_ordered_multidict_encoding(self):
     d = OrderedMultiDict()
     d.add("foo", 1)
     d.add("foo", 2)
     d.add("foo", 3)
     d.add("bar", 0)
     d.add("foo", 4)
     assert urls.url_encode(d) == "foo=1&foo=2&foo=3&bar=0&foo=4"
开发者ID:FakeSherlock,项目名称:Report,代码行数:8,代码来源:urls.py

示例6: test_ordered_multidict_encoding

def test_ordered_multidict_encoding():
    d = OrderedMultiDict()
    d.add('foo', 1)
    d.add('foo', 2)
    d.add('foo', 3)
    d.add('bar', 0)
    d.add('foo', 4)
    assert urls.url_encode(d) == 'foo=1&foo=2&foo=3&bar=0&foo=4'
开发者ID:char101,项目名称:werkzeug,代码行数:8,代码来源:test_urls.py

示例7: test_ordered_multidict_encoding

 def test_ordered_multidict_encoding(self):
     d = OrderedMultiDict()
     d.add('foo', 1)
     d.add('foo', 2)
     d.add('foo', 3)
     d.add('bar', 0)
     d.add('foo', 4)
     self.assert_equal(urls.url_encode(d), 'foo=1&foo=2&foo=3&bar=0&foo=4')
开发者ID:ArslanRafique,项目名称:werkzeug,代码行数:8,代码来源:urls.py

示例8: __init__

 def __init__(self, parsed):
     parsed = helpers.ensure_soup(parsed)
     if parsed.name != 'form':
         parsed = parsed.find('form')
     self.parsed = parsed
     self.action = self.parsed.get('action')
     self.method = self.parsed.get('method', 'get')
     self.fields = OrderedMultiDict()
     for field in _parse_fields(self.parsed):
         self.add_field(field)
开发者ID:M157q,项目名称:robobrowser,代码行数:10,代码来源:form.py

示例9: test_ordered_multidict_encoding

def test_ordered_multidict_encoding():
    """"Make sure URLs are properly encoded from OrderedMultiDicts"""
    d = OrderedMultiDict()
    d.add('foo', 1)
    d.add('foo', 2)
    d.add('foo', 3)
    d.add('bar', 0)
    d.add('foo', 4)
    assert url_encode(d) == 'foo=1&foo=2&foo=3&bar=0&foo=4'
开发者ID:Fak3,项目名称:werkzeug,代码行数:9,代码来源:test_urls.py

示例10: get_with_data

    def get_with_data(*args, **kwargs):
        filters = kwargs.pop('filters', None)
        limit = kwargs.pop('limit', None)
        offset = kwargs.pop('offset', 0)
        order = kwargs.pop('order', Reservation.start_dt)
        limit_per_room = kwargs.pop('limit_per_room', False)
        occurs_on = kwargs.pop('occurs_on')
        if kwargs:
            raise ValueError('Unexpected kwargs: {}'.format(kwargs))

        query = Reservation.query.options(joinedload(Reservation.room))
        if filters:
            query = query.filter(*filters)
        if occurs_on:
            query = query.filter(
                Reservation.id.in_(db.session.query(ReservationOccurrence.reservation_id)
                                   .filter(ReservationOccurrence.date.in_(occurs_on),
                                           ReservationOccurrence.is_valid))
            )
        if limit_per_room and (limit or offset):
            query = limit_groups(query, Reservation, Reservation.room_id, order, limit, offset)

        query = query.order_by(order, Reservation.created_dt)

        if not limit_per_room:
            if limit:
                query = query.limit(limit)
            if offset:
                query = query.offset(offset)

        result = OrderedDict((r.id, {'reservation': r}) for r in query)

        if 'occurrences' in args:
            occurrence_data = OrderedMultiDict(db.session.query(ReservationOccurrence.reservation_id,
                                                                ReservationOccurrence)
                                               .filter(ReservationOccurrence.reservation_id.in_(result.iterkeys()))
                                               .order_by(ReservationOccurrence.start_dt))
            for id_, data in result.iteritems():
                data['occurrences'] = occurrence_data.getlist(id_)

        return result.values()
开发者ID:mic4ael,项目名称:indico,代码行数:41,代码来源:reservations.py

示例11: test_multidict_pickle

def test_multidict_pickle():
    """MultiDict types are pickle-able"""
    for protocol in xrange(pickle.HIGHEST_PROTOCOL + 1):
        print 'pickling protocol', protocol
        d = MultiDict()
        d.setlist('foo', [1, 2, 3, 4])
        d.setlist('bar', 'foo bar baz'.split())
        s = pickle.dumps(d, protocol)
        ud = pickle.loads(s)
        assert type(ud) is type(d)
        assert ud == d
        assert pickle.loads(s.replace('werkzeug.datastructures', 'werkzeug')) == d
        ud['newkey'] = 'bla'
        assert ud != d

        d2 = OrderedMultiDict(d)
        d2.add('foo', 5)
        s = pickle.dumps(d2, protocol)
        ud = pickle.loads(s)
        assert type(ud) is type(d2)
        assert ud == d2
        ud['newkey'] = 'bla'
        print ud
        print d2
        assert ud != d2

        im = ImmutableMultiDict(d)
        assert im == d
        s = pickle.dumps(im, protocol)
        ud = pickle.loads(s)
        assert ud == im
        assert type(ud) is type(im)

        c = CombinedMultiDict([ud, im])
        cc = pickle.loads(pickle.dumps(c, protocol))
        assert c == cc
        assert type(c) is type(cc)
开发者ID:d1on,项目名称:werkzeug,代码行数:37,代码来源:test_datastructures.py

示例12: test_multidict_encoding

 def test_multidict_encoding(self):
     d = OrderedMultiDict()
     d.add('2013-10-10T23:26:05.657975+0000', '2013-10-10T23:26:05.657975+0000')
     self.assert_equal(urls.url_encode(d), '2013-10-10T23%3A26%3A05.657975%2B0000=2013-10-10T23%3A26%3A05.657975%2B0000')
开发者ID:ArslanRafique,项目名称:werkzeug,代码行数:4,代码来源:urls.py

示例13: test_ordered_multidict

def test_ordered_multidict():
    """Test the OrderedMultiDict"""
    d = OrderedMultiDict()
    assert not d
    d.add('foo', 'bar')
    assert len(d) == 1
    d.add('foo', 'baz')
    assert len(d) == 1
    assert d.items() == [('foo', 'bar')]
    assert list(d) == ['foo']
    assert d.items(multi=True) == [('foo', 'bar'),
                                   ('foo', 'baz')]
    del d['foo']
    assert not d
    assert len(d) == 0
    assert list(d) == []

    d.update([('foo', 1), ('foo', 2), ('bar', 42)])
    d.add('foo', 3)
    assert d.getlist('foo') == [1, 2, 3]
    assert d.getlist('bar') == [42]
    assert d.items() == [('foo', 1), ('bar', 42)]
    assert d.keys() == list(d) == list(d.iterkeys()) == ['foo', 'bar']
    assert d.items(multi=True) == [('foo', 1), ('foo', 2),
                                   ('bar', 42), ('foo', 3)]
    assert len(d) == 2

    assert d.pop('foo') == 1
    assert d.pop('blafasel', None) is None
    assert d.pop('blafasel', 42) == 42
    assert len(d) == 1
    assert d.poplist('bar') == [42]
    assert not d

    d.get('missingkey') is None

    d.add('foo', 42)
    d.add('foo', 23)
    d.add('bar', 2)
    d.add('foo', 42)
    assert d == MultiDict(d)
    id = ImmutableOrderedMultiDict(d)
    assert d == id
    d.add('foo', 2)
    assert d != id

    d.update({'blah': [1, 2, 3]})
    assert d['blah'] == 1
    assert d.getlist('blah') == [1, 2, 3]

    # setlist works
    d = OrderedMultiDict()
    d['foo'] = 42
    d.setlist('foo', [1, 2])
    assert d.getlist('foo') == [1, 2]

    assert_raises(OrderedMultiDict.KeyError, d.pop, 'missing')
    assert_raises(OrderedMultiDict.KeyError, d.__getitem__, 'missing')

    # popping
    d = OrderedMultiDict()
    d.add('foo', 23)
    d.add('foo', 42)
    d.add('foo', 1)
    assert d.popitem() == ('foo', 23)
    assert_raises(OrderedMultiDict.KeyError, d.popitem)
    assert not d

    d.add('foo', 23)
    d.add('foo', 42)
    d.add('foo', 1)
    assert d.popitemlist() == ('foo', [23, 42, 1])
    assert_raises(OrderedMultiDict.KeyError, d.popitemlist)
开发者ID:d1on,项目名称:werkzeug,代码行数:73,代码来源:test_datastructures.py

示例14: test_multidict_encode_decode_text

def test_multidict_encode_decode_text(t1, t2):
    d = OrderedMultiDict()
    d.add(t1, t2)
    assert d == urls.url_decode(urls.url_encode(d))
开发者ID:TomCorwine,项目名称:werkzeug,代码行数:4,代码来源:test_urls.py

示例15: StatementHistory

class StatementHistory(object):

    """Keeps a history of SQL statements with execution time and offers some pretty printing options.
    No precautions for thread safety.
    """

    def __init__(self):
        self._reset()

    def _reset(self):
        self._statements = OrderedMultiDict()
        self.last_statement = None
        self.last_duration = None
        self.last_timestamp = None

    def append(self, stmt, timestamp, duration, notices):
        self.last_statement = stmt
        self.last_timestamp = timestamp
        self.last_duration = duration
        self.last_notices = notices
        self._statements.add(stmt, (timestamp, duration, notices))

    def clear(self):
        # clear() does not work on OrderedMultiDict, bug in werkzeug?
        self._reset()

    @property
    def statements(self):
        return self._statements.keys()

    @property
    def statements_with_all_infos(self):
        return iteritems(self._statements)
    
    @property
    def statements_with_time(self):
        return ((k, v[0]) for k, v in iteritems(self._statements))

    def format_statement(self, stmt, highlight=True, time=0, duration=0, pygments_style=DEFAULT_PYGMENTS_STYLE, formatter_cls=None):
        show_time = time and duration
        highlight_format_stmt = _make_statement_formatter(show_time, highlight, pygments_style, formatter_cls)
        return highlight_format_stmt(stmt)

    def print_last_statement(self, show_time=True, highlight=True, pygments_style=DEFAULT_PYGMENTS_STYLE):
        if self.last_statement is None:
            print("history is empty")
            return

        highlight_format_stmt = _make_statement_formatter(show_time, highlight, pygments_style)
        print()
        print(highlight_format_stmt(self.last_statement, self.last_timestamp, self.last_duration))

    def print_statements(self, show_time=True, highlight=True, pygments_style=DEFAULT_PYGMENTS_STYLE):
        if self.last_statement is None:
            print("history is empty")
            return

        highlight_format_stmt = _make_statement_formatter(show_time, highlight, pygments_style)
        print()

        for stmt, (timestamp, duration) in self._statements.items(multi=True):
            print(highlight_format_stmt(stmt, timestamp, duration))
开发者ID:mediatum,项目名称:mediatum,代码行数:62,代码来源:psycopg2_debug.py


注:本文中的werkzeug.datastructures.OrderedMultiDict类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。