|
From: Fuzzyman <fuz...@vo...> - 2008-01-22 12:33:48
|
Hello everyone, I am just committing some new changes to ConfigObj. These include some stylistic changes for readability, plus two new methods: * reset - restore a ConfigObj instance to a freshly initialised state * reload - reload the current config file reload is the more important change, with the following notes: * It can only succeed if the config file was originally loaded from the filesystem - i.e. the filename attribute is set to a string. Otherwise a 'ReloadError' (a new exception that is a subclass of IOError) will be raised. * The ConfigObj is first cleared and then reloaded - so any direct references to sections will be orphaned by reload * ConfigObj construction now holds a reference to the configspec in whatever form you originally pass it in. It is reused by 'reload', so if you pass in the configspec as a filename then it will also be reloaded. * reload *doesn't* reset options to their original state (like list_values, unrepr, raise_errors, create_empty etc) - it uses the current options. The exception are attributes like BOM and newlines that are set in the process of parsing the file. Currently both reload and write are sensitive to the current working directory. If you pass in a relative filename and then change the current directory then both reload and write will 'do the wrong thing'. I wonder whether to change this, but there is a backwards compatibility issue (people could easily be relying on the current behaviour). Additionally, istrue, encode and decode have been marked as deprecated for some time. The new release (when it comes) will be version 4.5. It would be nice to remove these - but on the other hand they do little harm just sitting there. Any thoughts? reload is tested, but ConfigObj has so many private members (particularly when dealing with configspecs) that it is hard to be 100% certain that all angles are covered. If anyone is able to test this 'in the field' it would be appreciated. The full changelog from 4.4.0 to current head is: ConfigObj will now guarantee that files will be written terminated with a newline. BUGFIX: Proper quoting of keys, values and list values that contain hashes (when writing). When ``list_values=False``, values containing hashes are triple quoted. Added the ``reload`` method. This reloads a ConfigObj from file. If the filename attribute is not set then a ``ReloadError`` (a new exception inheriting from ``IOError``) is raised. BUGFIX: Files are read in in 'rb' mode, so that non native line endings will be preserved. Minor efficiency improvement in ``unrepr`` mode. Added missing docstrings for overridden dictionary methods. Added the ``reset`` method. This restores a ConfigObj to a freshly created state. (Plus the changes to the validate module discussed previously.) Adding reload didn't require much code, but it meant revisiting a lot of code I haven't touched for quite a while. The code quality isn't bad, but there is too much of it! A lot of the methods are very long and only a fairly large refactoring can sort that out. I did a bit of (necessary) refactoring adding reload and hopefully good changes can be made incrementally. Just the 'restore_defaults' patch to add now (plus a newlines bugfix if Nicola ever sends it) before I declare a release candidate. Test first with doctest is painful! All the best, Michael Foord |