[tor-bugs] #4913 [Stem]: Add stem.util.conf.Config.save()
Tor Bug Tracker & Wiki
torproject-admin at torproject.org
Sun Jan 15 22:35:25 UTC 2012
#4913: Add stem.util.conf.Config.save()
-------------------------+--------------------------------------------------
Reporter: gsathya | Owner: atagar
Type: enhancement | Status: needs_revision
Priority: normal | Milestone:
Component: Stem | Version:
Keywords: | Parent:
Points: | Actualpoints:
-------------------------+--------------------------------------------------
Changes (by atagar):
* status: new => needs_revision
Comment:
> with open(path, 'w') as f:
Ah nice, I've never run across the 'with' keyword before. I'm a little
dubious of its general usefulness since it isn't clear what has the
__enter__ and __exit__ methods (this is one case where a java style
interface tag would be nice) but oh well. Files at least are the textbook
example for using it. :)
Minor note in case you didn't know it: 'with' wasn't introduced until
python 2.5. That's fine though since stem aims for 2.5+ compatibility
(otherwise some of the ternary assignment statements I've been doing will
break too).
Minor thing but please use another variable name, such as 'output_file'.
Single letter variables are evil - they make the code ungrepable. For an
amusing bit on this see 'Single Letter Variable Names' under...
http://thc.org/root/phun/unmaintain.html
I'm fine with using them for single line statements like...
foo = [str(i) for i in range(5)] # becomes the list ["0", "1", "2", "3",
"4"]
or the classic 'i', 'j', 'k' for loop iteration ints, but for other blocks
or anything else longer than a single line please use something longer. :)
> for line in self._raw_contents:
Interesting, I hadn't thought of using _raw_contents for this. This would
generally do the trick but has a few issues...
- if we've used the "set" method to add new config entries then those will
be missed
- if we later allow config values to be unset then this will have issues
- as you mentioned commenting whitespace is lost, which is kinda common
for these key/value configs
While it would be nice if we had a magical function that merged the
current config state with the user created config we loaded, there are too
many land mines to dealing with the arbitrary user input. Lets go with the
first implementation, though with the keys sorted.
Thanks! -Damian
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/4913#comment:2>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list