code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
# get formatter initialized by config (usualy on a NullHandler) ll = logging.getLogger('irc') formatter = ll.handlers[0].formatter # add a handler for the sub logger handler = Handler(bot, *targets) handler.setFormatter(formatter) self.addHandler(handler)
def set_irc_targets(self, bot, *targets)
Add a irc Handler using bot and log to targets (can be nicks or channels: .. >>> bot = None .. code-block:: python >>> log = logging.getLogger('irc.mymodule') >>> log.set_irc_targets(bot, '#chan', 'admin')
11.087918
10.668086
1.039354
data = data.replace('\n', ' ').replace('\r', ' ') f = asyncio.Future(loop=self.loop) if self.queue is not None and nowait is False: self.queue.put_nowait((f, data)) else: self.send(data.replace('\n', ' ').replace('\r', ' ')) f.set_result(True)...
def send_line(self, data, nowait=False)
send a line to the server. replace CR by spaces
2.687424
2.409869
1.115175
if message: messages = utils.split_message(message, self.config.max_length) if isinstance(target, DCCChat): for message in messages: target.send_line(message) elif target: f = None for message in mes...
def privmsg(self, target, message, nowait=False)
send a privmsg to target
3.915631
3.900872
1.003784
if target and message: messages = utils.split_message(message, self.config.max_length) f = None for message in messages: f = self.send_line('PRIVMSG %s :\x01%s\x01' % (target, message), ...
def ctcp(self, target, message, nowait=False)
send a ctcp to target
3.677699
3.678371
0.999817
self.send_line('MODE %s %s' % (target, ' '.join(data)), nowait=True)
def mode(self, target, *data)
set user or channel mode
4.554104
3.962993
1.149158
password = self.config.passwords.get( target.strip(self.server_config['CHANTYPES'])) if password: target += ' ' + password self.send_line('JOIN %s' % target)
def join(self, target)
join a channel
7.564977
6.438608
1.17494
if reason: target += ' :' + reason self.send_line('PART %s' % target)
def part(self, target, reason=None)
quit a channel
6.223222
5.501031
1.131283
if reason: target += ' :' + reason self.send_line('KICK %s %s' % (channel, target), nowait=True)
def kick(self, channel, target, reason=None)
kick target from channel
3.939372
4.129658
0.953922
if topic: channel += ' :' + topic self.send_line('TOPIC %s' % channel)
def topic(self, channel, topic=None)
change or request the topic of a channel
6.143356
6.241993
0.984198
cmd = 'AWAY' if message: cmd += ' :' + message self.send_line(cmd)
def away(self, message=None)
mark ourself as away
5.246896
4.67177
1.123107
if not reason: reason = 'bye' else: reason = reason self.send_line('QUIT :%s' % reason)
def quit(self, reason=None)
disconnect
3.999575
3.897532
1.026181
if not self._ip: if 'ip' in self.config: ip = self.config['ip'] else: ip = self.protocol.transport.get_extra_info('sockname')[0] ip = ip_address(ip) if ip.version == 4: self._ip = ip else: # pra...
def ip(self)
return bot's ip as an ``ip_address`` object
2.740288
2.55347
1.073162
if self._dcc is None: self._dcc = DCCManager(self) return self._dcc
def dcc(self)
return the :class:`~irc3.dcc.DCCManager`
4.283595
2.477253
1.729171
return self.dcc.create( 'chat', mask, host=host, port=port).ready
def dcc_chat(self, mask, host=None, port=None)
Open a DCC CHAT whith mask. If host/port are specified then connect to a server. Else create a server
10.236041
11.383679
0.899186
return self.dcc.create( 'get', mask, filepath=filepath, filesize=filesize, host=host, port=port).ready
def dcc_get(self, mask, host, port, filepath, filesize=None)
DCC GET a file from mask. filepath must be an absolute path with an existing directory. filesize is the expected file size.
6.752532
6.664553
1.013201
return self.dcc.create('send', mask, filepath=filepath).ready
def dcc_send(self, mask, filepath)
DCC SEND a file to mask. filepath must be an absolute path to existing file
20.616076
26.34992
0.782396
return self.dcc.resume(mask, filepath, port, pos)
def dcc_accept(self, mask, filepath, port, pos)
accept a DCC RESUME for an axisting DCC SEND. filepath is the filename to sent. port is the port opened on the server. pos is the expected offset
8.553246
8.495426
1.006806
'''Encodes a dictionary of tags to fit into an IRC-message. See IRC Message Tags: http://ircv3.net/specs/core/message-tags-3.2.html >>> from collections import OrderedDict >>> encode({'key': 'value'}) 'key=value' >>> d = {'aaa': 'bbb', 'ccc': None, 'example.com/ddd': 'eee'} >>> d_ordered =...
def encode(tags)
Encodes a dictionary of tags to fit into an IRC-message. See IRC Message Tags: http://ircv3.net/specs/core/message-tags-3.2.html >>> from collections import OrderedDict >>> encode({'key': 'value'}) 'key=value' >>> d = {'aaa': 'bbb', 'ccc': None, 'example.com/ddd': 'eee'} >>> d_ordered = Ordere...
3.424061
1.570052
2.180859
'''Decodes a tag-string from an IRC-message into a python dictionary. See IRC Message Tags: http://ircv3.net/specs/core/message-tags-3.2.html >>> from pprint import pprint >>> pprint(decode('key=value')) {'key': 'value'} >>> pprint(decode('aaa=bbb;ccc;example.com/ddd=eee')) {'aaa': 'bbb', ...
def decode(tagstring)
Decodes a tag-string from an IRC-message into a python dictionary. See IRC Message Tags: http://ircv3.net/specs/core/message-tags-3.2.html >>> from pprint import pprint >>> pprint(decode('key=value')) {'key': 'value'} >>> pprint(decode('aaa=bbb;ccc;example.com/ddd=eee')) {'aaa': 'bbb', 'ccc': ...
3.61264
1.73562
2.081469
def hdig(x): return fdigest(x).hexdigest() fdigest = get_digest(digest) luser = lower(username) tpass = password[:10].encode("ascii") hvalue = hdig("{0}:{1}".format(luser, hdig(tpass)).encode("ascii")) bhvalue = hvalue.encode("ascii") bchallenge = challenge.encode("ascii") ...
def challenge_auth(username, password, challenge, lower, digest='sha256')
Calculates quakenet's challenge auth hash .. code-block:: python >>> challenge_auth("mooking", "0000000000", ... "12345678901234567890123456789012", str.lower, "md5") '2ed1a1f1d2cd5487d2e18f27213286b9'
5.270844
5.705415
0.923832
conn = bot.get_social_connection(id='twitter') dirname = os.path.expanduser('~/.irc3/twitter/{nick}'.format(**bot.config)) if not os.path.isdir(dirname): os.makedirs(dirname) filename = os.path.join(dirname, 'retweeted') if os.path.isfile(filename): with open(filename) as fd: ...
def auto_retweet(bot)
retweet author tweets about irc3 and pypi releases
3.441768
3.046941
1.129581
fstate = entry.filename + '.state' if os.path.isfile(fstate): with open(fstate) as fd: state = fd.read().strip() else: state = None if 'failed' in entry.summary: nstate = 'failed' else: nstate = 'success' ...
def filter_travis(self, entry)
Only show the latest entry iif this entry is in a new state
3.164727
2.954998
1.070974
for package in self.packages: if entry.title.lower().startswith(package): return entry
def filter_pypi(self, entry)
Show only usefull packages
6.216984
5.481204
1.134237
channels = [] for res in results: channels.extend(res.pop('channels', '').split()) value.update(res) value['channels'] = channels value['success'] = value.get('retcode') == '318' return value
def process_results(self, results=None, **value)
take results list of all events and put them in a dict
5.734854
5.52147
1.038646
for res in results: if 'mask' in res: res['mask'] = utils.IrcString(res['mask']) value['success'] = res.pop('retcode', None) != '486' value.update(res) return value
def process_results(self, results=None, **value)
take results list of all events and return first dict
8.101809
7.583353
1.068368
bot.send('NOTICE %(nick)s :PONG %(nick)s!' % dict(nick=mask.nick))
def ping(bot, mask, target, args)
ping/pong %%ping
7.986239
11.011778
0.725245
msg = ' '.join(args['<args>']) bot.log.info('quote> %r', msg) bot.send(msg)
def quote(bot, mask, target, args)
send quote to the server %%quote <args>...
6.799062
6.700917
1.014647
plugin = bot.get_plugin(utils.maybedotted('irc3.plugins.core.Core')) bot.loop.call_soon(plugin.reconnect)
def reconnect(bot, mask, target, args)
force reconnect %%reconnect
9.129182
9.509213
0.960035
def p(text): print(text, file=file) plugin = bot.get_plugin(Commands) title = "Available Commands for {nick} at {host}".format(**bot.config) p("=" * len(title)) p(title) p("=" * len(title)) p('') p('.. contents::') p('') modules = {} for name, (predicates, callba...
def print_help_page(bot, file=sys.stdout)
print help page
3.381144
3.415062
0.990068
self.bot.log.info('Server config: %r', self.bot.server_config) # recompile when I'm sure of my nickname self.bot.config['nick'] = kwargs['me'] self.bot.recompile() # Let all plugins know that server can handle commands self.bot.notify('server_ready') #...
def connected(self, **kwargs)
triger the server_ready event
10.617722
9.906042
1.071843
self.reconn_handle.cancel() self.reconn_handle = self.bot.loop.call_later(self.timeout, self.reconnect) if self.ping_handle is not None: self.ping_handle.cancel() self.ping_handle = self.bot.loop.call_later( ...
def pong(self, event='PONG', data='', **kw): # pragma: no cover self.bot.log.debug('%s ping-pong (%s)', event, data) if self.reconn_handle is not None
P0NG/PING
2.761166
2.68087
1.029951
self.bot.send('PONG :' + data) self.pong(event='PING', data=data)
def ping(self, data)
PING reply
10.971682
10.767144
1.018996
if self.bot.nick == nick.nick: self.bot.config['nick'] = new_nick self.bot.recompile()
def recompile(self, nick=None, new_nick=None, **kw)
recompile regexp on new nick
5.95528
5.192906
1.146811
if me == '*': self.bot.set_nick(self.bot.nick + '_') self.bot.log.debug('Trying to regain nickname in 30s...') self.nick_handle = self.bot.loop.call_later( 30, self.bot.set_nick, self.bot.original_nick)
def badnick(self, me=None, nick=None, **kw)
Use alt nick on nick error
5.371389
5.209739
1.031028
config = self.bot.config['server_config'] for opt in data.split(' '): if '=' in opt: opt, value = opt.split('=', 1) else: value = True if opt.isupper(): config[opt] = value
def set_config(self, data=None, **kwargs)
Store server config
3.499474
3.129873
1.118088
session = args['session'] for feed, filename in zip(args['feeds'], args['filenames']): try: resp = session.get(feed, timeout=5) content = resp.content except Exception: # pragma: no cover pass else: with open(filename, 'wb') as fd: ...
def fetch(args)
fetch a feed
3.386144
3.269918
1.035544
entries = [] args = irc3.utils.Config(args) max_date = datetime.datetime.now() - datetime.timedelta(days=2) for filename in args['filenames']: try: with open(filename + '.updated') as fd: updated = fd.read().strip() except (OSError, IOError): ...
def parse(feedparser, args)
parse a feed using feedparser
3.026645
3.022976
1.001214
self.set_timeout() data = self.decode(data) if self.queue: data = self.queue.popleft() + data lines = data.replace('\r', '').split('\n') self.queue.append(lines.pop(-1)) for line in lines: self.bot.dispatch(line, iotype='dcc_in', client=se...
def data_received(self, data)
data received
5.552233
5.361034
1.035665
def callback(context, name, ob): obj = context.context if info.scope == 'class': @functools.wraps(func) def f(self, *args, **kwargs): plugin = obj.get_plugin(ob) return getattr(plugin, func.__name__)(*args, **kwargs) setattr(ob...
def extend(func)
same as :func:`~irc3.dec.extend` but for servers
3.981201
3.700473
1.075863
reg = self.registry insert = 'insert' in kwargs for e in events: cregexp = e.compile(self.config) regexp = getattr(e.regexp, 're', e.regexp) if regexp not in reg.events[e.iotype]: if insert: reg.events_re[e.iotype]....
def attach_events(self, *events, **kwargs)
Attach one or more events to the bot instance
3.427091
3.472319
0.986975
reg = self.registry delete = defaultdict(list) # remove from self.events all_events = reg.events for e in events: regexp = getattr(e.regexp, 're', e.regexp) iotype = e.iotype if e in all_events[iotype].get(regexp, []): ...
def detach_events(self, *events)
Detach one or more events from the bot instance
3.005757
3.010981
0.998265
self.notify('before_reload') if 'configfiles' in self.config: # reload configfiles self.log.info('Reloading configuration...') cfg = utils.parse_config( self.server and 'server' or 'bot', *self.config['configfiles']) self.config.u...
def reload(self, *modules)
Reload one or more plugins
4.904237
4.919456
0.996906
if isinstance(callback, str): callback = getattr(self, callback) f = None for arg in args: f = callback(*arg) return f
def call_many(self, callback, args)
callback is run with each arg but run a call per second
3.846774
3.710018
1.036861
try: self.loop.add_signal_handler(signal.SIGHUP, self.SIGHUP) except (RuntimeError, AttributeError): # pragma: no cover # windows pass try: self.loop.add_signal_handler(signal.SIGINT, self.SIGINT) except (RuntimeError, NotImplemen...
def add_signal_handlers(self)
Register handlers for UNIX signals (SIGHUP/SIGINT)
2.871489
2.698408
1.064142
loop = self.create_connection() self.add_signal_handlers() if forever: loop.run_forever()
def run(self, forever=True)
start the bot
5.394147
4.984195
1.08225
cfg = dict(cfg, **kwargs) pythonpath = cfg.get('pythonpath', []) if 'here' in cfg: pythonpath.append(cfg['here']) for path in pythonpath: sys.path.append(os.path.expanduser(path)) prog = cls.server and 'irc3d' or 'irc3' if cfg.get('debug')...
def from_config(cls, cfg, **kwargs)
return an instance configured with the ``cfg`` dict
4.732173
4.676667
1.011869
''' Executes the provided Robot Framework keyword in a separate thread and immediately returns a handle to be used with async_get ''' handle = self._last_thread_handle thread = self._threaded(keyword, *args, **kwargs) thread.start() self._thread_pool[handle] = thread self...
def async_run(self, keyword, *args, **kwargs)
Executes the provided Robot Framework keyword in a separate thread and immediately returns a handle to be used with async_get
5.249269
3.372576
1.556457
''' Blocks until the thread created by async_run returns ''' assert handle in self._thread_pool, 'Invalid async call handle' result = self._thread_pool[handle].result_queue.get() del self._thread_pool[handle] return result
def async_get(self, handle)
Blocks until the thread created by async_run returns
6.229134
4.089239
1.523299
''' Gets the Robot Framework handler associated with the given keyword ''' if EXECUTION_CONTEXTS.current is None: raise RobotNotRunningError('Cannot access execution context') return EXECUTION_CONTEXTS.current.get_handler(keyword)
def _get_handler_from_keyword(self, keyword)
Gets the Robot Framework handler associated with the given keyword
6.488924
5.014369
1.294066
''' A special set function to ensure we're setting with a dictionary ''' if value is None: setattr(self, '_PMMail__custom_headers', {}) elif isinstance(value, dict): setattr(self, '_PMMail__custom_headers', value) else: raise Ty...
def _set_custom_headers(self, value)
A special set function to ensure we're setting with a dictionary
6.029646
3.453116
1.746146
''' A special set function to ensure we're setting with a dictionary ''' if value is None: setattr(self, '_PMMail__metadata', {}) elif isinstance(value, dict): for k, v in value.items(): if (not isinstance(k, str) and not isinstance...
def _set_metadata(self, value)
A special set function to ensure we're setting with a dictionary
3.456892
2.607652
1.325672
''' A special set function to ensure we're setting with a list ''' if value is None: setattr(self, '_PMMail__attachments', []) elif isinstance(value, list): setattr(self, '_PMMail__attachments', value) else: raise TypeError('Att...
def _set_attachments(self, value)
A special set function to ensure we're setting with a list
5.700715
3.315156
1.719592
''' Make sure all values are of the appropriate type and are not missing. ''' if not self.__api_key: raise PMMailMissingValueException('Cannot send an e-mail without a Postmark API Key') elif not self.__sender: raise PMMailMissingValueException('Ca...
def _check_values(self)
Make sure all values are of the appropriate type and are not missing.
3.187578
2.797478
1.139447
''' Send the email through the Postmark system. Pass test=True to just print out the resulting JSON message being sent to Postmark ''' self._check_values() # Set up message dictionary json_message = self.to_json_message() # if (self.__html_body a...
def send(self, test=None)
Send the email through the Postmark system. Pass test=True to just print out the resulting JSON message being sent to Postmark
3.181133
2.903669
1.095556
''' Remove a message from the batch ''' if message in self.__messages: self.__messages.remove(message)
def remove_message(self, message)
Remove a message from the batch
5.224534
4.209669
1.241079
''' Returns a summary of inactive emails and bounces by type. ''' self._check_values() req = Request( __POSTMARK_URL__ + 'deliverystats', None, { 'Accept': 'application/json', 'Content-Type': 'application/json',...
def delivery_stats(self)
Returns a summary of inactive emails and bounces by type.
4.630445
3.681401
1.257794
''' Fetches a portion of bounces according to the specified input criteria. The count and offset parameters are mandatory. You should never retrieve all bounces as that could be excessively slow for your application. To know how many bounces you have, you need to request a portion ...
def get_all(self, inactive='', email_filter='', tag='', count=25, offset=0)
Fetches a portion of bounces according to the specified input criteria. The count and offset parameters are mandatory. You should never retrieve all bounces as that could be excessively slow for your application. To know how many bounces you have, you need to request a portion first, usually the...
4.628893
2.435768
1.900383
''' Activates a deactivated bounce. ''' self._check_values() req_url = '/bounces/' + str(bounce_id) + '/activate' # print req_url h1 = HTTPConnection('api.postmarkapp.com') dta = urlencode({"data": "blank"}).encode('utf8') req = h1.request( ...
def activate(self, bounce_id)
Activates a deactivated bounce.
3.770846
3.604195
1.046238
if not email_messages: return sent = self._send(email_messages) if sent: return len(email_messages) return 0
def send_messages(self, email_messages)
Sends one or more EmailMessage objects and returns the number of email messages sent.
3.829627
3.538893
1.082154
if not message.recipients(): return False recipients = ','.join(message.to) recipients_cc = ','.join(message.cc) recipients_bcc = ','.join(message.bcc) text_body = message.body html_body = None if isinstance(message, EmailMultiAlternatives): ...
def _build_message(self, message)
A helper method to convert a PMEmailMessage to a PMMail
2.375316
2.257004
1.05242
if len(messages) == 1: to_send = self._build_message(messages[0]) if to_send is False: # The message was missing recipients. # Bail. return False else: pm_messages = list(map(self._build_message, messages)) ...
def _send(self, messages)
A helper method that does the actual sending.
3.516225
3.392299
1.036532
''' PDF link handler; never gets explicitly called by user ''' if tag == 'a' and ( ('class', 'download-pdf') in attrs or ('id', 'download-pdf') in attrs ): for attr in attrs: if attr[0] == 'href': self.download_link = 'http://www.nature.com' + attr[1]
def handle_starttag(self, tag, attrs)
PDF link handler; never gets explicitly called by user
5.970127
3.104698
1.922933
try: return rstr.xeger(pattern) except re.error as e: raise ValueError(str(e))
def genpass(pattern=r'[\w]{32}')
generates a password with random chararcters
4.280906
4.408187
0.971126
if string is None: string = CHAR_ZERO * self.__size__ data = struct.unpack(self.__fmt__, string) i = 0 for field in self.__fields__: (vtype, vlen) = self.__fields_types__[field] if vtype == 'char': # string setattr(self, field,...
def unpack(self, string)
Unpack the string containing packed C structure data
2.344151
2.290815
1.023283
data = [] for field in self.__fields__: (vtype, vlen) = self.__fields_types__[field] if vtype == 'char': # string data.append(getattr(self, field)) elif isinstance(vtype, CStructMeta): num = int(vlen / vtype.size) ...
def pack(self)
Pack the structure data into a string
2.487615
2.431772
1.022964
"andreax + pts/0 2013-08-21 08:58 . 32341 (l26.box)" " pts/34 2013-06-12 15:04 26396 id=s/34 term=0 exit=0" # if self.ut_type not in [6,7]: # return print("%-10s %-12s %15s %15s %-8s" % ( str_from_c(self.ut_user...
def print_info(self)
andreax + pts/0 2013-08-21 08:58 . 32341 (l26.box)
6.637933
3.863572
1.718082
_import_all_importer_files() for module in (value for key, value in globals().items() if key in __all__): for klass_name, klass in inspect.getmembers(module, inspect.isclass): if klass is not BaseImporter and issubclass(klass, BaseImporter): yield kl...
def get_all()
Get all subclasses of BaseImporter from module and return and generator
4.686962
3.871109
1.210754
credentials = db.credentials() if credentials: table = Table( db.config['headers'], table_format=db.config['table_format'], colors=db.config['colors'], hidden=db.config['hidden'], hidden_string=db.config['hidden_string'], ) ...
def list_database(db)
Print credential as a table
4.623463
4.255441
1.086483
if level == 'global': configuration = config.read(config.HOMEDIR, '.passpierc') elif level == 'local': configuration = config.read(os.path.join(db.path)) elif level == 'current': configuration = db.config if configuration: click.echo(yaml.safe_dump(configuration, de...
def check_config(db, level)
Show current configuration for shell
4.872434
4.408978
1.105116
self.data = self.handle(data, **kwargs) return self
def process(self, data=None, **kwargs)
Process the provided data and invoke :meth:`Handler.handle` method for this Handler class. :params data: The data being processed. :returns: self :rtype: :class:`Handler` .. code-block:: python def post(self, *args, **kwargs): self.request = self.ge...
6.414956
12.339267
0.519881
return super(RequestHandler, self).process(data=data or self.get_request_data())
def process(self, data=None)
Fetch incoming data from the Flask request object when no data is supplied to the process method. By default, the RequestHandler expects the incoming data to be sent as JSON.
8.512042
5.158293
1.650167
session = self.get_db_session() session.add(obj) session.commit() return obj
def save(self, obj)
Add ``obj`` to the SQLAlchemy session and commit the changes back to the database. :param obj: SQLAlchemy object being saved :returns: The saved object
4.413336
5.60295
0.787681
if self.model is None: raise ArrestedException('DBObjectMixin requires a model to be set.') idfield = getattr(self.model, self.model_id_param, None) if not idfield: raise ArrestedException('DBObjectMixin could not find a valid Model.id.') return query.f...
def filter_by_id(self, query)
Apply the primary key filter to query to filter the results for a specific instance by id. The filter applied by the this method by default can be controlled using the url_id_param :param query: SQLAlchemy Query :returns: A SQLAlchemy Query object
5.298433
4.916046
1.077783
query = self.get_query() query = self.filter_by_id(query) return self.get_result(query)
def get_object(self)
Implements the GetObjectMixin interface and calls :meth:`DBObjectMixin.get_query`. Using this mixin requires usage of a response handler capable of serializing SQLAlchemy query result objects. :returns: Typically a SQLALchemy Query result. :rtype: mixed .. seealso:: ...
6.627953
3.404398
1.946879
session = self.get_db_session() session.delete(obj) session.commit()
def delete_object(self, obj)
Deletes an object from the session by calling session.delete and then commits the changes to the database. :param obj: The SQLAlchemy instance being deleted :returns: None
3.820571
4.199606
0.909745
self.app = app if self.deferred: self.register_all(self.deferred)
def init_app(self, app)
Initialise the ArrestedAPI object by storing a pointer to a Flask app object. This method is typically used when initialisation is deferred. :param app: Flask application object Usage:: app = Flask(__name__) ap1_v1 = ArrestedAPI() api_v1.init_app(app)
8.736272
13.010861
0.67146
if defer: self.deferred.append(resource) else: resource.init_api(self) self.app.register_blueprint(resource, url_prefix=self.url_prefix)
def register_resource(self, resource, defer=False)
Register a :class:`.Resource` blueprint object against the Flask app object. :param resource: :class:`.Resource` or :class:`flask.Blueprint` object. :param defer: Optionally specify that registering this resource should be deferred. This option is useful when users are creating...
3.224874
5.126922
0.629008
hooks = [] if self.resource: hooks.extend(self.resource.api.before_all_hooks) hooks.extend(self.resource.before_all_hooks) hooks.extend(self.before_all_hooks) hooks.extend( getattr( self, 'before_{method}_hoo...
def process_before_request_hooks(self)
Process the list of before_{method}_hooks and the before_all_hooks. The hooks will be processed in the following order 1 - any before_all_hooks defined on the :class:`arrested.ArrestedAPI` object 2 - any before_all_hooks defined on the :class:`arrested.Resource` object 3 - any before_al...
3.310172
2.460812
1.345155
hooks = [] meth_hooks = getattr( self, 'after_{method}_hooks'.format(method=self.meth), [] ) hooks.extend(meth_hooks) hooks.extend(self.after_all_hooks) if self.resource: hooks.extend(self.resource.after_all_hook...
def process_after_request_hooks(self, resp)
Process the list of before_{method}_hooks and the before_all_hooks. The hooks will be processed in the following order 1 - any after_{method}_hooks defined on the :class:`arrested.Endpoint` object 2 - any after_all_hooks defined on the :class:`arrested.Endpoint` object 2 - any after_all...
2.839419
2.479214
1.14529
self.args = args self.kwargs = kwargs self.meth = request.method.lower() self.resource = current_app.blueprints.get(request.blueprint, None) if not any([self.meth in self.methods, self.meth.upper() in self.methods]): return self.return_error(405) se...
def dispatch_request(self, *args, **kwargs)
Dispatch the incoming HTTP request to the appropriate handler.
3.075711
3.050444
1.008283
if not isinstance(rv, Response): resp = Response( response=rv, headers=headers, mimetype=mime, status=status ) else: resp = rv return resp
def make_response(self, rv, status=200, headers=None, mime='application/json')
Create a response object using the :class:`flask.Response` class. :param rv: Response value. If the value is not an instance of :class:`werkzeug.wrappers.Response` it will be converted into a Response object. :param status: specify the HTTP status code for this response. ...
2.618308
3.270091
0.800683
assert self.response_handler is not None, \ 'Please define a response_handler ' \ ' for Endpoint: %s' % self.__class__.__name__ return self.response_handler(self, **self.get_response_handler_params())
def get_response_handler(self)
Return the Endpoints defined :attr:`Endpoint.response_handler`. :returns: A instance of the Endpoint specified :class:`ResonseHandler`. :rtype: :class:`ResponseHandler`
4.870206
4.533553
1.074258
assert self.request_handler is not None, \ 'Please define a request_handler ' \ ' for Endpoint: %s' % self.__class__.__name__ return self.request_handler(self, **self.get_request_handler_params())
def get_request_handler(self)
Return the Endpoints defined :attr:`Endpoint.request_handler`. :returns: A instance of the Endpoint specified :class:`RequestHandler`. :rtype: :class:`RequestHandler`
4.798378
4.602485
1.042562
resp = None if payload is not None: payload = json.dumps(payload) resp = self.make_response(payload, status=status) if status in [405]: abort(status) else: abort(status, response=resp)
def return_error(self, status, payload=None)
Error handler called by request handlers when an error occurs and the request should be aborted. Usage:: def handle_post_request(self, *args, **kwargs): self.request_handler = self.get_request_handler() try: self.request_handler.process(...
3.473684
4.047822
0.858161
if self.many: return self.mapper.many(raw=self.raw, **self.mapper_kwargs).serialize( data, role=self.role ) else: return self.mapper(obj=data, raw=self.raw, **self.mapper_kwargs).serialize( role=self.role )
def handle(self, data, **kwargs)
Run serialization for the specified mapper_class. Supports both .serialize and .many().serialize Kim interfaces. :param data: Objects to be serialized. :returns: Serialized data according to mapper configuration
4.307784
3.737141
1.152695
payload = { "message": "Invalid or incomplete data provided.", "errors": exp.errors } self.endpoint.return_error(self.error_status, payload=payload)
def handle_error(self, exp)
Called if a Mapper returns MappingInvalid. Should handle the error and return it in the appropriate format, can be overridden in order to change the error format. :param exp: MappingInvalid exception raised
8.000122
8.950667
0.893802
try: if self.many: return self.mapper.many(raw=self.raw, **self.mapper_kwargs).marshal( data, role=self.role ) else: return self.mapper( data=data, obj=self.obj, ...
def handle(self, data, **kwargs)
Run marshalling for the specified mapper_class. Supports both .marshal and .many().marshal Kim interfaces. Handles errors raised during marshalling and automatically returns a HTTP error response. :param data: Data to be marshaled. :returns: Marshaled object according to mapper config...
4.357848
3.625532
1.201988
params = super(KimEndpoint, self).get_response_handler_params(**params) params['mapper_class'] = self.mapper_class params['role'] = self.serialize_role # After a successfull attempt to marshal an object has been made, a response # is generated using the RepsonseHandler...
def get_response_handler_params(self, **params)
Return a config object that will be used to configure the KimResponseHandler :returns: a dictionary of config options :rtype: dict
7.957898
7.894757
1.007998
params = super(KimEndpoint, self).get_request_handler_params(**params) params['mapper_class'] = self.mapper_class params['role'] = self.marshal_role params['many'] = False # when handling a PUT or PATCH request, self.obj will be set.. There might be a # more rob...
def get_request_handler_params(self, **params)
Return a config object that will be used to configure the KimRequestHandler :returns: a dictionary of config options :rtype: dict
6.337188
6.150516
1.030351
return self._response(self.response.get_response_data(), status=status)
def list_response(self, status=200)
Pull the processed data from the response_handler and return a response. :param status: The HTTP status code returned with the response .. seealso: :meth:`Endpoint.make_response` :meth:`Endpoint.handle_get_request`
10.166265
9.45298
1.075456
self.objects = self.get_objects() self.response = self.get_response_handler() self.response.process(self.objects) return self.list_response()
def handle_get_request(self)
Handle incoming GET request to an Endpoint and return an array of results by calling :meth:`.GetListMixin.get_objects`. .. seealso:: :meth:`GetListMixin.get_objects` :meth:`Endpoint.get`
7.087131
6.401585
1.10709
self.response = self.get_response_handler() self.response.process(self.obj) return self._response(self.response.get_response_data(), status=status)
def create_response(self, status=201)
Generate a Response object for a POST request. By default, the newly created object will be passed to the specified ResponseHandler and will be serialized as the response body.
6.535758
5.344533
1.222887
self.request = self.get_request_handler() self.obj = self.request.process().data self.save_object(self.obj) return self.create_response()
def handle_post_request(self)
Handle incoming POST request to an Endpoint and marshal the request data via the specified RequestHandler. :meth:`.CreateMixin.save_object`. is then called and must be implemented by mixins implementing this interfce. .. seealso:: :meth:`CreateMixin.save_object` :meth:`...
6.460985
5.701785
1.133151
if not getattr(self, '_obj', None): self._obj = self.get_object() if self._obj is None and not self.allow_none: self.return_error(404) return self._obj
def obj(self)
Returns the value of :meth:`ObjectMixin.get_object` and sets a private property called _obj. This property ensures the logic around allow_none is enforced across Endpoints using the Object interface. :raises: :class:`werkzeug.exceptions.BadRequest` :returns: The result of :meth:ObjectM...
3.639326
3.294699
1.104601
''' An FSM accepting nothing (not even the empty string). This is demonstrates that this is possible, and is also extremely useful in some situations ''' return fsm( alphabet = alphabet, states = {0}, initial = 0, finals = set(), map = { 0: dict([(symbol, 0) for symbol in alphabet]), }...
def null(alphabet)
An FSM accepting nothing (not even the empty string). This is demonstrates that this is possible, and is also extremely useful in some situations
5.927529
2.568388
2.307879
''' Crawl several FSMs in parallel, mapping the states of a larger meta-FSM. To determine whether a state in the larger FSM is final, pass all of the finality statuses (e.g. [True, False, False] to `test`. ''' alphabet = set().union(*[fsm.alphabet for fsm in fsms]) initial = dict([(i, fsm.initial) for (i, fs...
def parallel(fsms, test)
Crawl several FSMs in parallel, mapping the states of a larger meta-FSM. To determine whether a state in the larger FSM is final, pass all of the finality statuses (e.g. [True, False, False] to `test`.
4.659944
3.25718
1.430668
''' Given the above conditions and instructions, crawl a new unknown FSM, mapping its states, final states and transitions. Return the new FSM. This is a pretty powerful procedure which could potentially go on forever if you supply an evil version of follow(). ''' states = [initial] finals = set() map = {...
def crawl(alphabet, initial, final, follow)
Given the above conditions and instructions, crawl a new unknown FSM, mapping its states, final states and transitions. Return the new FSM. This is a pretty powerful procedure which could potentially go on forever if you supply an evil version of follow().
4.492971
2.475701
1.814828
''' Test whether the present FSM accepts the supplied string (iterable of symbols). Equivalently, consider `self` as a possibly-infinite set of strings and test whether `string` is a member of it. This is actually mainly used for unit testing purposes. If `fsm.anything_else` is in your alphabet, then a...
def accepts(self, input)
Test whether the present FSM accepts the supplied string (iterable of symbols). Equivalently, consider `self` as a possibly-infinite set of strings and test whether `string` is a member of it. This is actually mainly used for unit testing purposes. If `fsm.anything_else` is in your alphabet, then any symbol...
6.208549
2.043392
3.038355
''' Concatenate arbitrarily many finite state machines together. ''' alphabet = set().union(*[fsm.alphabet for fsm in fsms]) def connect_all(i, substate): ''' Take a state in the numbered FSM and return a set containing it, plus (if it's final) the first state from the next FSM, plus (if that's ...
def concatenate(*fsms)
Concatenate arbitrarily many finite state machines together.
3.636794
3.53463
1.028904
''' If the present FSM accepts X, returns an FSM accepting X* (i.e. 0 or more Xes). This is NOT as simple as naively connecting the final states back to the initial state: see (b*ab)* for example. ''' alphabet = self.alphabet initial = {self.initial} def follow(state, symbol): next = set() fo...
def star(self)
If the present FSM accepts X, returns an FSM accepting X* (i.e. 0 or more Xes). This is NOT as simple as naively connecting the final states back to the initial state: see (b*ab)* for example.
5.038607
2.687385
1.87491