mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05: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:
parent
e45f5a8915
commit
26473f72f5
@ -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
|
||||
|
@ -44,7 +44,7 @@ FUNCTIONS
|
||||
|
||||
url -- The URL of the link.
|
||||
|
||||
goto_url_hook(url, current_url)
|
||||
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
|
||||
@ -53,8 +53,6 @@ FUNCTIONS
|
||||
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.
|
||||
|
||||
pre_format_html_hook(url, html)
|
||||
Rewrite the body of a document before it's formatted.
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "main/event.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "scripting/python/core.h"
|
||||
#include "session/location.h"
|
||||
#include "session/session.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
@ -64,28 +63,7 @@ script_hook_url(va_list ap, void *data)
|
||||
|
||||
python_ses = ses;
|
||||
|
||||
/*
|
||||
* Historical note: The only reason the goto and follow hooks are
|
||||
* treated differently is to maintain backwards compatibility for
|
||||
* people who already have a goto_url_hook() function in hooks.py
|
||||
* that expects a second argument. If we were starting over from
|
||||
* scratch, we could treat the goto and follow hooks identically and
|
||||
* simply pass @url as the sole argument in both cases; the Python
|
||||
* code for the goto hook no longer needs its @current_url argument
|
||||
* since it could instead determine the current URL by calling the
|
||||
* Python interpreter's elinks.current_url() function.
|
||||
*/
|
||||
if (!strcmp(method, "goto_url_hook")) {
|
||||
unsigned char *current_url = NULL;
|
||||
|
||||
if (python_ses && have_location(python_ses))
|
||||
current_url = struri(cur_loc(ses)->vs.uri);
|
||||
|
||||
result = PyObject_CallMethod(python_hooks, method, "ss", *url,
|
||||
current_url);
|
||||
} else {
|
||||
result = PyObject_CallMethod(python_hooks, method, "s", *url);
|
||||
}
|
||||
result = PyObject_CallMethod(python_hooks, method, "s", *url);
|
||||
|
||||
if (!result || !replace_with_python_string(url, result))
|
||||
alert_python_error();
|
||||
|
Loading…
Reference in New Issue
Block a user