repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
yougov/pmxbot | pmxbot/commands.py | urbandict | def urbandict(rest):
"Define a word with Urban Dictionary"
word = rest.strip()
definition = util.urban_lookup(word)
if not definition:
return "Arg! I didn't find a definition for that."
return 'Urban Dictionary says {word}: {definition}'.format(**locals()) | python | def urbandict(rest):
"Define a word with Urban Dictionary"
word = rest.strip()
definition = util.urban_lookup(word)
if not definition:
return "Arg! I didn't find a definition for that."
return 'Urban Dictionary says {word}: {definition}'.format(**locals()) | [
"def",
"urbandict",
"(",
"rest",
")",
":",
"word",
"=",
"rest",
".",
"strip",
"(",
")",
"definition",
"=",
"util",
".",
"urban_lookup",
"(",
"word",
")",
"if",
"not",
"definition",
":",
"return",
"\"Arg! I didn't find a definition for that.\"",
"return",
"'Ur... | Define a word with Urban Dictionary | [
"Define",
"a",
"word",
"with",
"Urban",
"Dictionary"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L732-L738 |
yougov/pmxbot | pmxbot/commands.py | acit | def acit(rest):
"Look up an acronym"
word = rest.strip()
res = util.lookup_acronym(word)
if res is None:
return "Arg! I couldn't expand that..."
else:
return ' | '.join(res) | python | def acit(rest):
"Look up an acronym"
word = rest.strip()
res = util.lookup_acronym(word)
if res is None:
return "Arg! I couldn't expand that..."
else:
return ' | '.join(res) | [
"def",
"acit",
"(",
"rest",
")",
":",
"word",
"=",
"rest",
".",
"strip",
"(",
")",
"res",
"=",
"util",
".",
"lookup_acronym",
"(",
"word",
")",
"if",
"res",
"is",
"None",
":",
"return",
"\"Arg! I couldn't expand that...\"",
"else",
":",
"return",
"' | '... | Look up an acronym | [
"Look",
"up",
"an",
"acronym"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L742-L749 |
yougov/pmxbot | pmxbot/commands.py | fight | def fight(nick, rest):
"Pit two sworn enemies against each other (separate with 'vs.')"
if rest:
vtype = random.choice(phrases.fight_victories)
fdesc = random.choice(phrases.fight_descriptions)
# valid separators are vs., v., and vs
pattern = re.compile('(.*) (?:vs[.]?|v[.]) (.*)')
matcher = pattern.match(r... | python | def fight(nick, rest):
"Pit two sworn enemies against each other (separate with 'vs.')"
if rest:
vtype = random.choice(phrases.fight_victories)
fdesc = random.choice(phrases.fight_descriptions)
# valid separators are vs., v., and vs
pattern = re.compile('(.*) (?:vs[.]?|v[.]) (.*)')
matcher = pattern.match(r... | [
"def",
"fight",
"(",
"nick",
",",
"rest",
")",
":",
"if",
"rest",
":",
"vtype",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"fight_victories",
")",
"fdesc",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"fight_descriptions",
")",
"# valid sep... | Pit two sworn enemies against each other (separate with 'vs.') | [
"Pit",
"two",
"sworn",
"enemies",
"against",
"each",
"other",
"(",
"separate",
"with",
"vs",
".",
")"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L753-L770 |
yougov/pmxbot | pmxbot/commands.py | progress | def progress(rest):
"Display the progress of something: start|end|percent"
if rest:
left, right, amount = [piece.strip() for piece in rest.split('|')]
ticks = min(int(round(float(amount) / 10)), 10)
bar = "=" * ticks
return "%s [%-10s] %s" % (left, bar, right) | python | def progress(rest):
"Display the progress of something: start|end|percent"
if rest:
left, right, amount = [piece.strip() for piece in rest.split('|')]
ticks = min(int(round(float(amount) / 10)), 10)
bar = "=" * ticks
return "%s [%-10s] %s" % (left, bar, right) | [
"def",
"progress",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"left",
",",
"right",
",",
"amount",
"=",
"[",
"piece",
".",
"strip",
"(",
")",
"for",
"piece",
"in",
"rest",
".",
"split",
"(",
"'|'",
")",
"]",
"ticks",
"=",
"min",
"(",
"int",
"(",... | Display the progress of something: start|end|percent | [
"Display",
"the",
"progress",
"of",
"something",
":",
"start|end|percent"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L774-L780 |
yougov/pmxbot | pmxbot/commands.py | nastygram | def nastygram(nick, rest):
"""
A random passive-agressive comment, optionally directed toward
some(one|thing).
"""
recipient = ""
if rest:
recipient = rest.strip()
karma.Karma.store.change(recipient, -1)
return util.passagg(recipient, nick.lower()) | python | def nastygram(nick, rest):
"""
A random passive-agressive comment, optionally directed toward
some(one|thing).
"""
recipient = ""
if rest:
recipient = rest.strip()
karma.Karma.store.change(recipient, -1)
return util.passagg(recipient, nick.lower()) | [
"def",
"nastygram",
"(",
"nick",
",",
"rest",
")",
":",
"recipient",
"=",
"\"\"",
"if",
"rest",
":",
"recipient",
"=",
"rest",
".",
"strip",
"(",
")",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"recipient",
",",
"-",
"1",
")",
"return... | A random passive-agressive comment, optionally directed toward
some(one|thing). | [
"A",
"random",
"passive",
"-",
"agressive",
"comment",
"optionally",
"directed",
"toward",
"some",
"(",
"one|thing",
")",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L784-L793 |
yougov/pmxbot | pmxbot/commands.py | meaculpa | def meaculpa(nick, rest):
"Sincerely apologize"
if rest:
rest = rest.strip()
if rest:
return random.choice(phrases.direct_apologies) % dict(a=nick, b=rest)
else:
return random.choice(phrases.apologies) % dict(a=nick) | python | def meaculpa(nick, rest):
"Sincerely apologize"
if rest:
rest = rest.strip()
if rest:
return random.choice(phrases.direct_apologies) % dict(a=nick, b=rest)
else:
return random.choice(phrases.apologies) % dict(a=nick) | [
"def",
"meaculpa",
"(",
"nick",
",",
"rest",
")",
":",
"if",
"rest",
":",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"rest",
":",
"return",
"random",
".",
"choice",
"(",
"phrases",
".",
"direct_apologies",
")",
"%",
"dict",
"(",
"a",
"=",
... | Sincerely apologize | [
"Sincerely",
"apologize"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L835-L843 |
yougov/pmxbot | pmxbot/commands.py | version | def version(rest):
"Get the version of pmxbot or one of its plugins"
pkg = rest.strip() or 'pmxbot'
if pkg.lower() == 'python':
return sys.version.split()[0]
return importlib_metadata.version(pkg) | python | def version(rest):
"Get the version of pmxbot or one of its plugins"
pkg = rest.strip() or 'pmxbot'
if pkg.lower() == 'python':
return sys.version.split()[0]
return importlib_metadata.version(pkg) | [
"def",
"version",
"(",
"rest",
")",
":",
"pkg",
"=",
"rest",
".",
"strip",
"(",
")",
"or",
"'pmxbot'",
"if",
"pkg",
".",
"lower",
"(",
")",
"==",
"'python'",
":",
"return",
"sys",
".",
"version",
".",
"split",
"(",
")",
"[",
"0",
"]",
"return",
... | Get the version of pmxbot or one of its plugins | [
"Get",
"the",
"version",
"of",
"pmxbot",
"or",
"one",
"of",
"its",
"plugins"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L847-L852 |
yougov/pmxbot | pmxbot/commands.py | timezone | def timezone(rest):
"""Convert date between timezones.
Example:
> !tz 11:00am UTC in PDT
11:00 UTC -> 4:00 PDT
UTC is implicit
> !tz 11:00am in PDT
11:00 UTC -> 4:00 PDT
> !tz 11:00am PDT
11:00 PDT -> 18:00 UTC
"""
if ' in ' in rest:
dstr, tzname = rest.split(' in ', 1)
else:
dstr, tzname = rest, ... | python | def timezone(rest):
"""Convert date between timezones.
Example:
> !tz 11:00am UTC in PDT
11:00 UTC -> 4:00 PDT
UTC is implicit
> !tz 11:00am in PDT
11:00 UTC -> 4:00 PDT
> !tz 11:00am PDT
11:00 PDT -> 18:00 UTC
"""
if ' in ' in rest:
dstr, tzname = rest.split(' in ', 1)
else:
dstr, tzname = rest, ... | [
"def",
"timezone",
"(",
"rest",
")",
":",
"if",
"' in '",
"in",
"rest",
":",
"dstr",
",",
"tzname",
"=",
"rest",
".",
"split",
"(",
"' in '",
",",
"1",
")",
"else",
":",
"dstr",
",",
"tzname",
"=",
"rest",
",",
"'UTC'",
"tzobj",
"=",
"TZINFOS",
"... | Convert date between timezones.
Example:
> !tz 11:00am UTC in PDT
11:00 UTC -> 4:00 PDT
UTC is implicit
> !tz 11:00am in PDT
11:00 UTC -> 4:00 PDT
> !tz 11:00am PDT
11:00 PDT -> 18:00 UTC | [
"Convert",
"date",
"between",
"timezones",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L898-L927 |
yougov/pmxbot | pmxbot/storage.py | SelectableStorage.finalize | def finalize(cls):
"Delete the various persistence objects"
for finalizer in cls._finalizers:
try:
finalizer()
except Exception:
log.exception("Error in finalizer %s", finalizer) | python | def finalize(cls):
"Delete the various persistence objects"
for finalizer in cls._finalizers:
try:
finalizer()
except Exception:
log.exception("Error in finalizer %s", finalizer) | [
"def",
"finalize",
"(",
"cls",
")",
":",
"for",
"finalizer",
"in",
"cls",
".",
"_finalizers",
":",
"try",
":",
"finalizer",
"(",
")",
"except",
"Exception",
":",
"log",
".",
"exception",
"(",
"\"Error in finalizer %s\"",
",",
"finalizer",
")"
] | Delete the various persistence objects | [
"Delete",
"the",
"various",
"persistence",
"objects"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/storage.py#L51-L57 |
yougov/pmxbot | pmxbot/system.py | help | def help(rest):
"""Help (this command)"""
rs = rest.strip()
if rs:
# give help for matching commands
for handler in Handler._registry:
if handler.name == rs.lower():
yield '!%s: %s' % (handler.name, handler.doc)
break
else:
yield "command not found"
return
# give help for all commands
def mk... | python | def help(rest):
"""Help (this command)"""
rs = rest.strip()
if rs:
# give help for matching commands
for handler in Handler._registry:
if handler.name == rs.lower():
yield '!%s: %s' % (handler.name, handler.doc)
break
else:
yield "command not found"
return
# give help for all commands
def mk... | [
"def",
"help",
"(",
"rest",
")",
":",
"rs",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"rs",
":",
"# give help for matching commands",
"for",
"handler",
"in",
"Handler",
".",
"_registry",
":",
"if",
"handler",
".",
"name",
"==",
"rs",
".",
"lower",
"("... | Help (this command) | [
"Help",
"(",
"this",
"command",
")"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/system.py#L17-L49 |
yougov/pmxbot | pmxbot/web/viewer.py | pmon | def pmon(month):
"""
P the month
>>> print(pmon('2012-08'))
August, 2012
"""
year, month = month.split('-')
return '{month_name}, {year}'.format(
month_name=calendar.month_name[int(month)],
year=year,
) | python | def pmon(month):
"""
P the month
>>> print(pmon('2012-08'))
August, 2012
"""
year, month = month.split('-')
return '{month_name}, {year}'.format(
month_name=calendar.month_name[int(month)],
year=year,
) | [
"def",
"pmon",
"(",
"month",
")",
":",
"year",
",",
"month",
"=",
"month",
".",
"split",
"(",
"'-'",
")",
"return",
"'{month_name}, {year}'",
".",
"format",
"(",
"month_name",
"=",
"calendar",
".",
"month_name",
"[",
"int",
"(",
"month",
")",
"]",
",",... | P the month
>>> print(pmon('2012-08'))
August, 2012 | [
"P",
"the",
"month"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/web/viewer.py#L54-L65 |
yougov/pmxbot | pmxbot/web/viewer.py | pday | def pday(dayfmt):
"""
P the day
>>> print(pday('2012-08-24'))
Friday the 24th
"""
year, month, day = map(int, dayfmt.split('-'))
return '{day} the {number}'.format(
day=calendar.day_name[calendar.weekday(year, month, day)],
number=inflect.engine().ordinal(day),
) | python | def pday(dayfmt):
"""
P the day
>>> print(pday('2012-08-24'))
Friday the 24th
"""
year, month, day = map(int, dayfmt.split('-'))
return '{day} the {number}'.format(
day=calendar.day_name[calendar.weekday(year, month, day)],
number=inflect.engine().ordinal(day),
) | [
"def",
"pday",
"(",
"dayfmt",
")",
":",
"year",
",",
"month",
",",
"day",
"=",
"map",
"(",
"int",
",",
"dayfmt",
".",
"split",
"(",
"'-'",
")",
")",
"return",
"'{day} the {number}'",
".",
"format",
"(",
"day",
"=",
"calendar",
".",
"day_name",
"[",
... | P the day
>>> print(pday('2012-08-24'))
Friday the 24th | [
"P",
"the",
"day"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/web/viewer.py#L68-L80 |
yougov/pmxbot | pmxbot/web/viewer.py | patch_compat | def patch_compat(config):
"""
Support older config values.
"""
if 'web_host' in config:
config['host'] = config.pop('web_host')
if 'web_port' in config:
config['port'] = config.pop('web_port') | python | def patch_compat(config):
"""
Support older config values.
"""
if 'web_host' in config:
config['host'] = config.pop('web_host')
if 'web_port' in config:
config['port'] = config.pop('web_port') | [
"def",
"patch_compat",
"(",
"config",
")",
":",
"if",
"'web_host'",
"in",
"config",
":",
"config",
"[",
"'host'",
"]",
"=",
"config",
".",
"pop",
"(",
"'web_host'",
")",
"if",
"'web_port'",
"in",
"config",
":",
"config",
"[",
"'port'",
"]",
"=",
"confi... | Support older config values. | [
"Support",
"older",
"config",
"values",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/web/viewer.py#L305-L312 |
yougov/pmxbot | pmxbot/web/viewer.py | resolve_file | def resolve_file(mgr, filename):
"""
Given a file manager (ExitStack), load the filename
and set the exit stack to clean up. See
https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename
for more details.
"""
path = importlib_resources.path('pmxbot.web.templates', filena... | python | def resolve_file(mgr, filename):
"""
Given a file manager (ExitStack), load the filename
and set the exit stack to clean up. See
https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename
for more details.
"""
path = importlib_resources.path('pmxbot.web.templates', filena... | [
"def",
"resolve_file",
"(",
"mgr",
",",
"filename",
")",
":",
"path",
"=",
"importlib_resources",
".",
"path",
"(",
"'pmxbot.web.templates'",
",",
"filename",
")",
"return",
"str",
"(",
"mgr",
".",
"enter_context",
"(",
"path",
")",
")"
] | Given a file manager (ExitStack), load the filename
and set the exit stack to clean up. See
https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename
for more details. | [
"Given",
"a",
"file",
"manager",
"(",
"ExitStack",
")",
"load",
"the",
"filename",
"and",
"set",
"the",
"exit",
"stack",
"to",
"clean",
"up",
".",
"See",
"https",
":",
"//",
"importlib",
"-",
"resources",
".",
"readthedocs",
".",
"io",
"/",
"en",
"/",
... | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/web/viewer.py#L339-L347 |
yougov/pmxbot | pmxbot/web/viewer.py | ChannelPage.date_key | def date_key(cls, month_string):
"""
Return a key suitable for sorting by month.
>>> k1 = ChannelPage.date_key('September, 2012')
>>> k2 = ChannelPage.date_key('August, 2013')
>>> k2 > k1
True
"""
month, year = month_string.split(',')
month_ord = cls.month_ordinal[month]
return year, month_ord | python | def date_key(cls, month_string):
"""
Return a key suitable for sorting by month.
>>> k1 = ChannelPage.date_key('September, 2012')
>>> k2 = ChannelPage.date_key('August, 2013')
>>> k2 > k1
True
"""
month, year = month_string.split(',')
month_ord = cls.month_ordinal[month]
return year, month_ord | [
"def",
"date_key",
"(",
"cls",
",",
"month_string",
")",
":",
"month",
",",
"year",
"=",
"month_string",
".",
"split",
"(",
"','",
")",
"month_ord",
"=",
"cls",
".",
"month_ordinal",
"[",
"month",
"]",
"return",
"year",
",",
"month_ord"
] | Return a key suitable for sorting by month.
>>> k1 = ChannelPage.date_key('September, 2012')
>>> k2 = ChannelPage.date_key('August, 2013')
>>> k2 > k1
True | [
"Return",
"a",
"key",
"suitable",
"for",
"sorting",
"by",
"month",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/web/viewer.py#L110-L121 |
yougov/pmxbot | pmxbot/web/viewer.py | LegacyPage.forward | def forward(self, channel, date_s, fragment):
"""
Given an HREF in the legacy timezone, redirect to an href for UTC.
"""
time_s, sep, nick = fragment.rpartition('.')
time = datetime.datetime.strptime(time_s, '%H.%M.%S')
date = datetime.datetime.strptime(date_s, '%Y-%m-%d')
dt = datetime.datetime.combine(d... | python | def forward(self, channel, date_s, fragment):
"""
Given an HREF in the legacy timezone, redirect to an href for UTC.
"""
time_s, sep, nick = fragment.rpartition('.')
time = datetime.datetime.strptime(time_s, '%H.%M.%S')
date = datetime.datetime.strptime(date_s, '%Y-%m-%d')
dt = datetime.datetime.combine(d... | [
"def",
"forward",
"(",
"self",
",",
"channel",
",",
"date_s",
",",
"fragment",
")",
":",
"time_s",
",",
"sep",
",",
"nick",
"=",
"fragment",
".",
"rpartition",
"(",
"'.'",
")",
"time",
"=",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"time_s",
... | Given an HREF in the legacy timezone, redirect to an href for UTC. | [
"Given",
"an",
"HREF",
"in",
"the",
"legacy",
"timezone",
"redirect",
"to",
"an",
"href",
"for",
"UTC",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/web/viewer.py#L256-L272 |
yougov/pmxbot | pmxbot/logging.py | parse_date | def parse_date(record):
"Parse a date from sqlite. Assumes the date is in US/Pacific time zone."
dt = record.pop('datetime')
fmts = [
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M:%S',
]
for fmt in fmts:
try:
dt = datetime.datetime.strptime(dt, fmt)
break
except ValueError:
pass
else:
raise
tz = pyt... | python | def parse_date(record):
"Parse a date from sqlite. Assumes the date is in US/Pacific time zone."
dt = record.pop('datetime')
fmts = [
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M:%S',
]
for fmt in fmts:
try:
dt = datetime.datetime.strptime(dt, fmt)
break
except ValueError:
pass
else:
raise
tz = pyt... | [
"def",
"parse_date",
"(",
"record",
")",
":",
"dt",
"=",
"record",
".",
"pop",
"(",
"'datetime'",
")",
"fmts",
"=",
"[",
"'%Y-%m-%d %H:%M:%S.%f'",
",",
"'%Y-%m-%d %H:%M:%S'",
",",
"]",
"for",
"fmt",
"in",
"fmts",
":",
"try",
":",
"dt",
"=",
"datetime",
... | Parse a date from sqlite. Assumes the date is in US/Pacific time zone. | [
"Parse",
"a",
"date",
"from",
"sqlite",
".",
"Assumes",
"the",
"date",
"is",
"in",
"US",
"/",
"Pacific",
"time",
"zone",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L219-L237 |
yougov/pmxbot | pmxbot/logging.py | strike | def strike(channel, nick, rest):
"Strike last <n> statements from the record"
yield NoLog
rest = rest.strip()
if not rest:
count = 1
else:
if not rest.isdigit():
yield "Strike how many? Argument must be a positive integer."
raise StopIteration
count = int(rest)
try:
struck = Logger.store.strike(cha... | python | def strike(channel, nick, rest):
"Strike last <n> statements from the record"
yield NoLog
rest = rest.strip()
if not rest:
count = 1
else:
if not rest.isdigit():
yield "Strike how many? Argument must be a positive integer."
raise StopIteration
count = int(rest)
try:
struck = Logger.store.strike(cha... | [
"def",
"strike",
"(",
"channel",
",",
"nick",
",",
"rest",
")",
":",
"yield",
"NoLog",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"not",
"rest",
":",
"count",
"=",
"1",
"else",
":",
"if",
"not",
"rest",
".",
"isdigit",
"(",
")",
":",
"y... | Strike last <n> statements from the record | [
"Strike",
"last",
"<n",
">",
"statements",
"from",
"the",
"record"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L468-L488 |
yougov/pmxbot | pmxbot/logging.py | where | def where(channel, nick, rest):
"When did pmxbot last see <nick> speak?"
onick = rest.strip()
last = Logger.store.last_seen(onick)
if last:
tm, chan = last
tmpl = "I last saw {onick} speak at {tm} in channel #{chan}"
return tmpl.format(tm=tm, chan=chan, onick=onick)
else:
return "Sorry! I don't have any r... | python | def where(channel, nick, rest):
"When did pmxbot last see <nick> speak?"
onick = rest.strip()
last = Logger.store.last_seen(onick)
if last:
tm, chan = last
tmpl = "I last saw {onick} speak at {tm} in channel #{chan}"
return tmpl.format(tm=tm, chan=chan, onick=onick)
else:
return "Sorry! I don't have any r... | [
"def",
"where",
"(",
"channel",
",",
"nick",
",",
"rest",
")",
":",
"onick",
"=",
"rest",
".",
"strip",
"(",
")",
"last",
"=",
"Logger",
".",
"store",
".",
"last_seen",
"(",
"onick",
")",
"if",
"last",
":",
"tm",
",",
"chan",
"=",
"last",
"tmpl",... | When did pmxbot last see <nick> speak? | [
"When",
"did",
"pmxbot",
"last",
"see",
"<nick",
">",
"speak?"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L492-L501 |
yougov/pmxbot | pmxbot/logging.py | logs | def logs(channel):
"Where can one find the logs?"
default_url = 'http://' + socket.getfqdn()
base = pmxbot.config.get('logs URL', default_url)
logged_channel = channel in pmxbot.config.log_channels
path = '/channel/' + channel.lstrip('#') if logged_channel else '/'
return urllib.parse.urljoin(base, path) | python | def logs(channel):
"Where can one find the logs?"
default_url = 'http://' + socket.getfqdn()
base = pmxbot.config.get('logs URL', default_url)
logged_channel = channel in pmxbot.config.log_channels
path = '/channel/' + channel.lstrip('#') if logged_channel else '/'
return urllib.parse.urljoin(base, path) | [
"def",
"logs",
"(",
"channel",
")",
":",
"default_url",
"=",
"'http://'",
"+",
"socket",
".",
"getfqdn",
"(",
")",
"base",
"=",
"pmxbot",
".",
"config",
".",
"get",
"(",
"'logs URL'",
",",
"default_url",
")",
"logged_channel",
"=",
"channel",
"in",
"pmxb... | Where can one find the logs? | [
"Where",
"can",
"one",
"find",
"the",
"logs?"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L524-L530 |
yougov/pmxbot | pmxbot/logging.py | log | def log(channel, rest):
"""
Enable or disable logging for a channel;
use 'please' to start logging and 'stop please' to stop.
"""
words = [s.lower() for s in rest.split()]
if 'please' not in words:
return
include = 'stop' not in rest
existing = set(pmxbot.config.log_channels)
# add the channel if include, ot... | python | def log(channel, rest):
"""
Enable or disable logging for a channel;
use 'please' to start logging and 'stop please' to stop.
"""
words = [s.lower() for s in rest.split()]
if 'please' not in words:
return
include = 'stop' not in rest
existing = set(pmxbot.config.log_channels)
# add the channel if include, ot... | [
"def",
"log",
"(",
"channel",
",",
"rest",
")",
":",
"words",
"=",
"[",
"s",
".",
"lower",
"(",
")",
"for",
"s",
"in",
"rest",
".",
"split",
"(",
")",
"]",
"if",
"'please'",
"not",
"in",
"words",
":",
"return",
"include",
"=",
"'stop'",
"not",
... | Enable or disable logging for a channel;
use 'please' to start logging and 'stop please' to stop. | [
"Enable",
"or",
"disable",
"logging",
"for",
"a",
"channel",
";",
"use",
"please",
"to",
"start",
"logging",
"and",
"stop",
"please",
"to",
"stop",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L534-L546 |
yougov/pmxbot | pmxbot/logging.py | MongoDBLogger._add_recent | def _add_recent(self, doc, logged_id):
"Keep a tab on the most recent message for each channel"
spec = dict(channel=doc['channel'])
doc['ref'] = logged_id
doc.pop('_id')
self._recent.replace_one(spec, doc, upsert=True) | python | def _add_recent(self, doc, logged_id):
"Keep a tab on the most recent message for each channel"
spec = dict(channel=doc['channel'])
doc['ref'] = logged_id
doc.pop('_id')
self._recent.replace_one(spec, doc, upsert=True) | [
"def",
"_add_recent",
"(",
"self",
",",
"doc",
",",
"logged_id",
")",
":",
"spec",
"=",
"dict",
"(",
"channel",
"=",
"doc",
"[",
"'channel'",
"]",
")",
"doc",
"[",
"'ref'",
"]",
"=",
"logged_id",
"doc",
".",
"pop",
"(",
"'_id'",
")",
"self",
".",
... | Keep a tab on the most recent message for each channel | [
"Keep",
"a",
"tab",
"on",
"the",
"most",
"recent",
"message",
"for",
"each",
"channel"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L256-L261 |
yougov/pmxbot | pmxbot/logging.py | FullTextMongoDBLogger._has_fulltext | def _has_fulltext(cls, uri):
"""
Enable full text search on the messages if possible and return True.
If the full text search cannot be enabled, then return False.
"""
coll = cls._get_collection(uri)
with ExceptionTrap(storage.pymongo.errors.OperationFailure) as trap:
coll.create_index([('message', 'text... | python | def _has_fulltext(cls, uri):
"""
Enable full text search on the messages if possible and return True.
If the full text search cannot be enabled, then return False.
"""
coll = cls._get_collection(uri)
with ExceptionTrap(storage.pymongo.errors.OperationFailure) as trap:
coll.create_index([('message', 'text... | [
"def",
"_has_fulltext",
"(",
"cls",
",",
"uri",
")",
":",
"coll",
"=",
"cls",
".",
"_get_collection",
"(",
"uri",
")",
"with",
"ExceptionTrap",
"(",
"storage",
".",
"pymongo",
".",
"errors",
".",
"OperationFailure",
")",
"as",
"trap",
":",
"coll",
".",
... | Enable full text search on the messages if possible and return True.
If the full text search cannot be enabled, then return False. | [
"Enable",
"full",
"text",
"search",
"on",
"the",
"messages",
"if",
"possible",
"and",
"return",
"True",
".",
"If",
"the",
"full",
"text",
"search",
"cannot",
"be",
"enabled",
"then",
"return",
"False",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/logging.py#L422-L430 |
yougov/pmxbot | pmxbot/slack.py | Bot._find_user_channel | def _find_user_channel(self, username):
"""
Use slacker to resolve the username to an opened IM channel
"""
user_id = self.slacker.users.get_user_id(username)
im = user_id and self.slacker.im.open(user_id).body['channel']['id']
return im and self.slack.server.channels.find(im) | python | def _find_user_channel(self, username):
"""
Use slacker to resolve the username to an opened IM channel
"""
user_id = self.slacker.users.get_user_id(username)
im = user_id and self.slacker.im.open(user_id).body['channel']['id']
return im and self.slack.server.channels.find(im) | [
"def",
"_find_user_channel",
"(",
"self",
",",
"username",
")",
":",
"user_id",
"=",
"self",
".",
"slacker",
".",
"users",
".",
"get_user_id",
"(",
"username",
")",
"im",
"=",
"user_id",
"and",
"self",
".",
"slacker",
".",
"im",
".",
"open",
"(",
"user... | Use slacker to resolve the username to an opened IM channel | [
"Use",
"slacker",
"to",
"resolve",
"the",
"username",
"to",
"an",
"opened",
"IM",
"channel"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/slack.py#L65-L71 |
yougov/pmxbot | pmxbot/slack.py | Bot.transmit | def transmit(self, channel, message):
"""
Send the message to Slack.
:param channel: channel or user to whom the message should be sent.
If a ``thread`` attribute is present, that thread ID is used.
:param str message: message to send.
"""
target = (
self.slack.server.channels.find(channel)
or sel... | python | def transmit(self, channel, message):
"""
Send the message to Slack.
:param channel: channel or user to whom the message should be sent.
If a ``thread`` attribute is present, that thread ID is used.
:param str message: message to send.
"""
target = (
self.slack.server.channels.find(channel)
or sel... | [
"def",
"transmit",
"(",
"self",
",",
"channel",
",",
"message",
")",
":",
"target",
"=",
"(",
"self",
".",
"slack",
".",
"server",
".",
"channels",
".",
"find",
"(",
"channel",
")",
"or",
"self",
".",
"_find_user_channel",
"(",
"username",
"=",
"channe... | Send the message to Slack.
:param channel: channel or user to whom the message should be sent.
If a ``thread`` attribute is present, that thread ID is used.
:param str message: message to send. | [
"Send",
"the",
"message",
"to",
"Slack",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/slack.py#L73-L87 |
yougov/pmxbot | pmxbot/util.py | wchoice | def wchoice(d):
"""
Given a dictionary of word: proportion, return a word randomly selected
from the keys weighted by proportion.
>>> wchoice({'a': 0, 'b': 1})
'b'
>>> choices = [wchoice({'a': 1, 'b': 2}) for x in range(1000)]
Statistically speaking, choices should be .5 a:b
>>> ratio = choices.count('a') / c... | python | def wchoice(d):
"""
Given a dictionary of word: proportion, return a word randomly selected
from the keys weighted by proportion.
>>> wchoice({'a': 0, 'b': 1})
'b'
>>> choices = [wchoice({'a': 1, 'b': 2}) for x in range(1000)]
Statistically speaking, choices should be .5 a:b
>>> ratio = choices.count('a') / c... | [
"def",
"wchoice",
"(",
"d",
")",
":",
"total",
"=",
"sum",
"(",
"d",
".",
"values",
"(",
")",
")",
"target",
"=",
"random",
".",
"random",
"(",
")",
"*",
"total",
"# elect the first item which pushes the count over target",
"count",
"=",
"0",
"for",
"word"... | Given a dictionary of word: proportion, return a word randomly selected
from the keys weighted by proportion.
>>> wchoice({'a': 0, 'b': 1})
'b'
>>> choices = [wchoice({'a': 1, 'b': 2}) for x in range(1000)]
Statistically speaking, choices should be .5 a:b
>>> ratio = choices.count('a') / choices.count('b')
>>>... | [
"Given",
"a",
"dictionary",
"of",
"word",
":",
"proportion",
"return",
"a",
"word",
"randomly",
"selected",
"from",
"the",
"keys",
"weighted",
"by",
"proportion",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/util.py#L20-L41 |
yougov/pmxbot | pmxbot/util.py | splitem | def splitem(query):
"""
Split a query into choices
>>> splitem('dog, cat')
['dog', 'cat']
Disregards trailing punctuation.
>>> splitem('dogs, cats???')
['dogs', 'cats']
>>> splitem('cats!!!')
['cats']
Allow or
>>> splitem('dogs, cats or prarie dogs?')
['dogs', 'cats', 'prarie dogs']
Honors serial comm... | python | def splitem(query):
"""
Split a query into choices
>>> splitem('dog, cat')
['dog', 'cat']
Disregards trailing punctuation.
>>> splitem('dogs, cats???')
['dogs', 'cats']
>>> splitem('cats!!!')
['cats']
Allow or
>>> splitem('dogs, cats or prarie dogs?')
['dogs', 'cats', 'prarie dogs']
Honors serial comm... | [
"def",
"splitem",
"(",
"query",
")",
":",
"prompt",
",",
"sep",
",",
"query",
"=",
"query",
".",
"rstrip",
"(",
"'?.!'",
")",
".",
"rpartition",
"(",
"':'",
")",
"choices",
"=",
"query",
".",
"split",
"(",
"','",
")",
"choices",
"[",
"-",
"1",
":... | Split a query into choices
>>> splitem('dog, cat')
['dog', 'cat']
Disregards trailing punctuation.
>>> splitem('dogs, cats???')
['dogs', 'cats']
>>> splitem('cats!!!')
['cats']
Allow or
>>> splitem('dogs, cats or prarie dogs?')
['dogs', 'cats', 'prarie dogs']
Honors serial commas
>>> splitem('dogs, cat... | [
"Split",
"a",
"query",
"into",
"choices"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/util.py#L44-L75 |
yougov/pmxbot | pmxbot/util.py | lookup | def lookup(word):
'''
Get a definition for a word (uses Wordnik)
'''
_patch_wordnik()
# Jason's key - do not abuse
key = 'edc4b9b94b341eeae350e087c2e05d2f5a2a9e0478cefc6dc'
client = wordnik.swagger.ApiClient(key, 'http://api.wordnik.com/v4')
words = wordnik.WordApi.WordApi(client)
definitions = words.getDefini... | python | def lookup(word):
'''
Get a definition for a word (uses Wordnik)
'''
_patch_wordnik()
# Jason's key - do not abuse
key = 'edc4b9b94b341eeae350e087c2e05d2f5a2a9e0478cefc6dc'
client = wordnik.swagger.ApiClient(key, 'http://api.wordnik.com/v4')
words = wordnik.WordApi.WordApi(client)
definitions = words.getDefini... | [
"def",
"lookup",
"(",
"word",
")",
":",
"_patch_wordnik",
"(",
")",
"# Jason's key - do not abuse",
"key",
"=",
"'edc4b9b94b341eeae350e087c2e05d2f5a2a9e0478cefc6dc'",
"client",
"=",
"wordnik",
".",
"swagger",
".",
"ApiClient",
"(",
"key",
",",
"'http://api.wordnik.com/v... | Get a definition for a word (uses Wordnik) | [
"Get",
"a",
"definition",
"for",
"a",
"word",
"(",
"uses",
"Wordnik",
")"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/util.py#L107-L120 |
yougov/pmxbot | pmxbot/util.py | urban_lookup | def urban_lookup(word):
'''
Return a Urban Dictionary definition for a word or None if no result was
found.
'''
url = "http://api.urbandictionary.com/v0/define"
params = dict(term=word)
resp = requests.get(url, params=params)
resp.raise_for_status()
res = resp.json()
if not res['list']:
return
return res['... | python | def urban_lookup(word):
'''
Return a Urban Dictionary definition for a word or None if no result was
found.
'''
url = "http://api.urbandictionary.com/v0/define"
params = dict(term=word)
resp = requests.get(url, params=params)
resp.raise_for_status()
res = resp.json()
if not res['list']:
return
return res['... | [
"def",
"urban_lookup",
"(",
"word",
")",
":",
"url",
"=",
"\"http://api.urbandictionary.com/v0/define\"",
"params",
"=",
"dict",
"(",
"term",
"=",
"word",
")",
"resp",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"params",
"=",
"params",
")",
"resp",
".",... | Return a Urban Dictionary definition for a word or None if no result was
found. | [
"Return",
"a",
"Urban",
"Dictionary",
"definition",
"for",
"a",
"word",
"or",
"None",
"if",
"no",
"result",
"was",
"found",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/util.py#L126-L138 |
yougov/pmxbot | pmxbot/util.py | passagg | def passagg(recipient, sender):
"""
Generate a passive-aggressive statement to recipient from sender.
"""
adj = random.choice(pmxbot.phrases.adjs)
if random.choice([False, True]):
# address the recipient last
lead = ""
trail = recipient if not recipient else ", %s" % recipient
else:
# address the recipien... | python | def passagg(recipient, sender):
"""
Generate a passive-aggressive statement to recipient from sender.
"""
adj = random.choice(pmxbot.phrases.adjs)
if random.choice([False, True]):
# address the recipient last
lead = ""
trail = recipient if not recipient else ", %s" % recipient
else:
# address the recipien... | [
"def",
"passagg",
"(",
"recipient",
",",
"sender",
")",
":",
"adj",
"=",
"random",
".",
"choice",
"(",
"pmxbot",
".",
"phrases",
".",
"adjs",
")",
"if",
"random",
".",
"choice",
"(",
"[",
"False",
",",
"True",
"]",
")",
":",
"# address the recipient la... | Generate a passive-aggressive statement to recipient from sender. | [
"Generate",
"a",
"passive",
"-",
"aggressive",
"statement",
"to",
"recipient",
"from",
"sender",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/util.py#L165-L183 |
yougov/pmxbot | pmxbot/config_.py | config | def config(client, event, channel, nick, rest):
"Change the running config, something like a=b or a+=b or a-=b"
pattern = re.compile(r'(?P<key>\w+)\s*(?P<op>[+-]?=)\s*(?P<value>.*)$')
match = pattern.match(rest)
if not match:
return "Command not recognized"
res = match.groupdict()
key = res['key']
op = res['op... | python | def config(client, event, channel, nick, rest):
"Change the running config, something like a=b or a+=b or a-=b"
pattern = re.compile(r'(?P<key>\w+)\s*(?P<op>[+-]?=)\s*(?P<value>.*)$')
match = pattern.match(rest)
if not match:
return "Command not recognized"
res = match.groupdict()
key = res['key']
op = res['op... | [
"def",
"config",
"(",
"client",
",",
"event",
",",
"channel",
",",
"nick",
",",
"rest",
")",
":",
"pattern",
"=",
"re",
".",
"compile",
"(",
"r'(?P<key>\\w+)\\s*(?P<op>[+-]?=)\\s*(?P<value>.*)$'",
")",
"match",
"=",
"pattern",
".",
"match",
"(",
"rest",
")",... | Change the running config, something like a=b or a+=b or a-=b | [
"Change",
"the",
"running",
"config",
"something",
"like",
"a",
"=",
"b",
"or",
"a",
"+",
"=",
"b",
"or",
"a",
"-",
"=",
"b"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/config_.py#L10-L33 |
yougov/pmxbot | pmxbot/itertools.py | trap_exceptions | def trap_exceptions(results, handler, exceptions=Exception):
"""
Iterate through the results, but if an exception occurs, stop
processing the results and instead replace
the results with the output from the exception handler.
"""
try:
for result in results:
yield result
except exceptions as exc:
for resul... | python | def trap_exceptions(results, handler, exceptions=Exception):
"""
Iterate through the results, but if an exception occurs, stop
processing the results and instead replace
the results with the output from the exception handler.
"""
try:
for result in results:
yield result
except exceptions as exc:
for resul... | [
"def",
"trap_exceptions",
"(",
"results",
",",
"handler",
",",
"exceptions",
"=",
"Exception",
")",
":",
"try",
":",
"for",
"result",
"in",
"results",
":",
"yield",
"result",
"except",
"exceptions",
"as",
"exc",
":",
"for",
"result",
"in",
"always_iterable",... | Iterate through the results, but if an exception occurs, stop
processing the results and instead replace
the results with the output from the exception handler. | [
"Iterate",
"through",
"the",
"results",
"but",
"if",
"an",
"exception",
"occurs",
"stop",
"processing",
"the",
"results",
"and",
"instead",
"replace",
"the",
"results",
"with",
"the",
"output",
"from",
"the",
"exception",
"handler",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/itertools.py#L13-L24 |
yougov/pmxbot | pmxbot/quotes.py | quote | def quote(rest):
"""
If passed with nothing then get a random quote. If passed with some
string then search for that. If prepended with "add:" then add it to the
db, eg "!quote add: drivers: I only work here because of pmxbot!".
Delete an individual quote by prepending "del:" and passing a search
matching exactly... | python | def quote(rest):
"""
If passed with nothing then get a random quote. If passed with some
string then search for that. If prepended with "add:" then add it to the
db, eg "!quote add: drivers: I only work here because of pmxbot!".
Delete an individual quote by prepending "del:" and passing a search
matching exactly... | [
"def",
"quote",
"(",
"rest",
")",
":",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"rest",
".",
"startswith",
"(",
"'add: '",
")",
"or",
"rest",
".",
"startswith",
"(",
"'add '",
")",
":",
"quote_to_add",
"=",
"rest",
".",
"split",
"(",
"' '... | If passed with nothing then get a random quote. If passed with some
string then search for that. If prepended with "add:" then add it to the
db, eg "!quote add: drivers: I only work here because of pmxbot!".
Delete an individual quote by prepending "del:" and passing a search
matching exactly one query. | [
"If",
"passed",
"with",
"nothing",
"then",
"get",
"a",
"random",
"quote",
".",
"If",
"passed",
"with",
"some",
"string",
"then",
"search",
"for",
"that",
".",
"If",
"prepended",
"with",
"add",
":",
"then",
"add",
"it",
"to",
"the",
"db",
"eg",
"!quote"... | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/quotes.py#L199-L220 |
yougov/pmxbot | pmxbot/quotes.py | MongoDBQuotes.delete | def delete(self, lookup):
"""
If exactly one quote matches, delete it. Otherwise,
raise a ValueError.
"""
lookup, num = self.split_num(lookup)
if num:
result = self.find_matches(lookup)[num - 1]
else:
result, = self.find_matches(lookup)
self.db.delete_one(result) | python | def delete(self, lookup):
"""
If exactly one quote matches, delete it. Otherwise,
raise a ValueError.
"""
lookup, num = self.split_num(lookup)
if num:
result = self.find_matches(lookup)[num - 1]
else:
result, = self.find_matches(lookup)
self.db.delete_one(result) | [
"def",
"delete",
"(",
"self",
",",
"lookup",
")",
":",
"lookup",
",",
"num",
"=",
"self",
".",
"split_num",
"(",
"lookup",
")",
"if",
"num",
":",
"result",
"=",
"self",
".",
"find_matches",
"(",
"lookup",
")",
"[",
"num",
"-",
"1",
"]",
"else",
"... | If exactly one quote matches, delete it. Otherwise,
raise a ValueError. | [
"If",
"exactly",
"one",
"quote",
"matches",
"delete",
"it",
".",
"Otherwise",
"raise",
"a",
"ValueError",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/quotes.py#L153-L163 |
yougov/pmxbot | pmxbot/stack.py | parse_index | def parse_index(index, items):
"""Return a list of 0-based index numbers from a (1-based) `index` str.
* A single item index, like `[3]`. Negative indices count backward from
the bottom; that is, the bottom-most item in a 3-item stack can be
identified by `[3]` or `[-1]`.
* A slice, shorthand f... | python | def parse_index(index, items):
"""Return a list of 0-based index numbers from a (1-based) `index` str.
* A single item index, like `[3]`. Negative indices count backward from
the bottom; that is, the bottom-most item in a 3-item stack can be
identified by `[3]` or `[-1]`.
* A slice, shorthand f... | [
"def",
"parse_index",
"(",
"index",
",",
"items",
")",
":",
"indices",
"=",
"[",
"]",
"if",
"index",
"is",
"None",
":",
"return",
"indices",
"for",
"atom",
"in",
"index",
".",
"split",
"(",
"\",\"",
")",
":",
"atom",
"=",
"atom",
".",
"strip",
"(",... | Return a list of 0-based index numbers from a (1-based) `index` str.
* A single item index, like `[3]`. Negative indices count backward from
the bottom; that is, the bottom-most item in a 3-item stack can be
identified by `[3]` or `[-1]`.
* A slice, shorthand for the entire inclusive range between ... | [
"Return",
"a",
"list",
"of",
"0",
"-",
"based",
"index",
"numbers",
"from",
"a",
"(",
"1",
"-",
"based",
")",
"index",
"str",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/stack.py#L214-L281 |
yougov/pmxbot | pmxbot/stack.py | stack | def stack(nick, rest):
'Manage short lists in pmxbot. See !stack help for more info'
atoms = [atom.strip() for atom in rest.split(' ', 1) if atom.strip()]
if len(atoms) == 0:
subcommand = "show"
rest = ""
elif len(atoms) == 1:
subcommand = atoms[0]
rest = ""
else:
... | python | def stack(nick, rest):
'Manage short lists in pmxbot. See !stack help for more info'
atoms = [atom.strip() for atom in rest.split(' ', 1) if atom.strip()]
if len(atoms) == 0:
subcommand = "show"
rest = ""
elif len(atoms) == 1:
subcommand = atoms[0]
rest = ""
else:
... | [
"def",
"stack",
"(",
"nick",
",",
"rest",
")",
":",
"atoms",
"=",
"[",
"atom",
".",
"strip",
"(",
")",
"for",
"atom",
"in",
"rest",
".",
"split",
"(",
"' '",
",",
"1",
")",
"if",
"atom",
".",
"strip",
"(",
")",
"]",
"if",
"len",
"(",
"atoms",... | Manage short lists in pmxbot. See !stack help for more info | [
"Manage",
"short",
"lists",
"in",
"pmxbot",
".",
"See",
"!stack",
"help",
"for",
"more",
"info"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/stack.py#L293-L393 |
yougov/pmxbot | pmxbot/irc.py | LoggingCommandBot._get_wrapper | def _get_wrapper():
"""
Get a socket wrapper based on SSL config.
"""
if not pmxbot.config.get('use_ssl', False):
return lambda x: x
return importlib.import_module('ssl').wrap_socket | python | def _get_wrapper():
"""
Get a socket wrapper based on SSL config.
"""
if not pmxbot.config.get('use_ssl', False):
return lambda x: x
return importlib.import_module('ssl').wrap_socket | [
"def",
"_get_wrapper",
"(",
")",
":",
"if",
"not",
"pmxbot",
".",
"config",
".",
"get",
"(",
"'use_ssl'",
",",
"False",
")",
":",
"return",
"lambda",
"x",
":",
"x",
"return",
"importlib",
".",
"import_module",
"(",
"'ssl'",
")",
".",
"wrap_socket"
] | Get a socket wrapper based on SSL config. | [
"Get",
"a",
"socket",
"wrapper",
"based",
"on",
"SSL",
"config",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/irc.py#L79-L85 |
yougov/pmxbot | pmxbot/irc.py | LoggingCommandBot.transmit | def transmit(self, channel, msg):
r"""
Transmit the message (or action) and return what was transmitted.
>>> ap = LoggingCommandBot.action_pattern
>>> ap.match('foo').groups()
(None, 'foo')
>>> ap.match('foo\nbar\n').group(2)
'foo\nbar\n'
>>> is_action, msg = ap.match('/me is feeling fine today').grou... | python | def transmit(self, channel, msg):
r"""
Transmit the message (or action) and return what was transmitted.
>>> ap = LoggingCommandBot.action_pattern
>>> ap.match('foo').groups()
(None, 'foo')
>>> ap.match('foo\nbar\n').group(2)
'foo\nbar\n'
>>> is_action, msg = ap.match('/me is feeling fine today').grou... | [
"def",
"transmit",
"(",
"self",
",",
"channel",
",",
"msg",
")",
":",
"is_action",
",",
"msg",
"=",
"self",
".",
"action_pattern",
".",
"match",
"(",
"msg",
")",
".",
"groups",
"(",
")",
"func",
"=",
"self",
".",
"_conn",
".",
"action",
"if",
"is_a... | r"""
Transmit the message (or action) and return what was transmitted.
>>> ap = LoggingCommandBot.action_pattern
>>> ap.match('foo').groups()
(None, 'foo')
>>> ap.match('foo\nbar\n').group(2)
'foo\nbar\n'
>>> is_action, msg = ap.match('/me is feeling fine today').groups()
>>> bool(is_action)
True
... | [
"r",
"Transmit",
"the",
"message",
"(",
"or",
"action",
")",
"and",
"return",
"what",
"was",
"transmitted",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/irc.py#L89-L117 |
MeaningCloud/meaningcloud-python | meaningcloud/Response.py | Response.getStatusCode | def getStatusCode(self):
"""
Returns the code of the status or None if it does not exist
:return:
Status code of the response
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('code' in self._response['status'].keys... | python | def getStatusCode(self):
"""
Returns the code of the status or None if it does not exist
:return:
Status code of the response
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('code' in self._response['status'].keys... | [
"def",
"getStatusCode",
"(",
"self",
")",
":",
"if",
"'status'",
"in",
"self",
".",
"_response",
".",
"keys",
"(",
")",
":",
"if",
"(",
"self",
".",
"_response",
"[",
"'status'",
"]",
"is",
"not",
"None",
")",
"and",
"(",
"'code'",
"in",
"self",
".... | Returns the code of the status or None if it does not exist
:return:
Status code of the response | [
"Returns",
"the",
"code",
"of",
"the",
"status",
"or",
"None",
"if",
"it",
"does",
"not",
"exist"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Response.py#L37-L52 |
MeaningCloud/meaningcloud-python | meaningcloud/Response.py | Response.getStatusMsg | def getStatusMsg(self):
"""
Returns the message of the status or an empty string if it does not exist
:return:
Status message of the response
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('msg' in self._response... | python | def getStatusMsg(self):
"""
Returns the message of the status or an empty string if it does not exist
:return:
Status message of the response
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('msg' in self._response... | [
"def",
"getStatusMsg",
"(",
"self",
")",
":",
"if",
"'status'",
"in",
"self",
".",
"_response",
".",
"keys",
"(",
")",
":",
"if",
"(",
"self",
".",
"_response",
"[",
"'status'",
"]",
"is",
"not",
"None",
")",
"and",
"(",
"'msg'",
"in",
"self",
".",... | Returns the message of the status or an empty string if it does not exist
:return:
Status message of the response | [
"Returns",
"the",
"message",
"of",
"the",
"status",
"or",
"an",
"empty",
"string",
"if",
"it",
"does",
"not",
"exist"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Response.py#L54-L66 |
MeaningCloud/meaningcloud-python | meaningcloud/Response.py | Response.getConsumedCredits | def getConsumedCredits(self):
"""
Returns the credit consumed by the request made
:return:
String with the number of credits consumed
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('credits' in self._response['st... | python | def getConsumedCredits(self):
"""
Returns the credit consumed by the request made
:return:
String with the number of credits consumed
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('credits' in self._response['st... | [
"def",
"getConsumedCredits",
"(",
"self",
")",
":",
"if",
"'status'",
"in",
"self",
".",
"_response",
".",
"keys",
"(",
")",
":",
"if",
"(",
"self",
".",
"_response",
"[",
"'status'",
"]",
"is",
"not",
"None",
")",
"and",
"(",
"'credits'",
"in",
"sel... | Returns the credit consumed by the request made
:return:
String with the number of credits consumed | [
"Returns",
"the",
"credit",
"consumed",
"by",
"the",
"request",
"made"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Response.py#L68-L85 |
MeaningCloud/meaningcloud-python | meaningcloud/Response.py | Response.getRemainingCredits | def getRemainingCredits(self):
"""
Returns the remaining credits for the license key used after the request was made
:return:
String with remaining credits
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('remainin... | python | def getRemainingCredits(self):
"""
Returns the remaining credits for the license key used after the request was made
:return:
String with remaining credits
"""
if 'status' in self._response.keys():
if (self._response['status'] is not None) and ('remainin... | [
"def",
"getRemainingCredits",
"(",
"self",
")",
":",
"if",
"'status'",
"in",
"self",
".",
"_response",
".",
"keys",
"(",
")",
":",
"if",
"(",
"self",
".",
"_response",
"[",
"'status'",
"]",
"is",
"not",
"None",
")",
"and",
"(",
"'remaining_credits'",
"... | Returns the remaining credits for the license key used after the request was made
:return:
String with remaining credits | [
"Returns",
"the",
"remaining",
"credits",
"for",
"the",
"license",
"key",
"used",
"after",
"the",
"request",
"was",
"made"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Response.py#L87-L104 |
MeaningCloud/meaningcloud-python | meaningcloud/Response.py | Response.getResults | def getResults(self):
"""
Returns the results from the API without the status of the request
:return:
Dictionary with the results
"""
results = self._response.copy()
if 'status' in self._response.keys():
if results['status'] is not None:
... | python | def getResults(self):
"""
Returns the results from the API without the status of the request
:return:
Dictionary with the results
"""
results = self._response.copy()
if 'status' in self._response.keys():
if results['status'] is not None:
... | [
"def",
"getResults",
"(",
"self",
")",
":",
"results",
"=",
"self",
".",
"_response",
".",
"copy",
"(",
")",
"if",
"'status'",
"in",
"self",
".",
"_response",
".",
"keys",
"(",
")",
":",
"if",
"results",
"[",
"'status'",
"]",
"is",
"not",
"None",
"... | Returns the results from the API without the status of the request
:return:
Dictionary with the results | [
"Returns",
"the",
"results",
"from",
"the",
"API",
"without",
"the",
"status",
"of",
"the",
"request"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Response.py#L106-L120 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_forces | def get_forces(self):
"""
Get a list of all police forces. Uses the forces_ API call.
.. _forces: https://data.police.uk/docs/method/forces/
:rtype: list
:return: A list of :class:`forces.Force` objects (one for each police
force represented in the API)
... | python | def get_forces(self):
"""
Get a list of all police forces. Uses the forces_ API call.
.. _forces: https://data.police.uk/docs/method/forces/
:rtype: list
:return: A list of :class:`forces.Force` objects (one for each police
force represented in the API)
... | [
"def",
"get_forces",
"(",
"self",
")",
":",
"forces",
"=",
"[",
"]",
"for",
"f",
"in",
"self",
".",
"service",
".",
"request",
"(",
"'GET'",
",",
"'forces'",
")",
":",
"forces",
".",
"append",
"(",
"Force",
"(",
"self",
",",
"id",
"=",
"f",
"[",
... | Get a list of all police forces. Uses the forces_ API call.
.. _forces: https://data.police.uk/docs/method/forces/
:rtype: list
:return: A list of :class:`forces.Force` objects (one for each police
force represented in the API) | [
"Get",
"a",
"list",
"of",
"all",
"police",
"forces",
".",
"Uses",
"the",
"forces_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L31-L45 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_neighbourhoods | def get_neighbourhoods(self, force):
"""
Get a list of all neighbourhoods for a force. Uses the neighbourhoods_
API call.
.. _neighbourhoods: https://data.police.uk/docs/method/neighbourhoods/
:param force: The force to get neighbourhoods for (either by ID or
... | python | def get_neighbourhoods(self, force):
"""
Get a list of all neighbourhoods for a force. Uses the neighbourhoods_
API call.
.. _neighbourhoods: https://data.police.uk/docs/method/neighbourhoods/
:param force: The force to get neighbourhoods for (either by ID or
... | [
"def",
"get_neighbourhoods",
"(",
"self",
",",
"force",
")",
":",
"if",
"not",
"isinstance",
"(",
"force",
",",
"Force",
")",
":",
"force",
"=",
"Force",
"(",
"self",
",",
"id",
"=",
"force",
")",
"neighbourhoods",
"=",
"[",
"]",
"for",
"n",
"in",
... | Get a list of all neighbourhoods for a force. Uses the neighbourhoods_
API call.
.. _neighbourhoods: https://data.police.uk/docs/method/neighbourhoods/
:param force: The force to get neighbourhoods for (either by ID or
:class:`forces.Force` object)
:type force: st... | [
"Get",
"a",
"list",
"of",
"all",
"neighbourhoods",
"for",
"a",
"force",
".",
"Uses",
"the",
"neighbourhoods_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L60-L82 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_neighbourhood | def get_neighbourhood(self, force, id, **attrs):
"""
Get a specific neighbourhood. Uses the neighbourhood_ API call.
.. _neighbourhood: https://data.police.uk/docs/method/neighbourhood/
:param force: The force within which the neighbourhood resides (either
by ID o... | python | def get_neighbourhood(self, force, id, **attrs):
"""
Get a specific neighbourhood. Uses the neighbourhood_ API call.
.. _neighbourhood: https://data.police.uk/docs/method/neighbourhood/
:param force: The force within which the neighbourhood resides (either
by ID o... | [
"def",
"get_neighbourhood",
"(",
"self",
",",
"force",
",",
"id",
",",
"*",
"*",
"attrs",
")",
":",
"if",
"not",
"isinstance",
"(",
"force",
",",
"Force",
")",
":",
"force",
"=",
"Force",
"(",
"self",
",",
"id",
"=",
"force",
",",
"*",
"*",
"attr... | Get a specific neighbourhood. Uses the neighbourhood_ API call.
.. _neighbourhood: https://data.police.uk/docs/method/neighbourhood/
:param force: The force within which the neighbourhood resides (either
by ID or :class:`forces.Force` object)
:type force: str or Force
... | [
"Get",
"a",
"specific",
"neighbourhood",
".",
"Uses",
"the",
"neighbourhood_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L84-L101 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.locate_neighbourhood | def locate_neighbourhood(self, lat, lng):
"""
Find a neighbourhood by location. Uses the locate-neighbourhood_ API
call.
.. _locate-neighbourhood:
https://data.police.uk/docs/method/neighbourhood-locate/
:param lat: The latitude of the location.
:type lat: f... | python | def locate_neighbourhood(self, lat, lng):
"""
Find a neighbourhood by location. Uses the locate-neighbourhood_ API
call.
.. _locate-neighbourhood:
https://data.police.uk/docs/method/neighbourhood-locate/
:param lat: The latitude of the location.
:type lat: f... | [
"def",
"locate_neighbourhood",
"(",
"self",
",",
"lat",
",",
"lng",
")",
":",
"method",
"=",
"'locate-neighbourhood'",
"q",
"=",
"'%s,%s'",
"%",
"(",
"lat",
",",
"lng",
")",
"try",
":",
"result",
"=",
"self",
".",
"service",
".",
"request",
"(",
"'GET'... | Find a neighbourhood by location. Uses the locate-neighbourhood_ API
call.
.. _locate-neighbourhood:
https://data.police.uk/docs/method/neighbourhood-locate/
:param lat: The latitude of the location.
:type lat: float or str
:param lng: The longitude of the location.... | [
"Find",
"a",
"neighbourhood",
"by",
"location",
".",
"Uses",
"the",
"locate",
"-",
"neighbourhood_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L103-L127 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crime_categories | def get_crime_categories(self, date=None):
"""
Get a list of crime categories, valid for a particular date. Uses the
crime-categories_ API call.
.. _crime-categories:
https://data.police.uk/docs/method/crime-categories/
:rtype: list
:param date: The date of ... | python | def get_crime_categories(self, date=None):
"""
Get a list of crime categories, valid for a particular date. Uses the
crime-categories_ API call.
.. _crime-categories:
https://data.police.uk/docs/method/crime-categories/
:rtype: list
:param date: The date of ... | [
"def",
"get_crime_categories",
"(",
"self",
",",
"date",
"=",
"None",
")",
":",
"return",
"sorted",
"(",
"self",
".",
"_get_crime_categories",
"(",
"date",
"=",
"date",
")",
".",
"values",
"(",
")",
",",
"key",
"=",
"lambda",
"c",
":",
"c",
".",
"nam... | Get a list of crime categories, valid for a particular date. Uses the
crime-categories_ API call.
.. _crime-categories:
https://data.police.uk/docs/method/crime-categories/
:rtype: list
:param date: The date of the crime categories to get.
:type date: str or None
... | [
"Get",
"a",
"list",
"of",
"crime",
"categories",
"valid",
"for",
"a",
"particular",
"date",
".",
"Uses",
"the",
"crime",
"-",
"categories_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L171-L187 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crime_category | def get_crime_category(self, id, date=None):
"""
Get a particular crime category by ID, valid at a particular date. Uses
the crime-categories_ API call.
:rtype: CrimeCategory
:param str id: The ID of the crime category to get.
:param date: The date that the given crime c... | python | def get_crime_category(self, id, date=None):
"""
Get a particular crime category by ID, valid at a particular date. Uses
the crime-categories_ API call.
:rtype: CrimeCategory
:param str id: The ID of the crime category to get.
:param date: The date that the given crime c... | [
"def",
"get_crime_category",
"(",
"self",
",",
"id",
",",
"date",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"_get_crime_categories",
"(",
"date",
"=",
"date",
")",
"[",
"id",
"]",
"except",
"KeyError",
":",
"raise",
"InvalidCategoryExceptio... | Get a particular crime category by ID, valid at a particular date. Uses
the crime-categories_ API call.
:rtype: CrimeCategory
:param str id: The ID of the crime category to get.
:param date: The date that the given crime category is valid for (the
latest date is use... | [
"Get",
"a",
"particular",
"crime",
"category",
"by",
"ID",
"valid",
"at",
"a",
"particular",
"date",
".",
"Uses",
"the",
"crime",
"-",
"categories_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L189-L207 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crime | def get_crime(self, persistent_id):
"""
Get a particular crime by persistent ID. Uses the outcomes-for-crime_
API call.
.. _outcomes-for-crime:
https://data.police.uk/docs/method/outcomes-for-crime/
:rtype: Crime
:param str persistent_id: The persistent ID o... | python | def get_crime(self, persistent_id):
"""
Get a particular crime by persistent ID. Uses the outcomes-for-crime_
API call.
.. _outcomes-for-crime:
https://data.police.uk/docs/method/outcomes-for-crime/
:rtype: Crime
:param str persistent_id: The persistent ID o... | [
"def",
"get_crime",
"(",
"self",
",",
"persistent_id",
")",
":",
"method",
"=",
"'outcomes-for-crime/%s'",
"%",
"persistent_id",
"response",
"=",
"self",
".",
"service",
".",
"request",
"(",
"'GET'",
",",
"method",
")",
"crime",
"=",
"Crime",
"(",
"self",
... | Get a particular crime by persistent ID. Uses the outcomes-for-crime_
API call.
.. _outcomes-for-crime:
https://data.police.uk/docs/method/outcomes-for-crime/
:rtype: Crime
:param str persistent_id: The persistent ID of the crime to get.
:return: The ``Crime`` with ... | [
"Get",
"a",
"particular",
"crime",
"by",
"persistent",
"ID",
".",
"Uses",
"the",
"outcomes",
"-",
"for",
"-",
"crime_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L209-L233 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crimes_point | def get_crimes_point(self, lat, lng, date=None, category=None):
"""
Get crimes within a 1-mile radius of a location. Uses the crime-street_
API call.
.. _crime-street: https//data.police.uk/docs/method/crime-street/
:rtype: list
:param lat: The latitude of the location.... | python | def get_crimes_point(self, lat, lng, date=None, category=None):
"""
Get crimes within a 1-mile radius of a location. Uses the crime-street_
API call.
.. _crime-street: https//data.police.uk/docs/method/crime-street/
:rtype: list
:param lat: The latitude of the location.... | [
"def",
"get_crimes_point",
"(",
"self",
",",
"lat",
",",
"lng",
",",
"date",
"=",
"None",
",",
"category",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"category",
",",
"CrimeCategory",
")",
":",
"category",
"=",
"category",
".",
"id",
"method",
"="... | Get crimes within a 1-mile radius of a location. Uses the crime-street_
API call.
.. _crime-street: https//data.police.uk/docs/method/crime-street/
:rtype: list
:param lat: The latitude of the location.
:type lat: float or str
:param lng: The longitude of the location.
... | [
"Get",
"crimes",
"within",
"a",
"1",
"-",
"mile",
"radius",
"of",
"a",
"location",
".",
"Uses",
"the",
"crime",
"-",
"street_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L235-L270 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crimes_area | def get_crimes_area(self, points, date=None, category=None):
"""
Get crimes within a custom area. Uses the crime-street_ API call.
.. _crime-street: https//data.police.uk/docs/method/crime-street/
:rtype: list
:param list points: A ``list`` of ``(lat, lng)`` tuples.
:pa... | python | def get_crimes_area(self, points, date=None, category=None):
"""
Get crimes within a custom area. Uses the crime-street_ API call.
.. _crime-street: https//data.police.uk/docs/method/crime-street/
:rtype: list
:param list points: A ``list`` of ``(lat, lng)`` tuples.
:pa... | [
"def",
"get_crimes_area",
"(",
"self",
",",
"points",
",",
"date",
"=",
"None",
",",
"category",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"category",
",",
"CrimeCategory",
")",
":",
"category",
"=",
"category",
".",
"id",
"method",
"=",
"'crimes-s... | Get crimes within a custom area. Uses the crime-street_ API call.
.. _crime-street: https//data.police.uk/docs/method/crime-street/
:rtype: list
:param list points: A ``list`` of ``(lat, lng)`` tuples.
:param date: The month in which the crimes were reported in the format
... | [
"Get",
"crimes",
"within",
"a",
"custom",
"area",
".",
"Uses",
"the",
"crime",
"-",
"street_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L272-L302 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crimes_location | def get_crimes_location(self, location_id, date=None):
"""
Get crimes at a particular snap-point location. Uses the
crimes-at-location_ API call.
.. _crimes-at-location:
https://data.police.uk/docs/method/crimes-at-location/
:rtype: list
:param int location_... | python | def get_crimes_location(self, location_id, date=None):
"""
Get crimes at a particular snap-point location. Uses the
crimes-at-location_ API call.
.. _crimes-at-location:
https://data.police.uk/docs/method/crimes-at-location/
:rtype: list
:param int location_... | [
"def",
"get_crimes_location",
"(",
"self",
",",
"location_id",
",",
"date",
"=",
"None",
")",
":",
"kwargs",
"=",
"{",
"'location_id'",
":",
"location_id",
",",
"}",
"crimes",
"=",
"[",
"]",
"if",
"date",
"is",
"not",
"None",
":",
"kwargs",
"[",
"'date... | Get crimes at a particular snap-point location. Uses the
crimes-at-location_ API call.
.. _crimes-at-location:
https://data.police.uk/docs/method/crimes-at-location/
:rtype: list
:param int location_id: The ID of the location to get crimes for.
:param date: The mont... | [
"Get",
"crimes",
"at",
"a",
"particular",
"snap",
"-",
"point",
"location",
".",
"Uses",
"the",
"crimes",
"-",
"at",
"-",
"location_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L304-L329 |
rkhleics/police-api-client-python | police_api/__init__.py | PoliceAPI.get_crimes_no_location | def get_crimes_no_location(self, force, date=None, category=None):
"""
Get crimes with no location for a force. Uses the crimes-no-location_
API call.
.. _crimes-no-location:
https://data.police.uk/docs/method/crimes-no-location/
:rtype: list
:param force: T... | python | def get_crimes_no_location(self, force, date=None, category=None):
"""
Get crimes with no location for a force. Uses the crimes-no-location_
API call.
.. _crimes-no-location:
https://data.police.uk/docs/method/crimes-no-location/
:rtype: list
:param force: T... | [
"def",
"get_crimes_no_location",
"(",
"self",
",",
"force",
",",
"date",
"=",
"None",
",",
"category",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"force",
",",
"Force",
")",
":",
"force",
"=",
"Force",
"(",
"self",
",",
"id",
"=",
"force"... | Get crimes with no location for a force. Uses the crimes-no-location_
API call.
.. _crimes-no-location:
https://data.police.uk/docs/method/crimes-no-location/
:rtype: list
:param force: The force to get no-location crimes for.
:type force: str or Force
:para... | [
"Get",
"crimes",
"with",
"no",
"location",
"for",
"a",
"force",
".",
"Uses",
"the",
"crimes",
"-",
"no",
"-",
"location_",
"API",
"call",
"."
] | train | https://github.com/rkhleics/police-api-client-python/blob/b5c1e493487eb2409e2c04ed9fbd304f73d89fdc/police_api/__init__.py#L331-L368 |
MeaningCloud/meaningcloud-python | meaningcloud/SentimentResponse.py | SentimentResponse.scoreTagToString | def scoreTagToString(self, scoreTag):
"""
:param scoreTag:
:return:
"""
scoreTagToString = ""
if scoreTag == "P+":
scoreTagToString = 'strong positive'
elif scoreTag == "P":
scoreTagToString = 'positive'
elif scoreTag == "NEU":
... | python | def scoreTagToString(self, scoreTag):
"""
:param scoreTag:
:return:
"""
scoreTagToString = ""
if scoreTag == "P+":
scoreTagToString = 'strong positive'
elif scoreTag == "P":
scoreTagToString = 'positive'
elif scoreTag == "NEU":
... | [
"def",
"scoreTagToString",
"(",
"self",
",",
"scoreTag",
")",
":",
"scoreTagToString",
"=",
"\"\"",
"if",
"scoreTag",
"==",
"\"P+\"",
":",
"scoreTagToString",
"=",
"'strong positive'",
"elif",
"scoreTag",
"==",
"\"P\"",
":",
"scoreTagToString",
"=",
"'positive'",
... | :param scoreTag:
:return: | [
":",
"param",
"scoreTag",
":",
":",
"return",
":"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/SentimentResponse.py#L177-L197 |
MaxStrange/retrowrapper | retrowrapper.py | _retrocom | def _retrocom(rx, tx, game, kwargs):
"""
This function is the target for RetroWrapper's internal
process and does all the work of communicating with the
environment.
"""
env = RetroWrapper.retro_make_func(game, **kwargs)
# Sit around on the queue, waiting for calls from RetroWrapper
whi... | python | def _retrocom(rx, tx, game, kwargs):
"""
This function is the target for RetroWrapper's internal
process and does all the work of communicating with the
environment.
"""
env = RetroWrapper.retro_make_func(game, **kwargs)
# Sit around on the queue, waiting for calls from RetroWrapper
whi... | [
"def",
"_retrocom",
"(",
"rx",
",",
"tx",
",",
"game",
",",
"kwargs",
")",
":",
"env",
"=",
"RetroWrapper",
".",
"retro_make_func",
"(",
"game",
",",
"*",
"*",
"kwargs",
")",
"# Sit around on the queue, waiting for calls from RetroWrapper",
"while",
"True",
":",... | This function is the target for RetroWrapper's internal
process and does all the work of communicating with the
environment. | [
"This",
"function",
"is",
"the",
"target",
"for",
"RetroWrapper",
"s",
"internal",
"process",
"and",
"does",
"all",
"the",
"work",
"of",
"communicating",
"with",
"the",
"environment",
"."
] | train | https://github.com/MaxStrange/retrowrapper/blob/f9a112e07ee432d5f34b3a167902e808cfb0e84f/retrowrapper.py#L13-L38 |
MaxStrange/retrowrapper | retrowrapper.py | RetroWrapper._ask_if_attr_is_callable | def _ask_if_attr_is_callable(self, attr):
"""
Returns whether or not the attribute is a callable.
"""
self._tx.put((RetroWrapper.symbol, attr, {}))
return self._rx.get() | python | def _ask_if_attr_is_callable(self, attr):
"""
Returns whether or not the attribute is a callable.
"""
self._tx.put((RetroWrapper.symbol, attr, {}))
return self._rx.get() | [
"def",
"_ask_if_attr_is_callable",
"(",
"self",
",",
"attr",
")",
":",
"self",
".",
"_tx",
".",
"put",
"(",
"(",
"RetroWrapper",
".",
"symbol",
",",
"attr",
",",
"{",
"}",
")",
")",
"return",
"self",
".",
"_rx",
".",
"get",
"(",
")"
] | Returns whether or not the attribute is a callable. | [
"Returns",
"whether",
"or",
"not",
"the",
"attribute",
"is",
"a",
"callable",
"."
] | train | https://github.com/MaxStrange/retrowrapper/blob/f9a112e07ee432d5f34b3a167902e808cfb0e84f/retrowrapper.py#L133-L138 |
MaxStrange/retrowrapper | retrowrapper.py | RetroWrapper.close | def close(self):
"""
Shutdown the environment.
"""
if "_tx" in self.__dict__ and "_proc" in self.__dict__:
self._tx.put(("close", (), {}))
self._proc.join() | python | def close(self):
"""
Shutdown the environment.
"""
if "_tx" in self.__dict__ and "_proc" in self.__dict__:
self._tx.put(("close", (), {}))
self._proc.join() | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"\"_tx\"",
"in",
"self",
".",
"__dict__",
"and",
"\"_proc\"",
"in",
"self",
".",
"__dict__",
":",
"self",
".",
"_tx",
".",
"put",
"(",
"(",
"\"close\"",
",",
"(",
")",
",",
"{",
"}",
")",
")",
"self",
... | Shutdown the environment. | [
"Shutdown",
"the",
"environment",
"."
] | train | https://github.com/MaxStrange/retrowrapper/blob/f9a112e07ee432d5f34b3a167902e808cfb0e84f/retrowrapper.py#L140-L146 |
MeaningCloud/meaningcloud-python | meaningcloud/Request.py | Request.addParam | def addParam(self, paramName, paramValue):
"""
Add a parameter to the request
:param paramName:
Name of the parameter
:param paramValue:
Value of the parameter
"""
if not paramName:
raise ValueError('paramName cannot be empty')
... | python | def addParam(self, paramName, paramValue):
"""
Add a parameter to the request
:param paramName:
Name of the parameter
:param paramValue:
Value of the parameter
"""
if not paramName:
raise ValueError('paramName cannot be empty')
... | [
"def",
"addParam",
"(",
"self",
",",
"paramName",
",",
"paramValue",
")",
":",
"if",
"not",
"paramName",
":",
"raise",
"ValueError",
"(",
"'paramName cannot be empty'",
")",
"self",
".",
"_params",
"[",
"paramName",
"]",
"=",
"paramValue"
] | Add a parameter to the request
:param paramName:
Name of the parameter
:param paramValue:
Value of the parameter | [
"Add",
"a",
"parameter",
"to",
"the",
"request"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Request.py#L37-L49 |
MeaningCloud/meaningcloud-python | meaningcloud/Request.py | Request.setContent | def setContent(self, type_, value):
"""
Sets the content that's going to be sent to analyze according to its type
:param type_:
Type of the content (text, file or url)
:param value:
Value of the content
"""
if type_ in [self.CONTENT_TYPE_TXT, sel... | python | def setContent(self, type_, value):
"""
Sets the content that's going to be sent to analyze according to its type
:param type_:
Type of the content (text, file or url)
:param value:
Value of the content
"""
if type_ in [self.CONTENT_TYPE_TXT, sel... | [
"def",
"setContent",
"(",
"self",
",",
"type_",
",",
"value",
")",
":",
"if",
"type_",
"in",
"[",
"self",
".",
"CONTENT_TYPE_TXT",
",",
"self",
".",
"CONTENT_TYPE_URL",
",",
"self",
".",
"CONTENT_TYPE_FILE",
"]",
":",
"if",
"type_",
"==",
"self",
".",
... | Sets the content that's going to be sent to analyze according to its type
:param type_:
Type of the content (text, file or url)
:param value:
Value of the content | [
"Sets",
"the",
"content",
"that",
"s",
"going",
"to",
"be",
"sent",
"to",
"analyze",
"according",
"to",
"its",
"type"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Request.py#L51-L67 |
MeaningCloud/meaningcloud-python | meaningcloud/Request.py | Request.sendRequest | def sendRequest(self, extraHeaders=""):
"""
Sends a request to the URL specified and returns a response only if the HTTP code returned is OK
:param extraHeaders:
Allows to configure additional headers in the request
:return:
Response object set to None if there ... | python | def sendRequest(self, extraHeaders=""):
"""
Sends a request to the URL specified and returns a response only if the HTTP code returned is OK
:param extraHeaders:
Allows to configure additional headers in the request
:return:
Response object set to None if there ... | [
"def",
"sendRequest",
"(",
"self",
",",
"extraHeaders",
"=",
"\"\"",
")",
":",
"self",
".",
"addParam",
"(",
"'src'",
",",
"'mc-python'",
")",
"params",
"=",
"urlencode",
"(",
"self",
".",
"_params",
")",
"url",
"=",
"self",
".",
"_url",
"if",
"'doc'",... | Sends a request to the URL specified and returns a response only if the HTTP code returned is OK
:param extraHeaders:
Allows to configure additional headers in the request
:return:
Response object set to None if there is an error | [
"Sends",
"a",
"request",
"to",
"the",
"URL",
"specified",
"and",
"returns",
"a",
"response",
"only",
"if",
"the",
"HTTP",
"code",
"returned",
"is",
"OK"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/Request.py#L99-L130 |
MeaningCloud/meaningcloud-python | meaningcloud/ParserResponse.py | ParserResponse.getLemmatization | def getLemmatization(self, fullPOSTag=False):
"""
This function obtains the lemmas and PoS for the text sent
:param fullPOSTag:
Set to true to obtain the complete PoS tag
:return:
Dictionary of tokens from the syntactic tree with their lemmas and PoS
"""
... | python | def getLemmatization(self, fullPOSTag=False):
"""
This function obtains the lemmas and PoS for the text sent
:param fullPOSTag:
Set to true to obtain the complete PoS tag
:return:
Dictionary of tokens from the syntactic tree with their lemmas and PoS
"""
... | [
"def",
"getLemmatization",
"(",
"self",
",",
"fullPOSTag",
"=",
"False",
")",
":",
"leaves",
"=",
"self",
".",
"_getTreeLeaves",
"(",
")",
"lemmas",
"=",
"{",
"}",
"for",
"leaf",
"in",
"leaves",
":",
"analyses",
"=",
"[",
"]",
"if",
"'analysis_list'",
... | This function obtains the lemmas and PoS for the text sent
:param fullPOSTag:
Set to true to obtain the complete PoS tag
:return:
Dictionary of tokens from the syntactic tree with their lemmas and PoS | [
"This",
"function",
"obtains",
"the",
"lemmas",
"and",
"PoS",
"for",
"the",
"text",
"sent"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/ParserResponse.py#L22-L44 |
MeaningCloud/meaningcloud-python | meaningcloud/TopicsResponse.py | TopicsResponse.getTypeLastNode | def getTypeLastNode(self, type_):
"""
Obtains the last node or leaf of the type specified
:param type_:
Type we want to analize (sementity, semtheme)
:return:
Last node of the type
"""
lastNode = ""
if type_ and (type(type_) is not list) ... | python | def getTypeLastNode(self, type_):
"""
Obtains the last node or leaf of the type specified
:param type_:
Type we want to analize (sementity, semtheme)
:return:
Last node of the type
"""
lastNode = ""
if type_ and (type(type_) is not list) ... | [
"def",
"getTypeLastNode",
"(",
"self",
",",
"type_",
")",
":",
"lastNode",
"=",
"\"\"",
"if",
"type_",
"and",
"(",
"type",
"(",
"type_",
")",
"is",
"not",
"list",
")",
"and",
"(",
"type",
"(",
"type_",
")",
"is",
"not",
"dict",
")",
":",
"aType",
... | Obtains the last node or leaf of the type specified
:param type_:
Type we want to analize (sementity, semtheme)
:return:
Last node of the type | [
"Obtains",
"the",
"last",
"node",
"or",
"leaf",
"of",
"the",
"type",
"specified"
] | train | https://github.com/MeaningCloud/meaningcloud-python/blob/1dd76ecabeedd80c9bb14a1716d39657d645775f/meaningcloud/TopicsResponse.py#L161-L175 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.__conn_listener | def __conn_listener(self, state):
"""
Connection event listener
:param state: The new connection state
"""
if state == KazooState.CONNECTED:
self.__online = True
if not self.__connected:
self.__connected = True
self._logger... | python | def __conn_listener(self, state):
"""
Connection event listener
:param state: The new connection state
"""
if state == KazooState.CONNECTED:
self.__online = True
if not self.__connected:
self.__connected = True
self._logger... | [
"def",
"__conn_listener",
"(",
"self",
",",
"state",
")",
":",
"if",
"state",
"==",
"KazooState",
".",
"CONNECTED",
":",
"self",
".",
"__online",
"=",
"True",
"if",
"not",
"self",
".",
"__connected",
":",
"self",
".",
"__connected",
"=",
"True",
"self",
... | Connection event listener
:param state: The new connection state | [
"Connection",
"event",
"listener"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L135-L160 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.start | def start(self):
"""
Starts the connection
"""
self.__stop = False
self._queue.start()
self._zk.start() | python | def start(self):
"""
Starts the connection
"""
self.__stop = False
self._queue.start()
self._zk.start() | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"__stop",
"=",
"False",
"self",
".",
"_queue",
".",
"start",
"(",
")",
"self",
".",
"_zk",
".",
"start",
"(",
")"
] | Starts the connection | [
"Starts",
"the",
"connection"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L162-L168 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.stop | def stop(self):
"""
Stops the connection
"""
self.__stop = True
self._queue.stop()
self._zk.stop() | python | def stop(self):
"""
Stops the connection
"""
self.__stop = True
self._queue.stop()
self._zk.stop() | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"__stop",
"=",
"True",
"self",
".",
"_queue",
".",
"stop",
"(",
")",
"self",
".",
"_zk",
".",
"stop",
"(",
")"
] | Stops the connection | [
"Stops",
"the",
"connection"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L170-L176 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.__path | def __path(self, path):
"""
Adds the prefix to the given path
:param path: Z-Path
:return: Prefixed Z-Path
"""
if path.startswith(self.__prefix):
return path
return "{}{}".format(self.__prefix, path) | python | def __path(self, path):
"""
Adds the prefix to the given path
:param path: Z-Path
:return: Prefixed Z-Path
"""
if path.startswith(self.__prefix):
return path
return "{}{}".format(self.__prefix, path) | [
"def",
"__path",
"(",
"self",
",",
"path",
")",
":",
"if",
"path",
".",
"startswith",
"(",
"self",
".",
"__prefix",
")",
":",
"return",
"path",
"return",
"\"{}{}\"",
".",
"format",
"(",
"self",
".",
"__prefix",
",",
"path",
")"
] | Adds the prefix to the given path
:param path: Z-Path
:return: Prefixed Z-Path | [
"Adds",
"the",
"prefix",
"to",
"the",
"given",
"path"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L192-L202 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.create | def create(self, path, data, ephemeral=False, sequence=False):
"""
Creates a ZooKeeper node
:param path: Z-Path
:param data: Node Content
:param ephemeral: Ephemeral flag
:param sequence: Sequential flag
"""
return self._zk.create(
self.__path... | python | def create(self, path, data, ephemeral=False, sequence=False):
"""
Creates a ZooKeeper node
:param path: Z-Path
:param data: Node Content
:param ephemeral: Ephemeral flag
:param sequence: Sequential flag
"""
return self._zk.create(
self.__path... | [
"def",
"create",
"(",
"self",
",",
"path",
",",
"data",
",",
"ephemeral",
"=",
"False",
",",
"sequence",
"=",
"False",
")",
":",
"return",
"self",
".",
"_zk",
".",
"create",
"(",
"self",
".",
"__path",
"(",
"path",
")",
",",
"data",
",",
"ephemeral... | Creates a ZooKeeper node
:param path: Z-Path
:param data: Node Content
:param ephemeral: Ephemeral flag
:param sequence: Sequential flag | [
"Creates",
"a",
"ZooKeeper",
"node"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L204-L215 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.get | def get(self, path, watch=None):
"""
Gets the content of a ZooKeeper node
:param path: Z-Path
:param watch: Watch method
"""
return self._zk.get(self.__path(path), watch=watch) | python | def get(self, path, watch=None):
"""
Gets the content of a ZooKeeper node
:param path: Z-Path
:param watch: Watch method
"""
return self._zk.get(self.__path(path), watch=watch) | [
"def",
"get",
"(",
"self",
",",
"path",
",",
"watch",
"=",
"None",
")",
":",
"return",
"self",
".",
"_zk",
".",
"get",
"(",
"self",
".",
"__path",
"(",
"path",
")",
",",
"watch",
"=",
"watch",
")"
] | Gets the content of a ZooKeeper node
:param path: Z-Path
:param watch: Watch method | [
"Gets",
"the",
"content",
"of",
"a",
"ZooKeeper",
"node"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L225-L232 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.get_children | def get_children(self, path, watch=None):
"""
Gets the list of children of a node
:param path: Z-Path
:param watch: Watch method
"""
return self._zk.get_children(self.__path(path), watch=watch) | python | def get_children(self, path, watch=None):
"""
Gets the list of children of a node
:param path: Z-Path
:param watch: Watch method
"""
return self._zk.get_children(self.__path(path), watch=watch) | [
"def",
"get_children",
"(",
"self",
",",
"path",
",",
"watch",
"=",
"None",
")",
":",
"return",
"self",
".",
"_zk",
".",
"get_children",
"(",
"self",
".",
"__path",
"(",
"path",
")",
",",
"watch",
"=",
"watch",
")"
] | Gets the list of children of a node
:param path: Z-Path
:param watch: Watch method | [
"Gets",
"the",
"list",
"of",
"children",
"of",
"a",
"node"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L234-L241 |
tcalmant/ipopo | pelix/remote/discovery/zookeeper.py | ZooKeeperClient.set | def set(self, path, data):
"""
Sets the content of a ZooKeeper node
:param path: Z-Path
:param data: New content
"""
return self._zk.set(self.__path(path), data) | python | def set(self, path, data):
"""
Sets the content of a ZooKeeper node
:param path: Z-Path
:param data: New content
"""
return self._zk.set(self.__path(path), data) | [
"def",
"set",
"(",
"self",
",",
"path",
",",
"data",
")",
":",
"return",
"self",
".",
"_zk",
".",
"set",
"(",
"self",
".",
"__path",
"(",
"path",
")",
",",
"data",
")"
] | Sets the content of a ZooKeeper node
:param path: Z-Path
:param data: New content | [
"Sets",
"the",
"content",
"of",
"a",
"ZooKeeper",
"node"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/discovery/zookeeper.py#L243-L250 |
tcalmant/ipopo | pelix/ipopo/constants.py | get_ipopo_svc_ref | def get_ipopo_svc_ref(bundle_context):
# type: (BundleContext) -> Optional[Tuple[ServiceReference, Any]]
"""
Retrieves a tuple containing the service reference to iPOPO and the service
itself
:param bundle_context: The calling bundle context
:return: The reference to the iPOPO service and the s... | python | def get_ipopo_svc_ref(bundle_context):
# type: (BundleContext) -> Optional[Tuple[ServiceReference, Any]]
"""
Retrieves a tuple containing the service reference to iPOPO and the service
itself
:param bundle_context: The calling bundle context
:return: The reference to the iPOPO service and the s... | [
"def",
"get_ipopo_svc_ref",
"(",
"bundle_context",
")",
":",
"# type: (BundleContext) -> Optional[Tuple[ServiceReference, Any]]",
"# Look after the service",
"ref",
"=",
"bundle_context",
".",
"get_service_reference",
"(",
"SERVICE_IPOPO",
")",
"if",
"ref",
"is",
"None",
":",... | Retrieves a tuple containing the service reference to iPOPO and the service
itself
:param bundle_context: The calling bundle context
:return: The reference to the iPOPO service and the service itself,
None if not available | [
"Retrieves",
"a",
"tuple",
"containing",
"the",
"service",
"reference",
"to",
"iPOPO",
"and",
"the",
"service",
"itself"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/constants.py#L189-L212 |
tcalmant/ipopo | pelix/ipopo/constants.py | use_ipopo | def use_ipopo(bundle_context):
# type: (BundleContext) -> Any
"""
Utility context to use the iPOPO service safely in a "with" block.
It looks after the the iPOPO service and releases its reference when
exiting the context.
:param bundle_context: The calling bundle context
:return: The iPOPO... | python | def use_ipopo(bundle_context):
# type: (BundleContext) -> Any
"""
Utility context to use the iPOPO service safely in a "with" block.
It looks after the the iPOPO service and releases its reference when
exiting the context.
:param bundle_context: The calling bundle context
:return: The iPOPO... | [
"def",
"use_ipopo",
"(",
"bundle_context",
")",
":",
"# type: (BundleContext) -> Any",
"# Get the service and its reference",
"ref_svc",
"=",
"get_ipopo_svc_ref",
"(",
"bundle_context",
")",
"if",
"ref_svc",
"is",
"None",
":",
"raise",
"BundleException",
"(",
"\"No iPOPO ... | Utility context to use the iPOPO service safely in a "with" block.
It looks after the the iPOPO service and releases its reference when
exiting the context.
:param bundle_context: The calling bundle context
:return: The iPOPO service
:raise BundleException: Service not found | [
"Utility",
"context",
"to",
"use",
"the",
"iPOPO",
"service",
"safely",
"in",
"a",
"with",
"block",
".",
"It",
"looks",
"after",
"the",
"the",
"iPOPO",
"service",
"and",
"releases",
"its",
"reference",
"when",
"exiting",
"the",
"context",
"."
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/constants.py#L216-L241 |
tcalmant/ipopo | pelix/ipopo/constants.py | use_waiting_list | def use_waiting_list(bundle_context):
# type: (BundleContext) -> Any
"""
Utility context to use the iPOPO waiting list safely in a "with" block.
It looks after the the iPOPO waiting list service and releases its
reference when exiting the context.
:param bundle_context: The calling bundle conte... | python | def use_waiting_list(bundle_context):
# type: (BundleContext) -> Any
"""
Utility context to use the iPOPO waiting list safely in a "with" block.
It looks after the the iPOPO waiting list service and releases its
reference when exiting the context.
:param bundle_context: The calling bundle conte... | [
"def",
"use_waiting_list",
"(",
"bundle_context",
")",
":",
"# type: (BundleContext) -> Any",
"# Get the service and its reference",
"ref",
"=",
"bundle_context",
".",
"get_service_reference",
"(",
"SERVICE_IPOPO_WAITING_LIST",
")",
"if",
"ref",
"is",
"None",
":",
"raise",
... | Utility context to use the iPOPO waiting list safely in a "with" block.
It looks after the the iPOPO waiting list service and releases its
reference when exiting the context.
:param bundle_context: The calling bundle context
:return: The iPOPO waiting list service
:raise BundleException: Service no... | [
"Utility",
"context",
"to",
"use",
"the",
"iPOPO",
"waiting",
"list",
"safely",
"in",
"a",
"with",
"block",
".",
"It",
"looks",
"after",
"the",
"the",
"iPOPO",
"waiting",
"list",
"service",
"and",
"releases",
"its",
"reference",
"when",
"exiting",
"the",
"... | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/constants.py#L245-L270 |
tcalmant/ipopo | pelix/misc/jabsorb.py | _compute_jsonclass | def _compute_jsonclass(obj):
"""
Compute the content of the __jsonclass__ field for the given object
:param obj: An object
:return: The content of the __jsonclass__ field
"""
# It's not a standard type, so it needs __jsonclass__
module_name = inspect.getmodule(obj).__name__
json_class =... | python | def _compute_jsonclass(obj):
"""
Compute the content of the __jsonclass__ field for the given object
:param obj: An object
:return: The content of the __jsonclass__ field
"""
# It's not a standard type, so it needs __jsonclass__
module_name = inspect.getmodule(obj).__name__
json_class =... | [
"def",
"_compute_jsonclass",
"(",
"obj",
")",
":",
"# It's not a standard type, so it needs __jsonclass__",
"module_name",
"=",
"inspect",
".",
"getmodule",
"(",
"obj",
")",
".",
"__name__",
"json_class",
"=",
"obj",
".",
"__class__",
".",
"__name__",
"if",
"module_... | Compute the content of the __jsonclass__ field for the given object
:param obj: An object
:return: The content of the __jsonclass__ field | [
"Compute",
"the",
"content",
"of",
"the",
"__jsonclass__",
"field",
"for",
"the",
"given",
"object"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/jabsorb.py#L141-L154 |
tcalmant/ipopo | pelix/misc/jabsorb.py | _is_builtin | def _is_builtin(obj):
"""
Checks if the type of the given object is a built-in one or not
:param obj: An object
:return: True if the object is of a built-in type
"""
module_ = inspect.getmodule(obj)
if module_ in (None, builtins):
return True
return module_.__name__ in ("", "__... | python | def _is_builtin(obj):
"""
Checks if the type of the given object is a built-in one or not
:param obj: An object
:return: True if the object is of a built-in type
"""
module_ = inspect.getmodule(obj)
if module_ in (None, builtins):
return True
return module_.__name__ in ("", "__... | [
"def",
"_is_builtin",
"(",
"obj",
")",
":",
"module_",
"=",
"inspect",
".",
"getmodule",
"(",
"obj",
")",
"if",
"module_",
"in",
"(",
"None",
",",
"builtins",
")",
":",
"return",
"True",
"return",
"module_",
".",
"__name__",
"in",
"(",
"\"\"",
",",
"... | Checks if the type of the given object is a built-in one or not
:param obj: An object
:return: True if the object is of a built-in type | [
"Checks",
"if",
"the",
"type",
"of",
"the",
"given",
"object",
"is",
"a",
"built",
"-",
"in",
"one",
"or",
"not"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/jabsorb.py#L157-L168 |
tcalmant/ipopo | pelix/misc/jabsorb.py | _is_converted_class | def _is_converted_class(java_class):
"""
Checks if the given Java class is one we *might* have set up
"""
if not java_class:
return False
return (
JAVA_MAPS_PATTERN.match(java_class) is not None
or JAVA_LISTS_PATTERN.match(java_class) is not None
or JAVA_SETS_PATTERN... | python | def _is_converted_class(java_class):
"""
Checks if the given Java class is one we *might* have set up
"""
if not java_class:
return False
return (
JAVA_MAPS_PATTERN.match(java_class) is not None
or JAVA_LISTS_PATTERN.match(java_class) is not None
or JAVA_SETS_PATTERN... | [
"def",
"_is_converted_class",
"(",
"java_class",
")",
":",
"if",
"not",
"java_class",
":",
"return",
"False",
"return",
"(",
"JAVA_MAPS_PATTERN",
".",
"match",
"(",
"java_class",
")",
"is",
"not",
"None",
"or",
"JAVA_LISTS_PATTERN",
".",
"match",
"(",
"java_cl... | Checks if the given Java class is one we *might* have set up | [
"Checks",
"if",
"the",
"given",
"Java",
"class",
"is",
"one",
"we",
"*",
"might",
"*",
"have",
"set",
"up"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/jabsorb.py#L171-L182 |
tcalmant/ipopo | pelix/misc/jabsorb.py | to_jabsorb | def to_jabsorb(value):
"""
Adds information for Jabsorb, if needed.
Converts maps and lists to a jabsorb form.
Keeps tuples as is, to let them be considered as arrays.
:param value: A Python result to send to Jabsorb
:return: The result in a Jabsorb map format (not a JSON object)
"""
#... | python | def to_jabsorb(value):
"""
Adds information for Jabsorb, if needed.
Converts maps and lists to a jabsorb form.
Keeps tuples as is, to let them be considered as arrays.
:param value: A Python result to send to Jabsorb
:return: The result in a Jabsorb map format (not a JSON object)
"""
#... | [
"def",
"to_jabsorb",
"(",
"value",
")",
":",
"# None ?",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"# Map ?",
"elif",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"if",
"JAVA_CLASS",
"in",
"value",
"or",
"JSON_CLASS",
"in",
"value",
":",
... | Adds information for Jabsorb, if needed.
Converts maps and lists to a jabsorb form.
Keeps tuples as is, to let them be considered as arrays.
:param value: A Python result to send to Jabsorb
:return: The result in a Jabsorb map format (not a JSON object) | [
"Adds",
"information",
"for",
"Jabsorb",
"if",
"needed",
"."
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/jabsorb.py#L188-L277 |
tcalmant/ipopo | pelix/misc/jabsorb.py | from_jabsorb | def from_jabsorb(request, seems_raw=False):
"""
Transforms a jabsorb request into a more Python data model (converts maps
and lists)
:param request: Data coming from Jabsorb
:param seems_raw: Set it to True if the given data seems to already have
been parsed (no Java class hin... | python | def from_jabsorb(request, seems_raw=False):
"""
Transforms a jabsorb request into a more Python data model (converts maps
and lists)
:param request: Data coming from Jabsorb
:param seems_raw: Set it to True if the given data seems to already have
been parsed (no Java class hin... | [
"def",
"from_jabsorb",
"(",
"request",
",",
"seems_raw",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"request",
",",
"(",
"tuple",
",",
"set",
",",
"frozenset",
")",
")",
":",
"# Special case : JSON arrays (Python lists)",
"return",
"type",
"(",
"request"... | Transforms a jabsorb request into a more Python data model (converts maps
and lists)
:param request: Data coming from Jabsorb
:param seems_raw: Set it to True if the given data seems to already have
been parsed (no Java class hint). If True, the lists will
be kep... | [
"Transforms",
"a",
"jabsorb",
"request",
"into",
"a",
"more",
"Python",
"data",
"model",
"(",
"converts",
"maps",
"and",
"lists",
")"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/jabsorb.py#L280-L352 |
tcalmant/ipopo | pelix/ipopo/contexts.py | Requirement.copy | def copy(self):
# type: () -> Requirement
"""
Returns a copy of this instance
:return: A copy of this instance
"""
return Requirement(
self.specification,
self.aggregate,
self.optional,
self.__original_filter,
s... | python | def copy(self):
# type: () -> Requirement
"""
Returns a copy of this instance
:return: A copy of this instance
"""
return Requirement(
self.specification,
self.aggregate,
self.optional,
self.__original_filter,
s... | [
"def",
"copy",
"(",
"self",
")",
":",
"# type: () -> Requirement",
"return",
"Requirement",
"(",
"self",
".",
"specification",
",",
"self",
".",
"aggregate",
",",
"self",
".",
"optional",
",",
"self",
".",
"__original_filter",
",",
"self",
".",
"immediate_rebi... | Returns a copy of this instance
:return: A copy of this instance | [
"Returns",
"a",
"copy",
"of",
"this",
"instance"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L146-L159 |
tcalmant/ipopo | pelix/ipopo/contexts.py | Requirement.set_filter | def set_filter(self, props_filter):
"""
Changes the current filter for the given one
:param props_filter: The new requirement filter on service properties
:raise TypeError: Unknown filter type
"""
if props_filter is not None and not (
is_string(props_filter)
... | python | def set_filter(self, props_filter):
"""
Changes the current filter for the given one
:param props_filter: The new requirement filter on service properties
:raise TypeError: Unknown filter type
"""
if props_filter is not None and not (
is_string(props_filter)
... | [
"def",
"set_filter",
"(",
"self",
",",
"props_filter",
")",
":",
"if",
"props_filter",
"is",
"not",
"None",
"and",
"not",
"(",
"is_string",
"(",
"props_filter",
")",
"or",
"isinstance",
"(",
"props_filter",
",",
"(",
"ldapfilter",
".",
"LDAPFilter",
",",
"... | Changes the current filter for the given one
:param props_filter: The new requirement filter on service properties
:raise TypeError: Unknown filter type | [
"Changes",
"the",
"current",
"filter",
"for",
"the",
"given",
"one"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L195-L227 |
tcalmant/ipopo | pelix/ipopo/contexts.py | FactoryContext._deepcopy | def _deepcopy(self, data):
"""
Deep copies the given object
:param data: Data to copy
:return: A copy of the data, if supported, else the data itself
"""
if isinstance(data, dict):
# Copy dictionary values
return {key: self._deepcopy(value) for ke... | python | def _deepcopy(self, data):
"""
Deep copies the given object
:param data: Data to copy
:return: A copy of the data, if supported, else the data itself
"""
if isinstance(data, dict):
# Copy dictionary values
return {key: self._deepcopy(value) for ke... | [
"def",
"_deepcopy",
"(",
"self",
",",
"data",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"dict",
")",
":",
"# Copy dictionary values",
"return",
"{",
"key",
":",
"self",
".",
"_deepcopy",
"(",
"value",
")",
"for",
"key",
",",
"value",
"in",
"data"... | Deep copies the given object
:param data: Data to copy
:return: A copy of the data, if supported, else the data itself | [
"Deep",
"copies",
"the",
"given",
"object"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L318-L337 |
tcalmant/ipopo | pelix/ipopo/contexts.py | FactoryContext.copy | def copy(self, inheritance=False):
# type: (bool) -> FactoryContext
"""
Returns a deep copy of the current FactoryContext instance
:param inheritance: If True, current handlers configurations are stored
as inherited ones
"""
# Create a new fac... | python | def copy(self, inheritance=False):
# type: (bool) -> FactoryContext
"""
Returns a deep copy of the current FactoryContext instance
:param inheritance: If True, current handlers configurations are stored
as inherited ones
"""
# Create a new fac... | [
"def",
"copy",
"(",
"self",
",",
"inheritance",
"=",
"False",
")",
":",
"# type: (bool) -> FactoryContext",
"# Create a new factory context and duplicate its values",
"new_context",
"=",
"FactoryContext",
"(",
")",
"for",
"field",
"in",
"self",
".",
"__slots__",
":",
... | Returns a deep copy of the current FactoryContext instance
:param inheritance: If True, current handlers configurations are stored
as inherited ones | [
"Returns",
"a",
"deep",
"copy",
"of",
"the",
"current",
"FactoryContext",
"instance"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L339-L363 |
tcalmant/ipopo | pelix/ipopo/contexts.py | FactoryContext.inherit_handlers | def inherit_handlers(self, excluded_handlers):
# type: (Iterable[str]) -> None
"""
Merges the inherited configuration with the current ones
:param excluded_handlers: Excluded handlers
"""
if not excluded_handlers:
excluded_handlers = tuple()
for hand... | python | def inherit_handlers(self, excluded_handlers):
# type: (Iterable[str]) -> None
"""
Merges the inherited configuration with the current ones
:param excluded_handlers: Excluded handlers
"""
if not excluded_handlers:
excluded_handlers = tuple()
for hand... | [
"def",
"inherit_handlers",
"(",
"self",
",",
"excluded_handlers",
")",
":",
"# type: (Iterable[str]) -> None",
"if",
"not",
"excluded_handlers",
":",
"excluded_handlers",
"=",
"tuple",
"(",
")",
"for",
"handler",
",",
"configuration",
"in",
"self",
".",
"__inherited... | Merges the inherited configuration with the current ones
:param excluded_handlers: Excluded handlers | [
"Merges",
"the",
"inherited",
"configuration",
"with",
"the",
"current",
"ones"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L365-L397 |
tcalmant/ipopo | pelix/ipopo/contexts.py | FactoryContext.add_instance | def add_instance(self, name, properties):
# type: (str, dict) -> None
"""
Stores the description of a component instance. The given properties
are stored as is.
:param name: Instance name
:param properties: Instance properties
:raise NameError: Already known inst... | python | def add_instance(self, name, properties):
# type: (str, dict) -> None
"""
Stores the description of a component instance. The given properties
are stored as is.
:param name: Instance name
:param properties: Instance properties
:raise NameError: Already known inst... | [
"def",
"add_instance",
"(",
"self",
",",
"name",
",",
"properties",
")",
":",
"# type: (str, dict) -> None",
"if",
"name",
"in",
"self",
".",
"__instances",
":",
"raise",
"NameError",
"(",
"name",
")",
"# Store properties \"as-is\"",
"self",
".",
"__instances",
... | Stores the description of a component instance. The given properties
are stored as is.
:param name: Instance name
:param properties: Instance properties
:raise NameError: Already known instance name | [
"Stores",
"the",
"description",
"of",
"a",
"component",
"instance",
".",
"The",
"given",
"properties",
"are",
"stored",
"as",
"is",
"."
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L399-L413 |
tcalmant/ipopo | pelix/ipopo/contexts.py | ComponentContext.get_field_callback | def get_field_callback(self, field, event):
# type: (str, str) -> Optional[Tuple[Callable, bool]]
"""
Retrieves the registered method for the given event. Returns None if
not found
:param field: Name of the dependency field
:param event: A component life cycle event
... | python | def get_field_callback(self, field, event):
# type: (str, str) -> Optional[Tuple[Callable, bool]]
"""
Retrieves the registered method for the given event. Returns None if
not found
:param field: Name of the dependency field
:param event: A component life cycle event
... | [
"def",
"get_field_callback",
"(",
"self",
",",
"field",
",",
"event",
")",
":",
"# type: (str, str) -> Optional[Tuple[Callable, bool]]",
"try",
":",
"return",
"self",
".",
"factory_context",
".",
"field_callbacks",
"[",
"field",
"]",
"[",
"event",
"]",
"except",
"... | Retrieves the registered method for the given event. Returns None if
not found
:param field: Name of the dependency field
:param event: A component life cycle event
:return: A 2-tuple containing the callback associated to the given
event and flag indicating if the callb... | [
"Retrieves",
"the",
"registered",
"method",
"for",
"the",
"given",
"event",
".",
"Returns",
"None",
"if",
"not",
"found"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L546-L561 |
tcalmant/ipopo | pelix/ipopo/contexts.py | ComponentContext.grab_hidden_properties | def grab_hidden_properties(self):
# type: () -> dict
"""
A one-shot access to hidden properties (the field is then destroyed)
:return: A copy of the hidden properties dictionary on the first call
:raise AttributeError: On any call after the first one
"""
# Copy p... | python | def grab_hidden_properties(self):
# type: () -> dict
"""
A one-shot access to hidden properties (the field is then destroyed)
:return: A copy of the hidden properties dictionary on the first call
:raise AttributeError: On any call after the first one
"""
# Copy p... | [
"def",
"grab_hidden_properties",
"(",
"self",
")",
":",
"# type: () -> dict",
"# Copy properties",
"result",
"=",
"self",
".",
"__hidden_properties",
".",
"copy",
"(",
")",
"# Destroy the field",
"self",
".",
"__hidden_properties",
".",
"clear",
"(",
")",
"del",
"... | A one-shot access to hidden properties (the field is then destroyed)
:return: A copy of the hidden properties dictionary on the first call
:raise AttributeError: On any call after the first one | [
"A",
"one",
"-",
"shot",
"access",
"to",
"hidden",
"properties",
"(",
"the",
"field",
"is",
"then",
"destroyed",
")"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/contexts.py#L590-L604 |
tcalmant/ipopo | pelix/ipopo/handlers/properties.py | PropertiesHandler._field_property_generator | def _field_property_generator(self, public_properties):
"""
Generates the methods called by the injected class properties
:param public_properties: If True, create a public property accessor,
else an hidden property accessor
:return: getter and setter m... | python | def _field_property_generator(self, public_properties):
"""
Generates the methods called by the injected class properties
:param public_properties: If True, create a public property accessor,
else an hidden property accessor
:return: getter and setter m... | [
"def",
"_field_property_generator",
"(",
"self",
",",
"public_properties",
")",
":",
"# Local variable, to avoid messing with \"self\"",
"stored_instance",
"=",
"self",
".",
"_ipopo_instance",
"# Choose public or hidden properties",
"# and select the method to call to notify about the ... | Generates the methods called by the injected class properties
:param public_properties: If True, create a public property accessor,
else an hidden property accessor
:return: getter and setter methods | [
"Generates",
"the",
"methods",
"called",
"by",
"the",
"injected",
"class",
"properties"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/handlers/properties.py#L116-L166 |
tcalmant/ipopo | pelix/ipopo/handlers/properties.py | PropertiesHandler.get_methods_names | def get_methods_names(public_properties):
"""
Generates the names of the fields where to inject the getter and setter
methods
:param public_properties: If True, returns the names of public property
accessors, else of hidden property ones
:return... | python | def get_methods_names(public_properties):
"""
Generates the names of the fields where to inject the getter and setter
methods
:param public_properties: If True, returns the names of public property
accessors, else of hidden property ones
:return... | [
"def",
"get_methods_names",
"(",
"public_properties",
")",
":",
"if",
"public_properties",
":",
"prefix",
"=",
"ipopo_constants",
".",
"IPOPO_PROPERTY_PREFIX",
"else",
":",
"prefix",
"=",
"ipopo_constants",
".",
"IPOPO_HIDDEN_PROPERTY_PREFIX",
"return",
"(",
"\"{0}{1}\"... | Generates the names of the fields where to inject the getter and setter
methods
:param public_properties: If True, returns the names of public property
accessors, else of hidden property ones
:return: getter and a setter field names | [
"Generates",
"the",
"names",
"of",
"the",
"fields",
"where",
"to",
"inject",
"the",
"getter",
"and",
"setter",
"methods"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/handlers/properties.py#L169-L186 |
tcalmant/ipopo | pelix/ipopo/handlers/properties.py | PropertiesHandler.manipulate | def manipulate(self, stored_instance, component_instance):
"""
Manipulates the component instance
:param stored_instance: The iPOPO component StoredInstance
:param component_instance: The component instance
"""
# Store the stored instance
self._ipopo_instance = s... | python | def manipulate(self, stored_instance, component_instance):
"""
Manipulates the component instance
:param stored_instance: The iPOPO component StoredInstance
:param component_instance: The component instance
"""
# Store the stored instance
self._ipopo_instance = s... | [
"def",
"manipulate",
"(",
"self",
",",
"stored_instance",
",",
"component_instance",
")",
":",
"# Store the stored instance",
"self",
".",
"_ipopo_instance",
"=",
"stored_instance",
"# Public flags to generate (True for public accessors)",
"flags_to_generate",
"=",
"set",
"("... | Manipulates the component instance
:param stored_instance: The iPOPO component StoredInstance
:param component_instance: The component instance | [
"Manipulates",
"the",
"component",
"instance"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/handlers/properties.py#L188-L215 |
tcalmant/ipopo | pelix/rsa/shell.py | _full_class_name | def _full_class_name(obj):
"""
Returns the full name of the class of the given object
:param obj: Any Python object
:return: The full name of the class of the object (if possible)
"""
module = obj.__class__.__module__
if module is None or module == str.__class__.__module__:
return o... | python | def _full_class_name(obj):
"""
Returns the full name of the class of the given object
:param obj: Any Python object
:return: The full name of the class of the object (if possible)
"""
module = obj.__class__.__module__
if module is None or module == str.__class__.__module__:
return o... | [
"def",
"_full_class_name",
"(",
"obj",
")",
":",
"module",
"=",
"obj",
".",
"__class__",
".",
"__module__",
"if",
"module",
"is",
"None",
"or",
"module",
"==",
"str",
".",
"__class__",
".",
"__module__",
":",
"return",
"obj",
".",
"__class__",
".",
"__na... | Returns the full name of the class of the given object
:param obj: Any Python object
:return: The full name of the class of the object (if possible) | [
"Returns",
"the",
"full",
"name",
"of",
"the",
"class",
"of",
"the",
"given",
"object"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/shell.py#L87-L97 |
tcalmant/ipopo | pelix/shell/beans.py | IOHandler._prompt | def _prompt(self, prompt=None):
"""
Reads a line written by the user
:param prompt: An optional prompt message
:return: The read line, after a conversion to str
"""
if prompt:
# Print the prompt
self.write(prompt)
self.output.flush()
... | python | def _prompt(self, prompt=None):
"""
Reads a line written by the user
:param prompt: An optional prompt message
:return: The read line, after a conversion to str
"""
if prompt:
# Print the prompt
self.write(prompt)
self.output.flush()
... | [
"def",
"_prompt",
"(",
"self",
",",
"prompt",
"=",
"None",
")",
":",
"if",
"prompt",
":",
"# Print the prompt",
"self",
".",
"write",
"(",
"prompt",
")",
"self",
".",
"output",
".",
"flush",
"(",
")",
"# Read the line",
"return",
"to_str",
"(",
"self",
... | Reads a line written by the user
:param prompt: An optional prompt message
:return: The read line, after a conversion to str | [
"Reads",
"a",
"line",
"written",
"by",
"the",
"user"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/beans.py#L195-L208 |
tcalmant/ipopo | pelix/shell/beans.py | IOHandler._write_bytes | def _write_bytes(self, data):
"""
Converts the given data then writes it
:param data: Data to be written
:return: The result of ``self.output.write()``
"""
with self.__lock:
self.output.write(to_bytes(data, self.encoding)) | python | def _write_bytes(self, data):
"""
Converts the given data then writes it
:param data: Data to be written
:return: The result of ``self.output.write()``
"""
with self.__lock:
self.output.write(to_bytes(data, self.encoding)) | [
"def",
"_write_bytes",
"(",
"self",
",",
"data",
")",
":",
"with",
"self",
".",
"__lock",
":",
"self",
".",
"output",
".",
"write",
"(",
"to_bytes",
"(",
"data",
",",
"self",
".",
"encoding",
")",
")"
] | Converts the given data then writes it
:param data: Data to be written
:return: The result of ``self.output.write()`` | [
"Converts",
"the",
"given",
"data",
"then",
"writes",
"it"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/beans.py#L210-L218 |
tcalmant/ipopo | pelix/shell/beans.py | IOHandler._write_str | def _write_str(self, data):
"""
Converts the given data then writes it
:param data: Data to be written
:return: The result of ``self.output.write()``
"""
with self.__lock:
self.output.write(
to_str(data, self.encoding)
.encode(... | python | def _write_str(self, data):
"""
Converts the given data then writes it
:param data: Data to be written
:return: The result of ``self.output.write()``
"""
with self.__lock:
self.output.write(
to_str(data, self.encoding)
.encode(... | [
"def",
"_write_str",
"(",
"self",
",",
"data",
")",
":",
"with",
"self",
".",
"__lock",
":",
"self",
".",
"output",
".",
"write",
"(",
"to_str",
"(",
"data",
",",
"self",
".",
"encoding",
")",
".",
"encode",
"(",
")",
".",
"decode",
"(",
"self",
... | Converts the given data then writes it
:param data: Data to be written
:return: The result of ``self.output.write()`` | [
"Converts",
"the",
"given",
"data",
"then",
"writes",
"it"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/beans.py#L220-L232 |
tcalmant/ipopo | pelix/shell/beans.py | IOHandler.write_line | def write_line(self, line=None, *args, **kwargs):
"""
Formats and writes a line to the output
"""
if line is None:
# Empty line
self.write("\n")
else:
# Format the line, if arguments have been given
if args or kwargs:
... | python | def write_line(self, line=None, *args, **kwargs):
"""
Formats and writes a line to the output
"""
if line is None:
# Empty line
self.write("\n")
else:
# Format the line, if arguments have been given
if args or kwargs:
... | [
"def",
"write_line",
"(",
"self",
",",
"line",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"line",
"is",
"None",
":",
"# Empty line",
"self",
".",
"write",
"(",
"\"\\n\"",
")",
"else",
":",
"# Format the line, if arguments hav... | Formats and writes a line to the output | [
"Formats",
"and",
"writes",
"a",
"line",
"to",
"the",
"output"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/beans.py#L234-L257 |
tcalmant/ipopo | pelix/shell/beans.py | IOHandler.write_line_no_feed | def write_line_no_feed(self, line=None, *args, **kwargs):
"""
Formats and writes a line to the output
"""
if line is None:
# Empty line
line = ""
else:
# Format the line, if arguments have been given
if args or kwargs:
... | python | def write_line_no_feed(self, line=None, *args, **kwargs):
"""
Formats and writes a line to the output
"""
if line is None:
# Empty line
line = ""
else:
# Format the line, if arguments have been given
if args or kwargs:
... | [
"def",
"write_line_no_feed",
"(",
"self",
",",
"line",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"line",
"is",
"None",
":",
"# Empty line",
"line",
"=",
"\"\"",
"else",
":",
"# Format the line, if arguments have been given",
"if... | Formats and writes a line to the output | [
"Formats",
"and",
"writes",
"a",
"line",
"to",
"the",
"output"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/beans.py#L259-L277 |
tcalmant/ipopo | samples/handler/logger.py | _LoggerHandlerFactory.get_handlers | def get_handlers(self, component_context, instance):
"""
Sets up service providers for the given component
:param component_context: The ComponentContext bean
:param instance: The component instance
:return: The list of handlers associated to the given component
... | python | def get_handlers(self, component_context, instance):
"""
Sets up service providers for the given component
:param component_context: The ComponentContext bean
:param instance: The component instance
:return: The list of handlers associated to the given component
... | [
"def",
"get_handlers",
"(",
"self",
",",
"component_context",
",",
"instance",
")",
":",
"# Extract information from the context",
"logger_field",
"=",
"component_context",
".",
"get_handler",
"(",
"constants",
".",
"HANDLER_LOGGER",
")",
"if",
"not",
"logger_field",
... | Sets up service providers for the given component
:param component_context: The ComponentContext bean
:param instance: The component instance
:return: The list of handlers associated to the given component
(never None) | [
"Sets",
"up",
"service",
"providers",
"for",
"the",
"given",
"component"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/samples/handler/logger.py#L100-L121 |
tcalmant/ipopo | samples/handler/logger.py | _LoggerHandler.manipulate | def manipulate(self, stored_instance, component_instance):
"""
Called by iPOPO right after the instantiation of the component.
This is the last chance to manipulate the component before the other
handlers start.
:param stored_instance: The iPOPO component StoredInstance
... | python | def manipulate(self, stored_instance, component_instance):
"""
Called by iPOPO right after the instantiation of the component.
This is the last chance to manipulate the component before the other
handlers start.
:param stored_instance: The iPOPO component StoredInstance
... | [
"def",
"manipulate",
"(",
"self",
",",
"stored_instance",
",",
"component_instance",
")",
":",
"# Create the logger for this component instance",
"self",
".",
"_logger",
"=",
"logging",
".",
"getLogger",
"(",
"self",
".",
"_name",
")",
"# Inject it",
"setattr",
"(",... | Called by iPOPO right after the instantiation of the component.
This is the last chance to manipulate the component before the other
handlers start.
:param stored_instance: The iPOPO component StoredInstance
:param component_instance: The component instance | [
"Called",
"by",
"iPOPO",
"right",
"after",
"the",
"instantiation",
"of",
"the",
"component",
".",
"This",
"is",
"the",
"last",
"chance",
"to",
"manipulate",
"the",
"component",
"before",
"the",
"other",
"handlers",
"start",
"."
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/samples/handler/logger.py#L140-L153 |
tcalmant/ipopo | samples/handler/logger.py | _LoggerHandler.clear | def clear(self):
"""
Cleans up the handler. The handler can't be used after this method has
been called
"""
self._logger.debug("Component handlers are cleared")
# Clean up everything to avoid stale references, ...
self._field = None
self._name = None
... | python | def clear(self):
"""
Cleans up the handler. The handler can't be used after this method has
been called
"""
self._logger.debug("Component handlers are cleared")
# Clean up everything to avoid stale references, ...
self._field = None
self._name = None
... | [
"def",
"clear",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Component handlers are cleared\"",
")",
"# Clean up everything to avoid stale references, ...",
"self",
".",
"_field",
"=",
"None",
"self",
".",
"_name",
"=",
"None",
"self",
".",... | Cleans up the handler. The handler can't be used after this method has
been called | [
"Cleans",
"up",
"the",
"handler",
".",
"The",
"handler",
"can",
"t",
"be",
"used",
"after",
"this",
"method",
"has",
"been",
"called"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/samples/handler/logger.py#L189-L199 |
tcalmant/ipopo | pelix/shell/completion/core.py | completion_hints | def completion_hints(config, prompt, session, context, current, arguments):
# type: (CompletionInfo, str, ShellSession, BundleContext, str, List[str]) -> List[str]
"""
Returns the possible completions of the current argument
:param config: Configuration of the current completion
:param prompt: The ... | python | def completion_hints(config, prompt, session, context, current, arguments):
# type: (CompletionInfo, str, ShellSession, BundleContext, str, List[str]) -> List[str]
"""
Returns the possible completions of the current argument
:param config: Configuration of the current completion
:param prompt: The ... | [
"def",
"completion_hints",
"(",
"config",
",",
"prompt",
",",
"session",
",",
"context",
",",
"current",
",",
"arguments",
")",
":",
"# type: (CompletionInfo, str, ShellSession, BundleContext, str, List[str]) -> List[str]",
"if",
"not",
"current",
":",
"# No word yet, so th... | Returns the possible completions of the current argument
:param config: Configuration of the current completion
:param prompt: The shell prompt string
:param session: Current shell session
:param context: Context of the shell UI bundle
:param current: Current argument (to be completed)
:param a... | [
"Returns",
"the",
"possible",
"completions",
"of",
"the",
"current",
"argument"
] | train | https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/completion/core.py#L105-L163 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.