aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Brendan Taylor <whateley@gmail.com>2011-02-17 13:09:50 -0700
committerGravatar Brendan Taylor <whateley@gmail.com>2011-02-17 13:09:50 -0700
commit67af28c8d147e35c91ea91b0ddf51680d9feb475 (patch)
tree697e96acc530fefdc6ab6189d95e23127cc127cc /examples
parentb7a47b3f58e6fa05d56577ea6425d353a41ddb86 (diff)
parente3b04d3ae9fb6dfeff5e6099784586b54591814e (diff)
Merge branch 'escaped_events' into experimental
Conflicts: src/util.c
Diffstat (limited to 'examples')
-rw-r--r--examples/data/plugins/bind.py9
-rw-r--r--examples/data/plugins/config.py7
-rw-r--r--examples/data/plugins/cookies.py4
-rw-r--r--examples/data/plugins/downloads.py18
-rw-r--r--examples/data/plugins/on_event.py6
-rwxr-xr-xexamples/data/scripts/uzbl-event-manager22
6 files changed, 44 insertions, 22 deletions
diff --git a/examples/data/plugins/bind.py b/examples/data/plugins/bind.py
index 41f96c5..69fd863 100644
--- a/examples/data/plugins/bind.py
+++ b/examples/data/plugins/bind.py
@@ -164,15 +164,6 @@ def split_glob(glob):
return (mods, glob)
-def unquote(str):
- '''Remove quotation marks around string.'''
-
- if str and str[0] == str[-1] and str[0] in ['"', "'"]:
- str = str[1:-1]
-
- return str
-
-
class Bind(object):
# Class attribute to hold the number of Bind classes created.
diff --git a/examples/data/plugins/config.py b/examples/data/plugins/config.py
index ed2d761..c9bdf67 100644
--- a/examples/data/plugins/config.py
+++ b/examples/data/plugins/config.py
@@ -3,8 +3,6 @@ from types import BooleanType
from UserDict import DictMixin
valid_key = compile('^[A-Za-z0-9_\.]+$').match
-types = {'int': int, 'float': float, 'str': unicode}
-escape = lambda s: unicode(s).replace('\n', '\\n')
class Config(DictMixin):
def __init__(self, uzbl):
@@ -49,7 +47,8 @@ class Config(DictMixin):
value = int(value)
else:
- value = escape(value)
+ value = unicode(value)
+ assert '\n' not in value
if not force and key in self and self[key] == value:
return
@@ -82,6 +81,8 @@ def parse_set_event(uzbl, args):
# plugin init hook
def init(uzbl):
+ global types
+ types = {'int': int, 'float': float, 'str': unquote}
export(uzbl, 'config', Config(uzbl))
connect(uzbl, 'VARIABLE_SET', parse_set_event)
diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py
index 6ee8798..e29ee36 100644
--- a/examples/data/plugins/cookies.py
+++ b/examples/data/plugins/cookies.py
@@ -7,10 +7,6 @@ import os, re
# these are symbolic names for the components of the cookie tuple
symbolic = {'domain': 0, 'path':1, 'name':2, 'value':3, 'scheme':4, 'expires':5}
-_splitquoted = re.compile("( |\\\".*?\\\"|'.*?')")
-def splitquoted(text):
- return [str(p.strip('\'"')) for p in _splitquoted.split(text) if p.strip()]
-
# allows for partial cookies
# ? allow wildcard in key
def match(key, cookie):
diff --git a/examples/data/plugins/downloads.py b/examples/data/plugins/downloads.py
index 7bf32d7..8d796ce 100644
--- a/examples/data/plugins/downloads.py
+++ b/examples/data/plugins/downloads.py
@@ -31,7 +31,11 @@ def update_download_section(uzbl):
if uzbl.config.get('downloads', '') != result:
uzbl.config['downloads'] = result
-def download_started(uzbl, destination_path):
+def download_started(uzbl, args):
+ # parse the arguments
+ args = splitquoted(args)
+ destination_path = args[0]
+
# add to the list of active downloads
global ACTIVE_DOWNLOADS
ACTIVE_DOWNLOADS[destination_path] = (0.0,)
@@ -41,9 +45,9 @@ def download_started(uzbl, destination_path):
def download_progress(uzbl, args):
# parse the arguments
- s = args.rindex(' ')
- destination_path = args[:s]
- progress = float(args[s+1:])
+ args = splitquoted(args)
+ destination_path = args[0]
+ progress = float(args[1])
# update the progress
global ACTIVE_DOWNLOADS
@@ -52,7 +56,11 @@ def download_progress(uzbl, args):
# update the status bar variable
update_download_section(uzbl)
-def download_complete(uzbl, destination_path):
+def download_complete(uzbl, args):
+ # parse the arguments
+ args = splitquoted(args)
+ destination_path = args[0]
+
# remove from the list of active downloads
global ACTIVE_DOWNLOADS
del ACTIVE_DOWNLOADS[destination_path]
diff --git a/examples/data/plugins/on_event.py b/examples/data/plugins/on_event.py
index 5142275..32f09e2 100644
--- a/examples/data/plugins/on_event.py
+++ b/examples/data/plugins/on_event.py
@@ -24,6 +24,10 @@ def event_handler(uzbl, *args, **kargs):
'''This function handles all the events being watched by various
on_event definitions and responds accordingly.'''
+ # Could be connected to a EM internal event that can use anything as args
+ if len(args) == 1 and isinstance(args[0], basestring):
+ args = splitquoted(args[0])
+
events = uzbl.on_events
event = kargs['on_event']
if event not in events:
@@ -80,3 +84,5 @@ def cleanup(uzbl):
del handlers[:]
uzbl.on_events.clear()
+
+# vi: set et ts=4:
diff --git a/examples/data/scripts/uzbl-event-manager b/examples/data/scripts/uzbl-event-manager
index 8ad3af7..cb462c7 100755
--- a/examples/data/scripts/uzbl-event-manager
+++ b/examples/data/scripts/uzbl-event-manager
@@ -34,6 +34,7 @@ import socket
import sys
import time
import weakref
+import re
from collections import defaultdict
from functools import partial
from glob import glob
@@ -169,13 +170,16 @@ class EventHandler(object):
self.callback(uzbl, *args, **kwargs)
+
+
+
class Plugin(object):
'''Plugin module wrapper object.'''
# Special functions exported from the Plugin instance to the
# plugin namespace.
special_functions = ['require', 'export', 'export_dict', 'connect',
- 'connect_dict', 'logger']
+ 'connect_dict', 'logger', 'unquote', 'splitquoted']
def __init__(self, parent, name, path, plugin):
@@ -291,6 +295,20 @@ class Plugin(object):
assert plugin in self.parent.plugins, self.logger.critical(
'plugin %r required by plugin %r' (plugin, self.name))
+ @classmethod
+ def unquote(cls, s):
+ '''Removes quotation marks around strings if any and interprets
+ \\-escape sequences using `string_escape`'''
+ if s and s[0] == s[-1] and s[0] in ['"', "'"]:
+ s = s[1:-1]
+ return s.encode('utf-8').decode('string_escape').decode('utf-8')
+
+ _splitquoted = re.compile("( |\"(?:\\\\.|[^\"])*?\"|'(?:\\\\.|[^'])*?')")
+ @classmethod
+ def splitquoted(cls, text):
+ '''Splits string on whitespace while respecting quotations'''
+ return [cls.unquote(p) for p in cls._splitquoted.split(text) if p.strip()]
+
class Uzbl(object):
def __init__(self, parent, child_socket):
@@ -969,3 +987,5 @@ if __name__ == "__main__":
daemon_actions[action]()
logger.debug('process CPU time: %f' % time.clock())
+
+# vi: set et ts=4: