msg99020 - (view) |
Author: Brian Curtin (brian.curtin) *  |
Date: 2010-02-07 21:31 |
While EnumKey and EnumValue directly implement the underlying Windows calls of the same name, they don't feel very Pythonic. The user has to create their own loop and increment a counter to get all of the keys or values, stopping the loop when WindowsError is raised. I created IterKey and IterValue, iterators over RegEnumKeyEx and RegEnumValueEx respectively. This mainly began as playing around with writing Python iterators in C, but has proven to work pretty nicely so I figured I'd put it out there. Patch includes docs and tests. Comments/suggestions welcome and appreciated. |
|
|
msg99049 - (view) |
Author: Tim Golden (tim.golden) *  |
Date: 2010-02-08 16:12 |
Traceback (most recent call last): File "", line 1, in WindowsError: [Error 6] The handle is invalid I suspect that .iterkeys / .itervalues would be more acceptable spellings as those mirror the dict methods. Whether the idea of extending _winreg beyond the absolute basics will fly I'm not sure. I don't often use it, but this would be useful if I did... # On 07/02/2010 21:31, Brian Curtin wrote: > > New submission from Brian Curtin<curtin@acm.org>: > > While EnumKey and EnumValue directly implement the underlying Windows calls of the same name, they don't feel very Pythonic. The user has to create their own loop and increment a counter to get all of the keys or values, stopping the loop when WindowsError is raised. > > I created IterKey and IterValue, iterators over RegEnumKeyEx and RegEnumValueEx respectively. This mainly began as playing around with writing Python iterators in C, but has proven to work pretty nicely so I figured I'd put it out there. > > Patch includes docs and tests. Comments/suggestions welcome and appreciated. > > ---------- > components: Library (Lib), Windows > files: keyvalue_iterators.diff > keywords: needs review, patch, patch > messages: 99020 > nosy: brian.curtin > priority: normal > severity: normal > stage: patch review > status: open > title: Iterators over _winreg EnumKey and EnumValue results > type: feature request > versions: Python 2.7, Python 3.2 > Added file: http://bugs.python.org/file16170/keyvalue_iterators.diff > > _______________________________________ > Python tracker<report@bugs.python.org> > <http://bugs.python.org/issue7877> > _______________________________________ > _______________________________________________ > Python-bugs-list mailing list > Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/mail%40timgolden.me.uk |
|
|
msg99050 - (view) |
Author: Tim Golden (tim.golden) *  |
Date: 2010-02-08 16:16 |
Sorry; the email interface messed that up. The code which triggered the error was: import _winreg list ( _winreg.IterValue ( _winreg.OpenKey (_winreg.HKEY_CURRENT_USER, "Console") ) ) |
|
|
msg99053 - (view) |
Author: Brian Curtin (brian.curtin) *  |
Date: 2010-02-08 16:35 |
Interesting, I'll take a look and see why that's happening. Good point about the names. |
|
|
msg111839 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2010-07-28 20:30 |
@Brian: @Tim: just a gentle nudge in the ribs in case this has slipped under the radar. |
|
|
msg115290 - (view) |
Author: Daniel Stutzbach (stutzbach)  |
Date: 2010-09-01 12:22 |
As most of the code in this patch was copied from EnumValue and EnumKey, it includes bugs from those functions that have since been fixed. I'm thinking of Issue #2810, although there might have been other changes. Instead of duplicating code, it would be better to abstract out some of the common elements so that in the future changes only need to be made in one place. While winreg isn't very Pythonic, I imagine most users write a simple wrapper around the functions to give it a more Pythonic feel. I have been using a home-brewed class that implements the MutableMapping ABC. I just posted it as a recipe on ActiveState: http://code.activestate.com/recipes/577381-collectionsmutablemapping-wrapper-around-_winreg/ |
|
|
msg222708 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2014-07-10 22:23 |
@Zach any interest in this? |
|
|