0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-09-21 19:46:23 -04:00

Python: Give goto_url_hook only one argument, like follow_url_hook.

On Dec 31, 2006, at 11:30am, Kalle Olavi Niemitalo writes:
>src/scripting/python/hooks.c (script_hook_url) calls hooks as
>goto_url_hook(new-url, current-url) and follow_url_hook(new-url).
>It has a comment saying that the current-url parameter exists
>only for compatibility and that the script can instead use
>elinks.current_url().  However, the current-url parameter was
>added in commit 87e27b9b3e and is
>not in ELinks 0.11.2, so any compatibility problems would only
>hit people who have been using 0.12.GIT snapshots.  Can we remove
>the second parameter now before releasing ELinks 0.12pre1?

The decision isn't up to me, but I think this is a good idea. Here's a
patch that would update the documentation and hooks.py, as well as hooks.c.

FYI, if this patch is applied then anyone who's still trying to use a
goto_url_hook that expects a second argument will get a "Browser scripting
error" dialog box that says:

	An error occurred while running a Python script:

	TypeError: goto_url_hook() takes exactly 2 arguments (1 given)
This commit is contained in:
M. Levinson
2006-12-31 10:00:34 -05:00
committed by Kalle Olavi Niemitalo
parent e45f5a8915
commit 26473f72f5
3 changed files with 4 additions and 31 deletions

View File

@@ -46,7 +46,7 @@ dumbprefixes = {
"sd" : "http://www.slashdot.org/"
}
def goto_url_hook(url, current_url):
def goto_url_hook(url):
"""Rewrite a URL that was entered in a "Go to URL" dialog box.
This function should return a URL for ELinks to follow, or None if
@@ -55,8 +55,6 @@ def goto_url_hook(url, current_url):
Arguments:
url -- The URL provided by the user.
current_url -- The URL of the document being viewed, or None if no
document is being viewed.
"""
if url in dumbprefixes:
@@ -136,13 +134,12 @@ class goto_url_in_new_tab:
"""Prompter that opens a given URL in a new tab."""
def __init__(self):
"""Prompt for a URL."""
self.current_location = elinks.current_url()
elinks.input_box("Enter URL", self._callback, title="Go to URL")
def _callback(self, url):
"""Open the given URL in a new tab."""
if 'goto_url_hook' in globals():
# Mimic the standard "Go to URL" dialog by calling goto_url_hook().
url = goto_url_hook(url, self.current_location) or url
url = goto_url_hook(url) or url
if url:
elinks.open(url, new_tab=True)
# The elinks.bind_key() function can be used to create a keystroke binding