def add_cookie(self, cookie): cookie = splitquoted(cookie) if self.secure: if match_list(self.secure, cookie): make_secure = {'http': 'https', 'httpOnly': 'httpsOnly'} if cookie[4] in make_secure: self.uzbl.send('cookie delete %s' % cookie.safe_raw()) new_cookie = list(cookie) new_cookie[4] = make_secure[cookie[4]] new_cookie = tuple(new_cookie) self.uzbl.send('cookie add %s' % new_cookie.safe_raw()) return if self.accept_cookie(cookie): for u in self.get_recipents(): u.send('cookie add %s' % cookie.safe_raw()) self.get_store(self.expires_with_session(cookie)).add_cookie( cookie.raw(), cookie) else: self.logger.debug('cookie %r is blacklisted', cookie) self.uzbl.send('cookie delete %s' % cookie.safe_raw())
def parse_set_event(self, args): '''Parse `VARIABLE_SET <var> <type> <value>` event and load the (key, value) pair into the `uzbl.config` dict.''' args = splitquoted(args) if len(args) == 2: key, type, raw_value = args[0], args[1], '' elif len(args) == 3: key, type, raw_value = args else: raise Exception('Invalid number of arguments') assert valid_key(key) assert type in types new_value = types[type](raw_value) old_value = self.data.get(key, None) # Update new value. self.data[key] = new_value if old_value != new_value: self.uzbl.event('CONFIG_CHANGED', key, new_value) # Cleanup null config values. if type == 'str' and not new_value: del self.data[key]
def parse_mode_bind(self, args): '''Parser for the MODE_BIND event. Example events: MODE_BIND <mode> <bind> = <command> MODE_BIND command o<location:>_ = uri %s MODE_BIND insert,command <BackSpace> = ... MODE_BIND global ... = ... MODE_BIND global,-insert ... = ... ''' args = splitquoted(args) if len(args) < 2: raise ArgumentError('missing mode or bind section: %r' % args.raw()) modes = args[0].split(',') for i, g in enumerate(args[1:]): if g == '=': glob = args.raw(1, i) command = args.raw(i+2) break else: raise ArgumentError('missing delimiter in bind section: %r' % args.raw()) self.mode_bind(modes, glob, command)
def parse_mode_bind(self, args): '''Parser for the MODE_BIND event. Example events: MODE_BIND <mode> <bind> = <command> MODE_BIND command o<location:>_ = uri %s MODE_BIND insert,command <BackSpace> = ... MODE_BIND global ... = ... MODE_BIND global,-insert ... = ... ''' args = splitquoted(args) if len(args) < 2: raise ArgumentError('missing mode or bind section: %r' % args.raw()) modes = args[0].split(',') for i, g in enumerate(args[1:]): if g == '=': glob = args.raw(1, i) command = args.raw(i + 2) break else: raise ArgumentError('missing delimiter in bind section: %r' % args.raw()) self.mode_bind(modes, glob, command)
def add_cookie(self, cookie): cookie = splitquoted(cookie) if self.secure: if match_list(self.secure, cookie): make_secure = { 'http': 'https', 'httpOnly': 'httpsOnly' } if cookie[4] in make_secure: self.uzbl.send('cookie delete %s' % cookie.safe_raw()) new_cookie = list(cookie) new_cookie[4] = make_secure[cookie[4]] new_cookie = tuple(new_cookie) self.uzbl.send('cookie add %s' % new_cookie.safe_raw()) return if self.accept_cookie(cookie): for u in self.get_recipents(): u.send('cookie add %s' % cookie.safe_raw()) store = self.get_store(self.expires_with_session(cookie)) store.add_cookie(cookie.raw(), cookie) else: self.logger.debug('cookie %r is blacklisted', cookie) self.uzbl.send('cookie delete %s' % cookie.safe_raw())
def keycmd_strip_word(self, args): ''' Removes the last word from the keycmd, similar to readline ^W ''' args = splitquoted(args) assert len(args) <= 1 self.logger.debug('STRIPWORD %r %r', args, self.keylet) if self.keylet.strip_word(*args): self.update_event(set(), self.keylet, False)
def parse_key_event(self, key): ''' Build a set from the modstate part of the event, and pass all keys through modmap ''' modstate, key = splitquoted(key) modstate = set(['<%s>' % self.modmap_key(k) for k in modstate.split('|') if k]) key = self.modmap_key(key) return modstate, key
def set_cursor_pos(self, args): '''Allow setting of the cursor position externally. Supports negative indexing and relative stepping with '+' and '-'.''' args = splitquoted(args) assert len(args) == 1 self.keylet.set_cursor_pos(args[0]) self.update_event(set(), self.keylet, False)
def modmap_parse(self, map): '''Parse a modmap definiton.''' split = splitquoted(map) if not split or len(split) > 2: raise Exception('Invalid modmap arguments: %r' % map) self.add_modmap(*split)
def parse_key_event(self, key): ''' Build a set from the modstate part of the event, and pass all keys through modmap ''' modstate, key = splitquoted(key) modstate = set( ['<%s>' % self.modmap_key(k) for k in modstate.split('|') if k]) key = self.modmap_key(key) return modstate, key
def add_cookie(self, cookie): cookie = splitquoted(cookie) if self.accept_cookie(cookie): for u in self.get_recipents(): u.send('add_cookie %s' % cookie.raw()) self.get_store(self.expires_with_session(cookie)).add_cookie(cookie.raw(), cookie) else: self.logger.debug('cookie %r is blacklisted', cookie) self.uzbl.send('delete_cookie %s' % cookie.raw())
def delete_cookie(self, cookie): cookie = splitquoted(cookie) for u in self.get_recipents(): u.send('delete_cookie %s' % cookie.raw()) if len(cookie) == 6: self.get_store(self.expires_with_session(cookie)).delete_cookie(cookie.raw(), cookie) else: for store in set([self.get_store(session) for session in (True, False)]): store.delete_cookie(cookie.raw(), cookie)
def delete_cookie(self, cookie): cookie = splitquoted(cookie) for u in self.get_recipents(): u.send("cookie delete %s" % cookie.safe_raw()) if len(cookie) == 6: self.get_store(self.expires_with_session(cookie)).delete_cookie(cookie.raw(), cookie) else: for store in set([self.get_store(session) for session in (True, False)]): store.delete_cookie(cookie.raw(), cookie)
def download_started(self, args): # parse the arguments args = splitquoted(args) destination_path = args[0] # add to the list of active downloads self.active_downloads[destination_path] = 0.0 # update the progress self.update_download_section()
def parse_on_set(self, args): '''Parse `ON_SET <glob> <command>` event then pass arguments to the `on_set(..)` function.''' args = splitquoted(args) assert len(args) >= 2 glob = args[0] command = args.raw(1) assert glob and command and valid_glob(glob) self.on_set(glob, command)
def download_progress(self, args): # parse the arguments args = splitquoted(args) destination_path = args[0] progress = float(args[1]) # update the progress self.active_downloads[destination_path] = progress # update the status bar variable self.update_download_section()
def download_complete(self, args): # TODO(tailhook) be more userfriendly: show download for some time! # parse the arguments args = splitquoted(args) destination_path = args[0] # remove from the list of active downloads del self.active_downloads[destination_path] # update the status bar variable self.update_download_section()
def parse_mode_config(self, args): '''Parse `MODE_CONFIG <mode> <var> = <value>` event and update config if the `<mode>` is the current mode.''' args = splitquoted(args) assert len(args) >= 3, 'missing mode config args %r' % args mode = args[0] key = args[1] assert args[2] == '=', 'invalid mode config set syntax' value = args.raw(3).strip() self.mode_config[mode][key] = value config = Config[self.uzbl] if config.get('mode', None) == mode: config[key] = value
def event_handler(self, *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 # arguments if len(args) == 1 and isinstance(args[0], str): args = splitquoted(args[0]) event = kargs['on_event'] if event not in self.events: return commands = self.events[event] for cmd, pattern in commands: if not pattern or match_args(pattern, args): send_user_command(self.uzbl, cmd, args)
def add_cookie_matcher(_list, arg): ''' add a cookie matcher to a whitelist or a blacklist. a matcher is a list of (component, re) tuples that matches a cookie when the "component" part of the cookie matches the regular expression "re". "component" is one of the keys defined in the variable "symbolic" above, or the index of a component of a cookie tuple. ''' args = splitquoted(arg) mlist = [] for (component, regexp) in zip(args[0::2], args[1::2]): try: component = symbolic[component] except KeyError: component = int(component) assert component <= 5 mlist.append((component, re.compile(regexp).search)) _list.append(mlist)
def parse_on_event(self, args): '''Parse ON_EVENT events and pass them to the on_event function. Syntax: "event ON_EVENT <EVENT_NAME> <[ pattern ]> commands".''' args = splitquoted(args) assert args, 'missing on event arguments' # split into event name, optional argument pattern and command event = args[0] pattern = [] if args[1] == '[': for i, arg in enumerate(args[2:]): if arg == ']': break pattern.append(arg) command = tuple(args[3 + i:]) else: command = tuple(args[1:]) assert event and command, 'missing on event command' self.on_event(event, pattern, command)
def parse_mode_config(self, args): '''Parse `MODE_CONFIG <mode> <var> <value>` event and update config if the `<mode>` is the current mode.''' args = splitquoted(args) assert len(args) >= 3, 'missing mode config args %r' % args mode = args[0] key = args[1] # Use the rest of the line verbatim as the value unless it's a # single properly quoted string if len(args) == 3 and is_quoted(args.raw(2)): value = args[2] else: value = args.raw(2).strip() self.logger.debug('value %r', value) self.mode_config[mode][key] = value config = Config[self.uzbl] if config.get('mode', None) == mode: config[key] = value
def parse_on_event(self, args): '''Parse ON_EVENT events and pass them to the on_event function. Syntax: "event ON_EVENT <EVENT_NAME> <[ pattern ]> commands".''' args = splitquoted(args) assert args, 'missing on event arguments' # split into event name, optional argument pattern and command event = args[0] pattern = [] if args[1] == '[': for i, arg in enumerate(args[2:]): if arg == ']': break pattern.append(arg) command = tuple(args[3+i:]) else: command = tuple(args[1:]) assert event and command, 'missing on event command' self.on_event(event, pattern, command)
def add_builtins(self, builtins): '''Pump the space delimited list of builtin commands into the builtin list.''' builtins = splitquoted(builtins) self.completion.update(builtins)
def delete_cookie(self, rkey, key): self[:] = [x for x in self if not match(key, splitquoted(x))]