python / cpython

The Python programming language
https://www.python.org
Other
63.11k stars 30.22k forks source link

Greatly enhanced webbrowser.py #38645

Closed 23aeb1a4-d162-4473-a32d-9adcac86cf2c closed 18 years ago

23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 21 years ago
BPO 754022
Nosy @birkenfeld, @birkenfeld, @rhettinger, @phdru
Files
  • webbrowser: webbrowser wrapper script
  • webbrowser.py.patch: Big webbrowser.py patch
  • webbrowser.diff: New patch by birkenfeld
  • libwebbrowser.tex.patch
  • 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: ```python assignee = 'https://github.com/birkenfeld' closed_at = created_at = labels = ['library'] title = 'Greatly enhanced webbrowser.py' updated_at = user = 'https://github.com/phdru' ``` bugs.python.org fields: ```python activity = actor = 'phd' assignee = 'georg.brandl' closed = True closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'phd' dependencies = [] files = ['5364', '5365', '5366', '5367'] hgrepos = [] issue_num = 754022 keywords = ['patch'] message_count = 32.0 messages = ['43954', '43955', '43956', '43957', '43958', '43959', '43960', '43961', '43962', '43963', '43964', '43965', '43966', '43967', '43968', '43969', '43970', '43971', '43972', '43973', '43974', '43975', '43976', '43977', '43978', '43979', '43980', '43981', '43982', '43983', '43984', '43985'] nosy_count = 7.0 nosy_names = ['nnorwitz', 'georg.brandl', 'georg.brandl', 'rhettinger', 'phd', 'quiver', 'rodsenra'] pr_nums = [] priority = 'normal' resolution = 'accepted' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue754022' versions = ['Python 2.5'] ```

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 21 years ago

    The patch enhances webbrowser.py.

    First, all calls to os.system return result code, and the inverse of the code (it is ok/fail status) passed through all higher-level routines up to top-level call to open(url). This allows to check if a browser was really started.

    Second, the very open() modified so it is now trying to run all registered browsers in order until a browser returns 1.

    Third, the file can be used as a program: webbrowser.py url. Optional parameters -n allows to open the url in a new window.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 20 years ago

    Logged In: YES user_id=4799

    And don't forget to make it executable.

    rhettinger commented 20 years ago

    Logged In: YES user_id=80475

    Too late for Py2.4.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Applied the patch from http://python.org/sf/1077979.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    I've consolidated patches 728278, 754022, 954628, 1166780 into this single patch. Some parts of those patches were applied, some rejected, many things changed. I also added elinks support - currently it is very similar to links.

    275775e0-5c06-463f-bfc8-f11015a5f101 commented 19 years ago

    Logged In: YES user_id=9057

    I have reviewed this patch in 2005-03-23 and recommend it to be applied !

    Oleg have made the comments below to Python-dev, and those must be taken into consideration while applying this patch.

    http://python.org/sf/728278 Close with resolution "partially applied, partially rejected".

    http://python.org/sf/754022 Review and apply! ;)

    http://python.org/sf/1166780 Close with resolution "applied". (Though it was not applied in exactly that form...)

    http://python.org/sf/1077979 Close with resolution "applied long ago".

    http://python.org/sf/1144816 Close with resolution "duplicate of 1077979".

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    I've moved script code to main() function.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    There's no uploaded file! You have to check the checkbox labeled "Check to Upload & Attach File" when you upload a file. In addition, even if you *did check this checkbox, a bug in SourceForge prevents attaching a file when *creating an issue.

    Please try again.

    (This is a SourceForge annoyance that we can do nothing about. :-( )

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Uploading webbrowser wrapper script. Put it into Tools/scripts directory, and add to the end of setup.py.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    I've reworked the patch once more. I moved some common functionality into the UnixBrowser class and added two new features - Elinks launcher class (elinks supports remote commands in a manner very similar to Mozilla) and new-tab functionality for browsers that support tabbed browsing (Mozilla and elinks); a user can now run "webbrowser -t URL" to open the URL a new tab. All classes in the module are now new-style classes (except for the Error class).

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Do not report error if the browser doesn't support tabs - just open the URL in a new window.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Minor bugfix.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Patch for documentation.

    275775e0-5c06-463f-bfc8-f11015a5f101 commented 19 years ago

    Logged In: YES user_id=9057

    I have revised: libwebbrowser.tex.patch and webbrowser.py.patch. They are Ok, I recommend to apply both. Outstanding work.

    However, I would withdraw the webbrowser wrapper script, since the same functionality can be accomplished with: python -m webbrowser http://www.python.org

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Changed _isexecutable() on w32 to test for executable extensions (.exe, bat) . Tested on Linux with Mozilla/links/elinks; on w32 with Mozilla/Opera/Firefox.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Updated documention patch - added a section about webbrowser script and its command-line options and arguments.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Added remote functionality for Opera on Unix.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Added Opera controller to the doc.

    birkenfeld commented 19 years ago

    Logged In: YES user_id=1188172

    I have reviewed this one too, and I really recommend to apply it for 2.5.

    birkenfeld commented 19 years ago

    Logged In: YES user_id=1188172

    Adding new patch (webbrowser.diff), enhanced with other patches and bugfixes here on SF. Also updated the docs with changed/added notes.

    Please review, I'll apply this for 2.5.

    f8df165f-84c5-416f-8de7-998c47672bbf commented 19 years ago

    Logged In: YES user_id=671362

    Let me point out two problems:

    o NameError

        if remote_background:
            cmd += ' &'
    =>
        if self.remote_background:   # add "self."
            cmd += ' &'

    o copy and paste mistake?

    \lineiii{'mozilla'}{\class{Mozilla('mozilla')}}{} \lineiii{'firefox'}{\class{Mozilla('mozilla')}}{} => \lineiii{'mozilla'}{\class{Mozilla('mozilla')}}{} \lineiii{'firefox'}{\class{Mozilla('firefox')}}{}

    birkenfeld commented 19 years ago

    Logged In: YES user_id=1188172

    Ah, thanks. I had already corrected #1, but didn't look closely enough for #2.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    In the main():

        opts, args = getopt.getopt(sys.argv[1:], 'ntd')

    You can remove 'd' as you've dropeed debugging prints.

    Are you going to drop standalone webbrowser script? Is "python -m webbrowser" enough?

    birkenfeld commented 19 years ago

    Logged In: YES user_id=1188172

    No other module that can be used standalone delivers such a script. There's also the question where to install it, etc.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    From setup.py:

              scripts = ['Tools/scripts/pydoc',
    'Tools/scripts/idle',
                         'Lib/smtpd.py']

    See, Python installs 3 scripts into /usr/{local/}bin/ - pydoc, idle and smtpd.py.

    birkenfeld commented 19 years ago

    Logged In: YES user_id=1188172

    Granted, but you will concur that starting a webbrowser isn't something that the command line user normally wants to do via a Python script.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Arguable (especially compared with smtpd.py), but I am not goint to argue. Please apply the patch and let us see what other people think and say. It seems there are enough users...

    f8df165f-84c5-416f-8de7-998c47672bbf commented 19 years ago

    Logged In: YES user_id=671362

    Minor nit.

    11.1.1 Browser Controller Objects from the description of open method::

    If new is true, a new browser window is opened if possible.

    Now "new" can be 0, 1 or 2. This part also needs an update.

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 19 years ago

    Logged In: YES user_id=4799

    Done. New libwebbrowser.tex.patch is about to be uploaded. Thank you!

    birkenfeld commented 19 years ago

    Logged In: YES user_id=1188172

    Committed the patch as Lib/webbrowser.py r1.38, Doc/lib/libwebbrowser.tex r1.11.

    d21744ff-f396-4c71-955e-7dbd2e886779 commented 18 years ago

    Logged In: YES user_id=33168

    There are a couple of bugs reported in 1338995 that appear to be associated with this patch. Could someone take a look and provide updates?

    23aeb1a4-d162-4473-a32d-9adcac86cf2c commented 18 years ago

    Logged In: YES user_id=4799

    One of these two is a bug. But the orther is not. Thank you for spotting.