Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webbrowser.UnixBrowser should use builtins.open #48787

Closed
schmichael mannequin opened this issue Dec 4, 2008 · 9 comments
Closed

webbrowser.UnixBrowser should use builtins.open #48787

schmichael mannequin opened this issue Dec 4, 2008 · 9 comments
Assignees

Comments

@schmichael
Copy link
Mannequin

schmichael mannequin commented Dec 4, 2008

BPO 4537
Nosy @amauryfa, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/amauryfa'
closed_at = <Date 2008-12-05.22:21:11.994>
created_at = <Date 2008-12-04.21:49:09.967>
labels = []
title = 'webbrowser.UnixBrowser should use builtins.open'
updated_at = <Date 2011-04-14.21:49:43.400>
user = 'https://bugs.python.org/schmichael'

bugs.python.org fields:

activity = <Date 2011-04-14.21:49:43.400>
actor = 'ackounts'
assignee = 'amaury.forgeotdarc'
closed = True
closed_date = <Date 2008-12-05.22:21:11.994>
closer = 'amaury.forgeotdarc'
components = ['None']
creation = <Date 2008-12-04.21:49:09.967>
creator = 'schmichael'
dependencies = []
files = []
hgrepos = []
issue_num = 4537
keywords = []
message_count = 9.0
messages = ['76931', '76946', '76957', '76968', '76983', '77083', '133704', '133725', '133775']
nosy_count = 5.0
nosy_names = ['amaury.forgeotdarc', 'gumpy', 'r.david.murray', 'schmichael', 'ackounts']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue4537'
versions = []

@schmichael
Copy link
Mannequin Author

schmichael mannequin commented Dec 4, 2008

On the joyous occasion of Python 3000's release my friends & I were
playing with "import antigravity" and it failed for someone with the
following traceback (anonymized):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../lib/python3.0/antigravity.py", line 4, in <module>
    webbrowser.open("http://xkcd.com/353/")
  File "/.../lib/python3.0/webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
  File "/.../lib/python3.0/webbrowser.py", line 275, in open
    success = self._invoke(args, True, autoraise)
  File "/.../lib/python3.0/webbrowser.py", line 226, in _invoke
    inout = open(os.devnull, "r+")
  File "/.../lib/python3.0/webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
  File "/.../lib/python3.0/webbrowser.py", line 271, in open
    "expected 0, 1, or 2, got %s" % new)
webbrowser.Error: Bad 'new' parameter to open(); expected 0, 1, or 2, got r+

I believe the following patch (against branches/release30-maint) fixes
it cleanly:

Index: Lib/webbrowser.py
===================================================================

--- Lib/webbrowser.py	(revision 67538)
+++ Lib/webbrowser.py	(working copy)
@@ -8,6 +8,7 @@
 import stat
 import subprocess
 import time
+import builtins
 
 __all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"]
 
@@ -223,7 +224,7 @@
         cmdline = [self.name] + raise_opt + args
 
         if remote or self.background:
-            inout = open(os.devnull, "r+")
+            inout = builtins.open(os.devnull, "r+")
         else:
             # for TTY browsers, we need stdin/out
             inout = None

@schmichael schmichael mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir labels Dec 4, 2008
@gumpy
Copy link
Mannequin

gumpy mannequin commented Dec 4, 2008

I'd suggest the same thing that was done on lines 351-352.

Index: Lib/webbrowser.py
===================================================================

--- Lib/webbrowser.py	(revision 67538)
+++ Lib/webbrowser.py	(working copy)
@@ -223,7 +223,8 @@
         cmdline = [self.name] + raise_opt + args
 
         if remote or self.background:
-            inout = open(os.devnull, "r+")
+            import io
+            inout = io.open(os.devnull, "r+")
         else:
             # for TTY browsers, we need stdin/out
             inout = None

@amauryfa amauryfa self-assigned this Dec 5, 2008
@amauryfa
Copy link
Member

amauryfa commented Dec 5, 2008

Fixed in 67539 (py3k) and 67540 (release30-maint)
Thanks for the report!

@amauryfa amauryfa closed this as completed Dec 5, 2008
@schmichael
Copy link
Mannequin Author

schmichael mannequin commented Dec 5, 2008

I believe you forgot to "import io" in UnixBrowser (line 226).

@amauryfa
Copy link
Member

amauryfa commented Dec 5, 2008

sorry**10... probably a wrong copy operation because the Linux machine
where I tested did not have my svn ssh keys.
Someone already corrected this on py3k (r67544, thanks to Fred!), I'll
take care of merging it to the 3.0 branch.

@amauryfa amauryfa reopened this Dec 5, 2008
@amauryfa
Copy link
Member

amauryfa commented Dec 5, 2008

Merged the 2nd fix with r67602.

@amauryfa amauryfa closed this as completed Dec 5, 2008
@ackounts
Copy link
Mannequin

ackounts mannequin commented Apr 14, 2011

This problem is happening in my linux box:

Python 3.2 (r32:88445, Feb 21 2011, 01:55:53) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import antigravity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/antigravity.py", line 5, in <module>
    webbrowser.open("http://xkcd.com/353/")
  File "/usr/lib/python3.2/webbrowser.py", line 62, in open
    if browser.open(url, new, autoraise):
  File "/usr/lib/python3.2/webbrowser.py", line 276, in open
    success = self._invoke(args, True, autoraise)
  File "/usr/lib/python3.2/webbrowser.py", line 239, in _invoke
    stderr=inout, preexec_fn=setsid)
  File "/usr/lib/python3.2/subprocess.py", line 736, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.2/subprocess.py", line 1330, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 9] Bad file descriptor
>>>

@bitdancer
Copy link
Member

Despite the apparent similarity, your issue is something different from what was reported in this issue. Could you please open a new issue for your problem?

@ackounts
Copy link
Mannequin

ackounts mannequin commented Apr 14, 2011

yes, you right, I will create a new issue, thanks.

@ackounts ackounts mannequin removed stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Apr 14, 2011
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants