Re: Problem with an OrderedDict

Bzzzz <[email protected]> Mon, 2 Mar 2015 20:48:28 +0100
Newsgroups gmane.comp.python.pyro
Organization Anyone, anywhere BUT in banana demokratik republik of france
Message-ID <[email protected]>
--MP_/l5Y79Ja_J84vtbPIvJCCWmo
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Mon, 2 Mar 2015 20:05:30 +0100
Irmen de Jong <[email protected]> wrote:

> > So, is it possible to fix this issue and how?
> > 
> 
> Sure, your example code already contains the solution: just pass the
> item list instead of the OrderedDict itself.  ( od.items() )
> 
> And on the client side, reconstruct the OrderedDict directly from the
> item list.

This is working well on a single level, however it also breaks as my
OD is a tree, i.e.:

mydb--schemas--public------+----functions----
          +----common      +----tables----table1
	  +----client              +------table2----rights
                                             +------col1----rights
                                             +------col2----rights
                                                      +-----integer
and so on.


I use it to retrieve all DBAs DBs objects schema, names, perms, etc, 
then I also use it to do the same for a regular user,
send it to he's client,
the client auto-adapt to this OD (ie: hide some parts of itself),
it also use it to send table/view + columns to rpc svr for queries
 (but the column order can be altered),
etc...

However, my first tests used a Storage() (modified dict shamelessy
stolen from Massimo Di Piero's web2py - see attachment) that was
combined with lists. Unfortunately, it returns to a regular dict
when serz/deserz by serpent.
The big advantage is the point notation, eliminating 80% of dicts blurb
(you don't: d['stuff']['thing'] but d.stuff.thing which is much easier
to build/process).
It would be easier if Storage() was preserved by serpent.

At this point, the only option I see is boring (work with many lists and
relying on indices from one list to another to rebuild the
arborescence).

Jean-Yves


 there may be a possible issue to
that: if Pyro4 could correctly serialize 
--MP_/l5Y79Ja_J84vtbPIvJCCWmo
Content-Type: text/x-python
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=storage.py

# -*- coding: utf-8 -*-

# Part of web2py Web Framework (Copyrighted, 2007)
# Developed by Massimo Di Pierro <[email protected]>

# Code shamelessly stollen from Massimo because it is very useful ;-)

# This line tells the interpreter to only import the content of __all__
# while 'from <module> import *'.  Mainly used when we don't want
# other PGMs to automatically import some of this file's classes/methods.
# If we want to explicitely use, lets say XYZ, from this file, it could
# be done by wether explicit call: 'storage.XYZ' or explicit import
# 'from storage import XYZ'.
__all__=['Storage']

class Storage(dict):
    """
    A Storage object is like a dictionary except `obj.foo` can be used
    in addition to `obj['foo']`.

        >>> o = Storage(a=1)
        >>> o.a
        1
        >>> o['a']
        1
        >>> o.a = 2
        >>> o['a']
        2
        >>> del o.a
        >>> o.a
        None
    """

    def __getattr__(self, key): 
        try: return self[key]
        except KeyError, k: return None

    def __setattr__(self, key, value): 
        self[key] = value

    def __delattr__(self, key):
        try: del self[key]
        except KeyError, k: raise AttributeError, k

    def __repr__(self):     
        return '<Storage ' + dict.__repr__(self) + '>'

    def __getstate__(self): 
        return dict(self)

    def __setstate__(self,value):
        for k,v in value.items(): self[k]=v


--MP_/l5Y79Ja_J84vtbPIvJCCWmo
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
--MP_/l5Y79Ja_J84vtbPIvJCCWmo
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Pyro-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyro-core

--MP_/l5Y79Ja_J84vtbPIvJCCWmo--