~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/bpymodules/BPyRegistry.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# Module BPyRegistry version 0.1
3
3
#   Helper functions to store / restore configuration data.
4
4
# --------------------------------------------------------------------------
5
 
# $Id: BPyRegistry.py,v 1.4 2006/05/15 07:29:28 campbellbarton Exp $
 
5
# $Id: BPyRegistry.py,v 1.5 2007/04/17 14:23:19 campbellbarton Exp $
6
6
#
7
7
# ***** BEGIN GPL LICENSE BLOCK *****
8
8
#
43
43
_EXT = '.cfg' # file extension for saved config data
44
44
 
45
45
# limits:
46
 
MAX_ITEMS_NUM = 60 # max number of keys per dict and itens per list and tuple
47
 
MAX_STR_LEN = 300 # max string length (remember this is just for config data)
 
46
#MAX_ITEMS_NUM = 60 # max number of keys per dict and itens per list and tuple
 
47
#MAX_STR_LEN = 300 # max string length (remember this is just for config data)
48
48
 
49
49
_CFG_DIR = ''
50
50
if Blender.Get('udatadir'):
61
61
 
62
62
_KEYS = [k for k in Registry.Keys() if k[0] != '_']
63
63
 
64
 
_ITEMS_NUM = 0
 
64
# _ITEMS_NUM = 0
65
65
 
66
66
def _sanitize(o):
67
67
        "Check recursively that all objects are valid, set invalid ones to None"
68
68
 
69
 
        global MAX_ITEMS_NUM, MAX_STR_LEN, _ITEMS_NUM
 
69
        # global MAX_ITEMS_NUM, MAX_STR_LEN, _ITEMS_NUM
70
70
 
71
71
        valid_types = [int, float, bool, long, type]
72
72
        valid_checked_types = [str, unicode]
73
73
        # Only very simple types are considered valid for configuration data,
74
 
  # functions, methods and Blender objects (use their names instead) aren't.
 
74
        # functions, methods and Blender objects (use their names instead) aren't.
75
75
 
76
76
        t = type(o)
77
77
 
78
78
        if t == dict:
79
 
                keys = o.keys()
80
 
                len_keys = len(keys)
81
 
                _ITEMS_NUM += len_keys
 
79
                '''
 
80
                _ITEMS_NUM += len(o)
82
81
                if _ITEMS_NUM > MAX_ITEMS_NUM:
83
82
                        return None
84
 
                for k in keys:
85
 
                        o[k] = _sanitize(o[k])
 
83
                '''
 
84
                for k, v in o.iteritems():
 
85
                        o[k] = _sanitize(v)
86
86
        elif t in [list, tuple]:
87
 
                len_seq = len(o)
88
 
                _ITEMS_NUM += len_seq
 
87
                '''
 
88
                _ITEMS_NUM += len(o)
89
89
                if _ITEMS_NUM > MAX_ITEMS_NUM:
90
90
                        return None
91
 
                result = []
92
 
                for i in o: result.append(_sanitize(i))
93
 
                return result
 
91
                '''
 
92
                return [_sanitize(i) for i in o]
94
93
        elif t in valid_types:
95
94
                return o
96
95
        elif t in valid_checked_types:
 
96
                '''
97
97
                if len(o) > MAX_STR_LEN:
98
98
                        o = o[:MAX_STR_LEN]
 
99
                '''
99
100
                return o
100
101
        else: return None
101
102
 
108
109
        
109
110
        if name: l = ['%s = {' % name]
110
111
        else: l = ['{']
111
 
        keys = d.keys()
112
 
        for k in keys:
113
 
                if type(d[k]) == dict:
114
 
                        l.append("'%s': %s" % (k, _dict_to_str(None, d[k])))
 
112
        #keys = d.keys()
 
113
        for k,v in d.iteritems(): # .keys()
 
114
                if type(v) == dict:
 
115
                        l.append("'%s': %s" % (k, _dict_to_str(None, v)))
115
116
                else:
116
 
                        l.append("'%s': %s," % (k, repr(d[k])))
 
117
                        l.append("'%s': %s," % (k, repr(v)))
117
118
        if name: l.append('}')
118
119
        else: l.append('},')
119
120
        return "\n".join(l)
185
186
 
186
187
        if not key:
187
188
                files = \
188
 
                        [bsys.join(_CFG_DIR, f) for f in os.listdir(_CFG_DIR) if f[-4:] == _EXT]
 
189
                        [bsys.join(_CFG_DIR, f) for f in os.listdir(_CFG_DIR) if f.endswith(_EXT)]
189
190
        else:
190
191
                files = []
191
192
                fname = bsys.join(_CFG_DIR, "%s%s" % (key, _EXT))
214
215
 
215
216
        if not key:
216
217
                files = \
217
 
                        [bsys.join(_CFG_DIR, f) for f in os.listdir(_CFG_DIR) if f[-4:] == _EXT]
 
218
                        [bsys.join(_CFG_DIR, f) for f in os.listdir(_CFG_DIR) if f.endswith(_EXT)]
218
219
        else:
219
220
                files = []
220
221
                fname = bsys.join(_CFG_DIR, "%s%s" % (key, _EXT))
243
244
 
244
245
        for mainkey in keys:
245
246
                cfgdict = Registry.GetKey(mainkey).copy()
246
 
                for k in cfgdict.keys():
247
 
                        if not k or k[0] == '_': cfgdict.pop(k)
 
247
                for k in cfgdict: # .keys()
 
248
                        if not k or k[0] == '_':
 
249
                                del cfgdict[k]
248
250
 
249
251
                if not cfgdict: continue
250
252
 
254
256
                if output!='None':
255
257
                        f.write(output)
256
258
                        f.close()
257