classification
Title: Implement os.getlogin on Windows
Type: enhancement Stage: resolved
Components: Extension Modules, Windows Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brian.curtin Nosy List: amaury.forgeotdarc, brian.curtin, giampaolo.rodola, janglin, tim.golden
Priority: normal Keywords: patch

Created on 2010-09-09 03:20 by janglin, last changed 2010-09-23 20:40 by janglin. This issue is now closed.

Files
File name Uploaded Description Edit
os_getlogin.diff janglin, 2010-09-09 03:20 proposed implementation of getlogin
issue9808.diff brian.curtin, 2010-09-09 14:09
issue9808.diff janglin, 2010-09-09 17:20 no env vars in test
issue9808-new.diff janglin, 2010-09-15 02:21
issue9808.diff janglin, 2010-09-18 02:25 no _countof macro
Messages (10)
msg115927 - (view) Author: Jon Anglin (janglin) Date: 2010-09-09 03:20
This is a feature request to implement the os.getlogin function on Windows systems.  This may not be a widely used function, but implementing on Windows will bring Python on Windows one step closer to Python on Unix (like) systems.  The os_getlogin.diff file contains my proposed patch to add this functionality for Windows.
msg115946 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-09-09 14:09
After a quick glance the patch looks alright, just cleaned a few things up in issue9808.diff (moved the #include up with others, removed 'is not None' from tests).

The test skip decorator could also be moved to the LoginTests class level. Is there any reason the variables could legitimately be different from what getlogin reports?
msg115953 - (view) Author: Jon Anglin (janglin) Date: 2010-09-09 15:49
I can't answer that for the 'LOGNAME' environment variable on non-Windows systems, I was just keying off of what the docs claimed. As for Windows, I just came across this article http://support.microsoft.com/kb/273633 that shows we can not rely on this in the test.  

I only put those environment variables in the test because I thought this test was a little weak (what else can we do?)

    user_name = os.getlogin()
    self.assertNotEqual(0, len(user_name))

Even though %USERNAME% == os.getlogin() MOST of the time. It should be removed from the test.
msg115955 - (view) Author: Jon Anglin (janglin) Date: 2010-09-09 17:20
Here is an updated patch with the updated test.  This test does not use either the LOGNAME or USERNAME environment variables.
msg115974 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-09-09 20:51
+1 on the idea in general; I'm away at the moment
and not in a position to review the patch. Hopefully
Brian can review/commit
msg116431 - (view) Author: Jon Anglin (janglin) Date: 2010-09-15 02:21
I went ahead and moved the test skip decorator to the class level as suggested by Brian Curtin, see issue9808-new.diff.
msg116435 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-15 06:59
It's the first time I see the _countof() macro. There is no other usage of it in python codebase. Could you change it for something more easy for non-Windows readers?
msg116748 - (view) Author: Jon Anglin (janglin) Date: 2010-09-18 02:25
The _countof(_x_) macro expands to something like this:

    sizeof(_x_)/sizeof(_x_[0])

This was an attempt by Microsoft to mitigate some buffer overrun issues.  I have gotten in the habit of using it as it is less verbose.  I have uploaded a new issue9808.diff file that removes the _countof macro. I will leave it up to those with commit privileges which version gets checked in. Personally I like it because it clarifies the programmers intent. Why not introduce it to the Python code base?
msg117169 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-23 06:36
The patch looks good.
msg117226 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-09-23 20:04
Committed in r84983. Thanks!
History
Date User Action Args
2010-09-23 20:40:09janglinsetstatus: open -> closed
2010-09-23 20:04:54brian.curtinsetnosy: amaury.forgeotdarc, giampaolo.rodola, tim.golden, brian.curtin, janglin
messages: + msg117226

components: + Extension Modules, - Library (Lib)
resolution: accepted -> fixed
stage: patch review -> resolved
2010-09-23 06:36:23amaury.forgeotdarcsetmessages: + msg117169
2010-09-18 02:25:37janglinsetfiles: + issue9808.diff

messages: + msg116748
2010-09-15 06:59:04amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg116435
2010-09-15 03:03:39brian.curtinsetresolution: accepted
2010-09-15 02:21:51janglinsetfiles: + issue9808-new.diff

messages: + msg116431
2010-09-10 08:28:37giampaolo.rodolasetnosy: + giampaolo.rodola
2010-09-09 20:51:12tim.goldensetmessages: + msg115974
2010-09-09 17:20:42janglinsetfiles: + issue9808.diff

messages: + msg115955
2010-09-09 15:49:35janglinsetmessages: + msg115953
2010-09-09 14:09:09brian.curtinsetfiles: + issue9808.diff
assignee: brian.curtin
messages: + msg115946

stage: patch review
2010-09-09 05:06:42r.david.murraysetnosy: + tim.golden, brian.curtin
2010-09-09 03:20:23janglincreate