text
stringlengths
0
828
friendly_id = friendly_id.decode(""utf8"")
else:
friendly_id = unidecode(name).replace(""'"", ""_"")
token.value = (state, continent, name, friendly_id)
token.lexer.lineno += 1
return token"
1497,"def t_TEXT(self, token):
ur'(?P<text>[^<#\n ].+?[^ ])(?=\n)'
text = token.lexer.lexmatch.group(""text"").decode(""utf8"")
token.value = text
return token"
1498,"def t_PARBREAK(self, token):
ur'\n{2,}'
token.lexer.lineno += len(token.value)
return token"
1499,"def t_trailingwhitespace(self, token):
ur'.+? \n'
print ""Error: trailing whitespace at line %s in text '%s'"" % (token.lexer.lineno + 1, token.value[:-1])
token.lexer.lexerror = True
token.lexer.skip(1)"
1500,"def register_event(cls, event_name, event, method):
""""""
Register an event class on it's name with a method to process it.
:param event_name: name of the event.
:param event: class of the event.
:param method: a method used to process this event.
""""""
log.info('@Registry.register_event `{}` with subscriber `{}`'
.format(event_name, method.__name__))
if event_name not in cls._events:
cls._events[event_name] = {}
if event not in cls._events[event_name]:
cls._events[event_name][event] = []
cls._events[event_name][event].append(method)"
1501,"def register_producer(cls, producer):
""""""
Register a default producer for events to use.
:param producer: the default producer to to dispatch events on.
""""""
log.info('@Registry.register_producer `{}`'
.format(producer.__class__.__name__))
cls._producer = (cls._producer or producer)"
1502,"def exec_before_request_actions(actions, **kwargs):
""""""Execute actions in the ""before"" and ""before_METHOD"" groups
""""""
groups = (""before"", ""before_"" + flask.request.method.lower())
return execute_actions(actions, limit_groups=groups, **kwargs)"
1503,"def exec_after_request_actions(actions, response, **kwargs):
""""""Executes actions of the ""after"" and ""after_METHOD"" groups.
A ""response"" var will be injected in the current context.
""""""
current_context[""response""] = response
groups = (""after_"" + flask.request.method.lower(), ""after"")
try:
rv = execute_actions(actions, limit_groups=groups, **kwargs)
except ReturnValueException as e:
rv = e.value
if rv:
return rv
return response"
1504,"def full_exec_request_actions(actions, func=None, render_func=None):
""""""Full process to execute before, during and after actions.
If func is specified, it will be called after exec_request_actions()
unless a ContextExitException was raised. If render_func is specified,
it will be called after exec_request_actions() only if there is no
response. exec_after_request_actions() is always called.
""""""
response = None
try:
exec_before_request_actions(actions, catch_context_exit=False)
exec_request_actions(actions, catch_context_exit=False)
if func:
response = func()
except ContextExitException as e:
response = e.result
except ReturnValueException as e:
response = e.value
if render_func and response is None:
response = render_func()
return exec_after_request_actions(actions, response)"
1505,"def as_view(url=None, methods=None, view_class=ActionsView, name=None, url_rules=None, **kwargs):
""""""Decorator to transform a function into a view class. Be warned that this will replace
the function with the view class.
""""""
def decorator(f):
if url is not None:
f = expose(url, methods=methods)(f)
clsdict = {""name"": name or f.__name__,
""actions"": getattr(f, ""actions"", None),
""url_rules"": url_rules or getattr(f, ""urls"", None)}
if isinstance(f, WithActionsDecorator):
f = f.func
clsdict['func'] = f
def constructor(self, **ctorkwargs):