~ubuntu-branches/ubuntu/gutsy/prewikka/gutsy

« back to all changes in this revision

Viewing changes to prewikka/DataSet.py

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2007-04-11 14:41:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070411144109-2hh7zx3amwd27b4l
Tags: upstream-0.9.10
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004,2005 PreludeIDS Technologies. All Rights Reserved.
 
2
# Author: Nicolas Delon <nicolas.delon@prelude-ids.com>
 
3
#
 
4
# This file is part of the Prewikka program.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2, or (at your option)
 
9
# any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; see the file COPYING.  If not, write to
 
18
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
 
 
21
import sys
 
22
 
 
23
 
 
24
class DataSet(dict):
 
25
    def __setitem__(self, key, value):
 
26
        keys = key.split(".", 1)
 
27
        if len(keys) == 1:
 
28
            dict.__setitem__(self, key, value)
 
29
        else:
 
30
            key1, key2 = keys
 
31
            if not self.has_key(key1):
 
32
                dict.__setitem__(self, key1, DataSet())
 
33
            dict.__getitem__(self, key1)[key2] = value
 
34
    
 
35
    def __getitem__(self, key):
 
36
        try:
 
37
            keys = key.split(".", 1)
 
38
            if len(keys) == 1:
 
39
                return dict.__getitem__(self, key)
 
40
            return dict.__getitem__(self, keys[0])[keys[1]]
 
41
        except KeyError:
 
42
            return ""