Instruction stringlengths 362 7.83k | output_code stringlengths 1 945 |
|---|---|
Predict the next line for this snippet: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under... | 'providers': ', '.join([prov for prov in get_available_providers() |
Predict the next line for this snippet: <|code_start|> "Report information about oauth2 client applications.",
)
if isinstance(result, int):
return result
else:
settings, closer, env, args = result
try:
db = settings['mongodb'].get_database()
for app in db.app... | key = get_provider_key(provider) |
Here is a snippet: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU... | 'passwords': get_n_passwords(db, user), |
Next line prediction: <|code_start|> 'verified': user.get('email_verified', False),
'date_joined': user.get('date_joined', 'Unknown'),
'last_login': user.get('last_login', 'Unknown'),
}
def users():
result = setup_simple_command(
"users",
"Report information about us... | safe_print(text) |
Predict the next line after this snippet: <|code_start|>#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
... | result = setup_simple_command( |
Using the snippet: <|code_start|># Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of... | url = urlparse.urlparse(response.location) |
Next line prediction: <|code_start|># GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server. If not, see <http://www.gnu.org/licenses/>.
class Gravatar(object):
def __init__(self, request, default_image_url):
... | email_hash, url_encode(parameters)) |
Predict the next line after this snippet: <|code_start|> last_name = ' '.join(parts[1:])
else:
first_name = parts[0]
last_name = ''
return first_name, last_name
def delete_user(db, user):
result = db.users.remove(user['_id'], safe=True)
return result['n'] == 1
def update_user... | provider_key = get_provider_key(provider) |
Based on the snippet: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU A... | message = create_message( |
Based on the snippet: <|code_start|> message = create_message(
request,
'yithlibraryserver.tests:templates/email_test',
{'name': 'John', 'email': 'john@example.com'},
'Testing message', ['john@example.com'],
extra_headers={'foo': 'bar'},
)
... | send_email( |
Given snippet: <|code_start|> 'admin_emails': self.admin_emails,
})
self.config.include('pyramid_mailer.testing')
self.config.include('yithlibraryserver')
super(SendEmailTests, self).setUp()
def test_send_email(self):
request = testing.DummyRequest()
... | send_email_to_admins( |
Given the code snippet: <|code_start|>#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a ... | gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') |
Given the code snippet: <|code_start|> response.encode_content('gzip')
return response
accepted = event.request.accept_encoding.best_match(('identity', 'gzip'))
if 'gzip' == accepted:
event.request.add_response_callback(gzip_response)
def add_base_templates(event):
def get_templat... | config.set_request_property(get_db, 'db', reify=True) |
Given snippet: <|code_start|>
def add_compress_response_callback(event):
def gzip_response(request, response):
response.encode_content('gzip')
return response
accepted = event.request.accept_encoding.best_match(('identity', 'gzip'))
if 'gzip' == accepted:
event.request.add_respons... | 'dates_formatter': DatesFormatter(locale_name), |
Continue the code snippet: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2012-2013 Yaco Sistemas
# Copyright (C) 2012-2013 Alejandro Blanco Escudero <alejandro.b.e@gmail.com>
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith L... | mdb = MongoDB(MONGO_URI) |
Next line prediction: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2012-2013 Yaco Sistemas
# Copyright (C) 2012-2013 Alejandro Blanco Escudero <alejandro.b.e@gmail.com>
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Librar... | mdb = MongoDB(MONGO_URI) |
Predict the next line after this snippet: <|code_start|># (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public L... | self.assertEqual(None, get_user(request)) |
Given the code snippet: <|code_start|> self.config.include('yithlibraryserver.user')
mdb = MongoDB(MONGO_URI)
self.db = mdb.get_database()
def tearDown(self):
testing.tearDown()
self.db.drop_collection('users')
def test_get_user(self):
request = testing.DummyRequ... | self.assertRaises(HTTPFound, assert_authenticated_user_is_registered, request) |
Given the code snippet: <|code_start|># You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server. If not, see <http://www.gnu.org/licenses/>.
CONFIG = """[app:main]
use = egg:yith-library-server
mongo_uri = %s
auth_tk_secret = 123456
testing = True
pyramid_mailer.pre... | mdb = MongoDB(MONGO_URI) |
Given the code snippet: <|code_start|># This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your o... | """ % MONGO_URI |
Using the snippet: <|code_start|>#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your opti... | self.request.datetime_service = FakeDatetimeService(self.request) |
Given the code snippet: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU... | mdb = MongoDB(MONGO_URI) |
Given the following code snippet before the placeholder: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modif... | mdb = MongoDB(MONGO_URI) |
Using the snippet: <|code_start|># but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server. ... | self.assertFalse(include_sticker(1)) |
Continue the code snippet: <|code_start|>
class ModelTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
mdb = MongoDB(MONGO_URI)
self.db = mdb.get_database()
os.environ['YITH_FAKE_DATETIME'] = '2013-1-2-10-11-02'
self.request = testing.DummyRequest... | donation = create_donation(self.request, { |
Next line prediction: <|code_start|>#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your o... | self.assertEqual(get_user_passwords(self.db, user), []) |
Based on the snippet: <|code_start|>
class UtilsTests(TestCase):
clean_collections = ('users', 'passwords', )
def test_get_user_passwords(self):
user_id = self.db.users.insert({
'first_name': 'John',
'last_name': 'Doe',
}, safe=True)
user = self.... | self.assertEqual(get_backup_filename(datetime.date(2012, 10, 28)), |
Predict the next line after this snippet: <|code_start|> 'last_name': 'Doe',
}, safe=True)
user = self.db.users.find_one({'_id': user_id})
self.assertEqual(get_user_passwords(self.db, user), [])
self.db.passwords.insert({
'owner': user_id,
... | self.assertEqual(uncompress(compress(passwords)), passwords) |
Predict the next line after this snippet: <|code_start|> 'last_name': 'Doe',
}, safe=True)
user = self.db.users.find_one({'_id': user_id})
self.assertEqual(get_user_passwords(self.db, user), [])
self.db.passwords.insert({
'owner': user_id,
... | self.assertEqual(uncompress(compress(passwords)), passwords) |
Based on the snippet: <|code_start|>#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a co... | sys.stdout = StringIO() |
Next line prediction: <|code_start|># but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Serve... | result = announce() |
Next line prediction: <|code_start|>class SendEmailTests(TestCase):
def setUp(self):
self.admin_emails = ['admin1@example.com', 'admin2@example.com']
self.config = testing.setUp(settings={
'admin_emails': self.admin_emails,
})
self.config.include('pyramid_mai... | send_thankyou_email(request, donation) |
Based on the snippet: <|code_start|> 'creation': datetime.datetime.utcnow(),
'send_sticker': True,
}
send_thankyou_email(request, donation)
self.assertEqual(len(mailer.outbox), 1)
message = mailer.outbox[0]
self.assertEqual(message.subject, 'Thanks for you... | send_notification_to_admins(request, donation) |
Using the snippet: <|code_start|># Copyright (C) 2012-2013 Alejandro Blanco Escudero <alejandro.b.e@gmail.com>
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it ... | self.assertRaises(HTTPUnauthorized, authorize_user, request) |
Here is a snippet: <|code_start|>#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your opti... | return User(user) |
Predict the next line for this snippet: <|code_start|># (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public Lic... | attachment = Attachment(get_backup_filename(today), |
Continue the code snippet: <|code_start|># Yith Library Server is a password storage server.
# Copyright (C) 2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the ... | passwords = get_user_passwords(request.db, user) |
Next line prediction: <|code_start|># Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy... | compress(passwords)) |
Based on the snippet: <|code_start|># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server. If not, see <http://www.gnu.org/licenses/>.
def get_day_t... | send_email( |
Predict the next line after this snippet: <|code_start|># (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public L... | return _('Log in with ${idp}', mapping={'idp': self.name.capitalize()}) |
Here is a snippet: <|code_start|>
def memoized(fget):
"""
Return a property attribute for new-style classes that only calls its
getter on the first access. The result is stored and on subsequent
accesses is returned, preventing the need to call the getter any more.
https://github.com/estebistec/pyt... | with Timer() as timer: |
Next line prediction: <|code_start|> return result, timer
return timer_wrapper
def timeout(seconds):
"""
Raises a TimeoutError if a function does not terminate within
specified seconds.
"""
def _timeout_error(signal, frame):
raise TimeoutError("Operation did not finish within \... | def reraise(klass=FeetError, message=None, trap=Exception): |
Given the code snippet: <|code_start|> setattr(self, attr_name, fget(self))
return getattr(self, attr_name)
return property(fget_memoized)
def timeit(func):
"""
Returns the number of seconds that a function took along with the result
"""
@wraps(func)
def timer_wrapper(*arg... | raise TimeoutError("Operation did not finish within \ |
Given the code snippet: <|code_start|> 'help': 'entity dictionary'
},
'--txt': {
'metavar': 'PLAIN_FILE',
'required': False,
'help': 'path to a plain text file that will be loaded'
},
'--csv': {
'metavar': 'CSV_FILE',
... | registry = Registry.find_or_create(args.registry, |
Based on the snippet: <|code_start|> },
'--txt': {
'metavar': 'PLAIN_FILE',
'required': False,
'help': 'path to a plain text file that will be loaded'
},
'--csv': {
'metavar': 'CSV_FILE',
'required': False,
'help': 'p... | dict_class=CSVDictionary, |
Based on the snippet: <|code_start|># Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
class NLPEntitiesTests(unittest.TestCase):
def setup(self):
pass
def test_extract_entities(self):
"""
Test
"""
text = 'The United Nations (UN) is an intergov... | result = Parser().extract_entities(text, grammar) |
Predict the next line after this snippet: <|code_start|># -*- coding: utf8 -*-
# feet TornadoWeb server application
#
# Author: Romary Dupuis <romary.dupuis@altarika.com>
#
# Copyright (C) 2016 Romary Dupuis
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
"""
TornadoWeb application definit... | app = make_app() |
Here is a snippet: <|code_start|># Copyright (C) 2016 Romary Dupuis
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
"""
TornadoWeb application definition in Feet.
"""
# tornado Web server
tornado_settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static"),
"cooki... | run(host=settings.server.host, port=settings.server.port) |
Given the code snippet: <|code_start|># -*- coding: utf8 -*-
# test_jptools.py
# Test the Japanese NLP tools
#
# Author: Romary Dupuis <romary.dupuis@altarika.com>
#
# Copyright (C) 2016 Romary Dupuis
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
class JAParserTests(unittest.TestCase):... | self.assertEqual(JAParser(), JAParser()) |
Predict the next line for this snippet: <|code_start|>
# parse test data csv files, quick and dirty
def parse_csv_file(path):
first_line = True
with open(path, 'rb') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
if first_line:
first_line = False
... | Registry.flush('registry_api_test') |
Given the following code snippet before the placeholder: <|code_start|># -*- coding: utf8 -*-
# test_nlp.py
# Test the feet.entities.nlp module
#
# Author: Romary Dupuis <romary.dupuis@altarika.com>
#
# Copyright (C) 2016 Romary Dupuis
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
clas... | self.assertEqual(Parser().detect_language(None), None) |
Predict the next line for this snippet: <|code_start|>
class DropCommand(Command):
name = 'drop'
help = 'Drop an entity dictionary'
args = {
'--registry': {
'metavar': 'REGISTRY',
'default': 'feet',
'required': False,
'help': 'registry of entities'
... | registry = Registry.find_or_create(args.registry, |
Given snippet: <|code_start|># -*- coding: utf8 -*-
# Launch feet server
#
# Author: Romary Dupuis <romary.dupuis@altarika.com>
#
# Copyright (C) 2016 Romary Dupuis
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
class RunCommand(Command):
name = 'run'
help = 'run the feet serve... | 'default': settings.server.host, |
Predict the next line for this snippet: <|code_start|> help = 'run the feet server application'
args = {
'--host': {
'metavar': 'ADDR',
'default': settings.server.host,
'help': 'set the host to run the app on'
},
'--port': {
'metavar': 'PORT... | run(**kwargs) |
Given snippet: <|code_start|># -*- coding: utf8 -*-
# Parser class: provides NLP tools
#
# Author: Romary Dupuis <romary.dupuis@altarika.com>
#
# Copyright (C) 2016 Romary Dupuis
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
WORLD_2_NLTK = {
'english': 'english',
'en': 'english'... | class Parser(LoggingMixin): |
Given the code snippet: <|code_start|> if lang is not None:
lang = WORLD_2_NLTK[lang]
else:
lang = self._lang
if lang == 'japanese':
return JAParser().word_tokenize(text)
else:
if not isinstance(text, unicode):
text = text.de... | @timeit |
Using the snippet: <|code_start|>
F1_NOUN = '名詞'
F1_PARTICLE = '助詞'
F1_CONJONCTION = '接続詞'
F1_INTERJECTION = '感動詞'
F1_VERB = '動詞'
F1_AUXILIARY_VERB = '助動詞'
F1_ADJECTIVE = '形容詞'
F1_SEPARATOR = '記号'
F2_NUMBER = '数'
F2_SUFFIX = '接尾'
F2_SUFFIX_COUNTER = '接尾'
F2_IND_VERB = '自立'
F2_NO_MEANING_NAMES = '非自立'
F2_PRONOUN = '代名詞'... | return MeCab.Tagger('-d %s' % settings.mecab.mecabdict) |
Continue the code snippet: <|code_start|> 'with_year': False
}
]
F1_NOUN = '名詞'
F1_PARTICLE = '助詞'
F1_CONJONCTION = '接続詞'
F1_INTERJECTION = '感動詞'
F1_VERB = '動詞'
F1_AUXILIARY_VERB = '助動詞'
F1_ADJECTIVE = '形容詞'
F1_SEPARATOR = '記号'
F2_NUMBER = '数'
F2_SUFFIX = '接尾'
F2_SUFFIX_COUNTER = '接尾'
F2_IND_VERB = '自立'
F2_... | @memoized |
Predict the next line for this snippet: <|code_start|> 'regex': ur'\d{1}/\d{1}',
'format': '',
'with_year': False
}
]
F1_NOUN = '名詞'
F1_PARTICLE = '助詞'
F1_CONJONCTION = '接続詞'
F1_INTERJECTION = '感動詞'
F1_VERB = '動詞'
F1_AUXILIARY_VERB = '助動詞'
F1_ADJECTIVE = '形容詞'
F1_SEPARATOR = '記号'
F2_NUMBER =... | __metaclass__ = SingletonMetaClass |
Based on the snippet: <|code_start|> {
'regex': ur'\d{1}/\d{1}',
'format': '',
'with_year': False
}
]
F1_NOUN = '名詞'
F1_PARTICLE = '助詞'
F1_CONJONCTION = '接続詞'
F1_INTERJECTION = '感動詞'
F1_VERB = '動詞'
F1_AUXILIARY_VERB = '助動詞'
F1_ADJECTIVE = '形容詞'
F1_SEPARATOR = '記号'
F2_NUMBER = '数'
F2_SUFF... | class JAParser(LoggingMixin): |
Here is a snippet: <|code_start|>"""
configuration = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(name)s %(levelname)s [%(asctime)s] -- %(message)s',
'datefmt': ISO8601_DATETIME,
}
},
'handlers': {
'n... | 'filename': settings.logfile, |
Predict the next line for this snippet: <|code_start|># -*- coding: utf8 -*-
# load_dictionary
# Logging Utility for Feet
#
# Author: Romary Dupuis <romary.dupuis@altarika.com>
# Credits: Benjamin Bengfort <benjamin@bengfort.com>
"""
Logging utility for Feet
"""
configuration = {
'version': 1,
'disable_ex... | 'datefmt': ISO8601_DATETIME, |
Continue the code snippet: <|code_start|># encoding: utf-8
from __future__ import absolute_import, division, print_function
# Copyright (C) 2005-2007 Carabos Coop. V. All rights reserved
# Copyright (C) 2008-2013 Vicent Mas. All rights reserved
#
# This program is free software: you can redistribute ... | if not config.debug and not PY2: |
Given the code snippet: <|code_start|># encoding: utf-8
from __future__ import absolute_import, division, print_function
# Copyright (C) 2005-2007 Carabos Coop. V. All rights reserved
# Copyright (C) 2008-2013 Vicent Mas. All rights reserved
#
# This program is free software: you can redistribute it ... | if not config.debug and not PY2: |
Here is a snippet: <|code_start|># encoding: utf-8
from __future__ import absolute_import, division, print_function
# Copyright (C) 2005-2007 Carabos Coop. V. All rights reserved
# Copyright (C) 2008-2013 Vicent Mas. All rights reserved
#
# This program is free software: you can redistribute it and/o... | VTApp = ExceptionOnGetAttr(e) |
Predict the next line after this snippet: <|code_start|># encoding: utf-8
from __future__ import absolute_import, division, print_function
__version__ = "0.4"
def filter_h5(input_path, output_path, condition, copy_globals=True):
print("filtering for '%s'" % condition)
input_file = tables.open_fil... | copy_table(table, output_entities, condition=condition)
|
Predict the next line after this snippet: <|code_start|> input_file = tables.open_file(input_path)
output_file = tables.open_file(output_path, mode="w")
# copy globals
if copy_globals:
# noinspection PyProtectedMember
input_file.root.globals._f_copy(output_file.root, recursive=True... | timed(filter_h5, args[1], args[2], args[3], eval(args.get(4, 'True')))
|
Predict the next line after this snippet: <|code_start|>
def longest_word(s):
return max(len(w) for w in s.split()) if s else 0
def get_min_width(table, index):
return max(longest_word(row[index]) for row in table)
def table2str(table, missing):
"""table is a list of lists"""
if not table:
... | for minw, width in zip(minwidths, colwidths)] |
Using the snippet: <|code_start|> if self.varargs:
l.append('*' + self.varargs)
if self.varkw:
l.append('**' + self.varkw)
if self.kwonlyargs:
l.extend([k + '=' + repr(self.kwonlydefaults[k])
for k in self.kwonlyargs])
return ', '.... | return l and isinstance(l[-1], basestring) and l[-1].startswith(s) |
Given the following code snippet before the placeholder: <|code_start|> '1.95 Kb'
>>> size2str(10000000)
'9.54 Mb'
>>> size2str(1.27 * 1024 ** 3)
'1.27 Gb'
"""
units = ["bytes", "Kb", "Mb", "Gb", "Tb", "Pb"]
scale = int(math.log(value, 1024)) if value else 0
fmt = "%.2f %s" if scale e... | if config.show_timings: |
Predict the next line for this snippet: <|code_start|># encoding: utf-8
from __future__ import absolute_import, division, print_function
__version__ = "0.1"
def dropfields(input_path, output_path, todrop):
input_file = tables.open_file(input_path, mode="r")
input_root = input_file.root
out... | copy_table(input_root.globals.periodic, output_globals)
|
Here is a snippet: <|code_start|># encoding: utf-8
from __future__ import absolute_import, division, print_function
__version__ = "0.1"
def dropfields(input_path, output_path, todrop):
input_file = tables.open_file(input_path, mode="r")
input_root = input_file.root
output_file = tables.ope... | table_fields = get_fields(table)
|
Predict the next line after this snippet: <|code_start|> print(" * copying globals ...", end=' ')
copy_table(input_root.globals.periodic, output_globals)
print("done.")
output_entities = output_file.create_group("/", "entities", "Entities")
for table in input_file.iterNodes(input_root.entities)... | timed(dropfields, args[1], args[2], args[3:])
|
Here is a snippet: <|code_start|> fname + ' (file1)',
fname + ' (file2)']] +
[[ids[idx], col1[idx], col2[idx]]
for idx in diff]))
if raiseondiff:
r... | input1_rows = index_table_light(table1)
|
Based on the snippet: <|code_start|>
def diff_array(array1, array2, showdiffs=10, raiseondiff=False):
if len(array1) != len(array2):
print("length is different: %d vs %d" % (len(array1),
len(array2)))
ids1 = array1['id']
ids2 = array2[... | fields1 = get_fields(array1)
|
Predict the next line after this snippet: <|code_start|> for fname, _ in merge_items((fields1, fields2)):
print(" - %s:" % fname, end=' ')
if fname not in fnames1:
print("missing in file 1")
continue
elif fname not in fnames2:
print("missing in file ... | print(PrettyTable([['id',
|
Continue the code snippet: <|code_start|> len(array2)))
ids1 = array1['id']
ids2 = array2['id']
all_ids = np.union1d(ids1, ids2)
notin1 = np.setdiff1d(ids1, all_ids)
notin2 = np.setdiff1d(ids2, all_ids)
if notin1:
... | for fname, _ in merge_items((fields1, fields2)):
|
Using the snippet: <|code_start|> :param url: url of the remote repository
:param branch: an optional branch (defaults to 'refs/heads/master')
:return: name/hash of the last revision
"""
if branch is None:
branch = 'refs/heads/master'
output = call('git ls-remote %s %s' % (url, branch))
... | answer = input(msg + choices).lower() |
Using the snippet: <|code_start|> self.extra[key] = value
def __delitem__(self, key):
del self.extra[key]
def __contains__(self, key):
entity = self.entity
period = self.eval_ctx.period
array_period = entity.array_period
# entity.array can be None! (eg. with "exp... | assert list(unique(res)) == res |
Using the snippet: <|code_start|>
def decorate(self, sizefunc, func):
def decorated(*args, **kwargs):
return self.safe_call(sizefunc(*args, **kwargs),
func, *args, **kwargs)
decorated.__name__ = func.__name__
return decorated
def free(self, ... | return prod(shape) * dt.itemsize |
Using the snippet: <|code_start|>#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License fo... | repo = mysql_repo.MysqlRepo(base.config.CONF) |
Here is a snippet: <|code_start|>
def tearDown(self):
super(TestHipchat, self).tearDown()
self.assertTrue(self.trap.empty())
def _http_post_200(self, url, data, **kwargs):
self.trap.put(url)
self.trap.put(data)
r = requestsResponse(200)
return r
@mock.patch(... | notification = m_notification.Notification(0, 'hipchat', 'hipchat notification', |
Given the code snippet: <|code_start|># implied.
# See the License for the specific language governing permissions and
# limitations under the License.
def alarm(metrics):
return {"tenantId": "0",
"alarmId": "0",
"alarmDefinitionId": 0,
"alarmName": "test Alarm",
... | super(TestHipchat, self).setUp(hipchat_notifier.register_opts) |
Given snippet: <|code_start|># distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
def alarm(metrics):
return {"tenant... | class TestHipchat(base.PluginTestCase): |
Using the snippet: <|code_start|>
log = logging.getLogger(__name__)
CONF = cfg.CONF
class RetryEngine(object):
def __init__(self):
self._statsd = get_statsd_client()
self._consumer = client_factory.get_kafka_consumer(
CONF.kafka.url,
CONF.kafka.group,
CONF.ka... | notification = construct_notification_object(self._db_repo, notification_data) |
Predict the next line for this snippet: <|code_start|># Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governi... | self._db_repo = get_db_repo() |
Predict the next line for this snippet: <|code_start|># (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
# Copyright 2017 Fujitsu LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the... | self._statsd = get_statsd_client() |
Predict the next line after this snippet: <|code_start|>#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language gov... | self._notifier = notification_processor.NotificationProcessor() |
Predict the next line after this snippet: <|code_start|># Copyright 2015-2017 FUJITSU LIMITED
# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy o... | aa = models.create_alarm_action_model(metadata).alias('aa') |
Based on the snippet: <|code_start|>
"""
Note:
This plugin doesn't support multi tenancy. Multi tenancy requires support for
multiple JIRA server url. JIRA doesn't support OAUTH2 tokens, we may need to get
the user credentials in query params and store them in monasca DB which we don't want to do.
... | class JiraNotifier(AbstractNotifier): |
Continue the code snippet: <|code_start|> CONF.kafka.legacy_kafka_client_enabled)
self._notifier = notification_processor.NotificationProcessor()
self._db_repo = get_db_repo()
self._period = period
def _keep_sending(self, alarm_id, original_state, period):
try:
... | notification = construct_notification_object(self._db_repo, notification_data) |
Predict the next line for this snippet: <|code_start|># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
log = logging.getLogger(__name__)
CONF = cfg.CONF
class PeriodicEngine(object):
... | self._db_repo = get_db_repo() |
Predict the next line after this snippet: <|code_start|># (C) Copyright 2016 Hewlett Packard Enterprise Development LP
# Copyright 2017 Fujitsu LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the Li... | self._statsd = get_statsd_client() |
Predict the next line for this snippet: <|code_start|># distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
log = logging.... | self._notifier = notification_processor.NotificationProcessor() |
Given the code snippet: <|code_start|>
self._trap = queue.Queue()
mock_log = mock.Mock()
mock_log.info = self._trap.put
mock_log.debug = self._trap.put
mock_log.warn = self._trap.put
mock_log.error = self._trap.put
mock_log.exception = self._trap.put
sel... | notification = m_notification.Notification(0, 'jira', |
Based on the snippet: <|code_start|> 'project': {'key': 'MyProject'},
'summary': 'Monasca alarm for alarm_defintion test Alarm status '
'changed to ALARM for the alarm_id 0'}}
if component:
issue['fields'].update({'components'... | jira_notifier.register_opts |
Here is a snippet: <|code_start|> 'stateChangeReason': 'I am alarming!',
'timestamp': 1429023453632,
'metrics': {'dimension': {'hostname': 'foo1', 'service': 'bar1'}}}
def issue(component=True, custom_config=False):
issue = {'fields': {'description': 'Monasca alarm',
... | class TestJira(base.PluginTestCase): |
Predict the next line for this snippet: <|code_start|># Copyright 2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless ... | self._rep = orm_repo.OrmRepo() |
Predict the next line for this snippet: <|code_start|> alarm = self._create_raw_alarm(0, 3, alarm_dict)
notifications, partition, offset = self._run_alarm_processor(alarm, None)
self.assertEqual(notifications, [])
self.assertEqual(partition, 0)
self.assertEqual(offset, 3)
d... | test_notification = m_notification.Notification(1, 'email', 'test notification', |
Next line prediction: <|code_start|> json_msg = json.dumps({'alarm-transitioned': message})
msg_tuple = message_tuple(key, json_msg)
return legacy_kafka_message.LegacyKafkaMessage([partition,
alarm_tuple(offset,
... | processor = alarm_processor.AlarmProcessor() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.