function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def n_meas(self): """ Returns the sum of any tuple in the domain. :rtype: `int` """ return self._n_meas
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def n_elements(self): """ Returns the number of elements of a tuple in the domain. :rtype: `int` """ return self._n_elements
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def is_continuous(self): """ Whether or not the domain has an uncountable number of values. :type: `bool` """ return False
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def is_finite(self): """ Whether or not the domain contains a finite number of points. :type: `bool` """ return True
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def dtype(self): """ The numpy dtype of a single element of the domain. :type: `np.dtype` """ return np.dtype([('k', np.int, self.n_elements)])
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def n_members(self): """ Returns the number of members in the domain if it `is_finite`, otherwise, returns `None`. :type: ``int`` """ return int(binom(self.n_meas + self.n_elements -1, self.n_elements - 1))
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def example_point(self): """ Returns any single point guaranteed to be in the domain, but no other guarantees; useful for testing purposes. This is given as a size 1 ``np.array`` of type ``dtype``. :type: ``np.ndarray`` """ return np.array([([self.n_meas] + [0] *...
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def values(self): """ Returns an `np.array` of type `self.dtype` containing some values from the domain. For domains where ``is_finite`` is ``True``, all elements of the domain will be yielded exactly once. :rtype: `np.ndarray` """ # This code comes from...
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def to_regular_array(self, A): """ Converts from an array of type `self.dtype` to an array of type `int` with an additional index labeling the tuple indeces. :param np.ndarray A: An `np.array` of type `self.dtype`. :rtype: `np.ndarray` """ # this could b...
QInfer/python-qinfer
[ 91, 32, 91, 22, 1344992565 ]
def __init__(self, request, exc_type, exc_value, frames): ExceptionReporter.__init__(self, request, exc_type, exc_value, None) self.frames = frames
dcramer/django-db-log
[ 116, 25, 116, 8, 1253216083 ]
def get_traceback_html(self): "Return HTML code for traceback." if issubclass(self.exc_type, TemplateDoesNotExist): self.template_does_not_exist = True if (settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source') and isinstance(self.exc_value, TemplateSyntaxError)):...
dcramer/django-db-log
[ 116, 25, 116, 8, 1253216083 ]
def ResponseFromHandler(self, path): content = "Hello from handler" return self.MakeResponse(content, "text/html", False)
catapult-project/catapult
[ 1835, 570, 1835, 1039, 1429033745 ]
def setUp(self): super(MemoryCacheHTTPServerTest, self).setUp() self._test_filename = 'bear.webm' test_file = os.path.join(util.GetUnittestDataDir(), 'bear.webm') self._test_file_size = os.stat(test_file).st_size
catapult-project/catapult
[ 1835, 570, 1835, 1039, 1429033745 ]
def CheckContentHeaders(self, content_range_request, content_range_response, content_length_response): self._tab.ExecuteJavaScript( """ var loaded = false; var xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function(e) { loaded = true; };...
catapult-project/catapult
[ 1835, 570, 1835, 1039, 1429033745 ]
def __init__(self, project): self.project = project self.stripped_js_by_filename = {} self.loaded_modules = {} self.loaded_raw_scripts = {} self.loaded_style_sheets = {} self.loaded_images = {}
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def source_paths(self): """A list of base directories to search for modules under.""" return self.project.source_paths
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def FindResourceGivenAbsolutePath(self, absolute_path, binary=False): """Returns a Resource for the given absolute path.""" candidate_paths = [] for source_path in self.source_paths: if absolute_path.startswith(source_path): candidate_paths.append(source_path) if len(candidate_paths) == 0:...
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def _FindResourceGivenNameAndSuffix( self, requested_name, extension, return_resource=False): """Searches for a file and reads its contents. Args: requested_name: The name of the resource that was requested. extension: The extension for this requested resource. Returns: A (path, ...
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def LoadModule(self, module_name=None, module_filename=None, excluded_scripts=None): assert bool(module_name) ^ bool(module_filename), ( 'Must provide either module_name or module_filename.') if module_filename: resource = self.FindResource(module_filename) if not resource: ...
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def LoadStyleSheet(self, name): if name in self.loaded_style_sheets: return self.loaded_style_sheets[name] resource = self._FindResourceGivenNameAndSuffix( name, '.css', return_resource=True) if not resource: raise module.DepsException( 'Could not find a file for stylesheet %s...
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def GetStrippedJSForFilename(self, filename, early_out_if_no_py_vulcanize): if filename in self.stripped_js_by_filename: return self.stripped_js_by_filename[filename] with open(filename, 'r') as f: contents = f.read(4096) if early_out_if_no_py_vulcanize and ('py_vulcanize' not in contents): ...
endlessm/chromium-browser
[ 21, 16, 21, 3, 1435959644 ]
def main(): """ This Python script displays a web page with test created with the video_quality_measurement program, which is a tool in WebRTC. The script requires on two external files and one Python library: - A HTML template file with layout and references to the json variables defined in this script ...
golden1232004/webrtc_new
[ 7, 5, 7, 1, 1467039620 ]
def ShowErrorPage(error_message): print '<html><body>%s</body></html>' % error_message
golden1232004/webrtc_new
[ 7, 5, 7, 1, 1467039620 ]
def GabeToCsv(filepath,csvpath): """ Converti un fichier GABE (Generic Array Binary Exchange) en format CSV (Comma Separated Values) """ # Instanciation du lecteur reader=ls.Gabe_rw() # Lecture du fichier gabe if reader.Load(filepath): # Conversion en liste data=...
Ifsttar/I-Simpa
[ 185, 54, 185, 114, 1395306706 ]
def get_media_url(url): try: HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', ...
mrknow/filmkodi
[ 68, 68, 68, 206, 1444160337 ]
def make_casa_testimage(infile, outname): infile = str(infile) outname = str(outname) if not CASA_INSTALLED: raise Exception("Attempted to make a CASA test image in a non-CASA " "environment") ia = image() ia.fromfits(infile=infile, outfile=outname, overwrite=True...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def filename(request): return request.getfixturevalue(request.param)
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_read_basic(memmap, bigendian): # Check that SpectralCube.read works for an example CASA dataset stored # in the tests directory. This test should NOT require CASA, whereas a # number of tests below require CASA to generate test datasets. The present # test is to ensure CASA is not require...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_read_basic_nomask(): # Make sure things work well if there is no mask in the data cube = SpectralCube.read(os.path.join(DATA, 'nomask.image')) assert cube.shape == (3, 4, 5) assert_allclose(cube.wcs.pixel_to_world_values(1, 2, 3), [2.406271e+01, 2.993521e+01, 1.421911...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_read(filename, tmp_path): # Check that SpectralCube.read returns data with the same shape and values # if read from CASA as if read from FITS. cube = SpectralCube.read(filename) make_casa_testimage(filename, tmp_path / 'casa.image') casacube = SpectralCube.read(tmp_path / 'casa.ima...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_read_nomask(filename, tmp_path): # As for test_casa_read, but we remove the mask to make sure # that we can still read in the cubes cube = SpectralCube.read(filename) make_casa_testimage(filename, tmp_path / 'casa.image') shutil.rmtree(tmp_path / 'casa.image' / 'mask0') casacub...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_read_stokes(data_advs, tmp_path): # Check that StokesSpectralCube.read returns data with the same shape and values # if read from CASA as if read from FITS. cube = StokesSpectralCube.read(data_advs) make_casa_testimage(data_advs, tmp_path / 'casa.image') casacube = StokesSpectralCu...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_mask(data_adv, tmp_path): # This tests the make_casa_mask function which can be used to create a mask # file in an existing image. cube = SpectralCube.read(data_adv) mask_array = np.array([[True, False], [False, False], [True, True]]) bool_mask = BooleanArrayMask(mask=mask_array, wc...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def test_casa_mask_append(data_adv, tmp_path): # This tests the append option for the make_casa_mask function cube = SpectralCube.read(data_adv) mask_array = np.array([[True, False], [False, False], [True, True]]) bool_mask = BooleanArrayMask(mask=mask_array, wcs=cube._wcs, ...
radio-astro-tools/spectral-cube
[ 84, 57, 84, 183, 1397489630 ]
def capwords(s, sep=None): """capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None, runs of whitespace characters are replaced by a single spac...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def __init__(cls, name, bases, dct): super(_TemplateMetaclass, cls).__init__(name, bases, dct) if 'pattern' in dct: pattern = cls.pattern else: pattern = _TemplateMetaclass.pattern % { 'delim' : _re.escape(cls.delimiter), 'id' : cls.idpa...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def __init__(self, template): self.template = template
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def _invalid(self, mo): i = mo.start('invalid') lines = self.template[:i].splitlines(keepends=True) if not lines: colno = 1 lineno = 1 else: colno = i - len(''.join(lines[:-1])) lineno = len(lines) raise ValueError('Invalid placehol...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def convert(mo): # Check the most common path first. named = mo.group('named') or mo.group('braced') if named is not None: val = mapping[named] # We use this idiom instead of str() because the latter will # fail if val is a Unicode cont...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def safe_substitute(*args, **kws): if not args: raise TypeError("descriptor 'safe_substitute' of 'Template' object " "needs an argument") self, *args = args # allow the "self" keyword be passed if len(args) > 1: raise TypeError('Too many posit...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def format(*args, **kwargs): if not args: raise TypeError("descriptor 'format' of 'Formatter' object " "needs an argument") self, *args = args # allow the "self" keyword be passed try: format_string, *args = args # allow the "format_string" ke...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def _vformat(self, format_string, args, kwargs, used_args, recursion_depth, auto_arg_index=0): if recursion_depth < 0: raise ValueError('Max string recursion exceeded') result = [] for literal_text, field_name, format_spec, conversion in \ self.parse(...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def check_unused_args(self, used_args, args, kwargs): pass
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def convert_field(self, value, conversion): # do any conversion on the resulting object if conversion is None: return value elif conversion == 's': return str(value) elif conversion == 'r': return repr(value) elif conversion == 'a': ...
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def parse(self, format_string): return _string.formatter_parser(format_string)
jameswatt2008/jameswatt2008.github.io
[ 1, 1, 1, 1, 1414399890 ]
def __init__ (self): TestBase.__init__ (self, __file__) self.name = "Header Ops: Add multiple headers" self.request = "GET /%s/ HTTP/1.0\r\n" %(DIR) self.expected_error = 200 self.conf = CONF%(globals()) n = 2 for h,v in HEADERS: ...
cherokee/webserver
[ 561, 103, 561, 433, 1318335564 ]
def setUp(self): super(UserManagementHelperTest, self).setUp() self.request = RequestFactory().post('/') self.old_user = UserFactory.create() self.new_user = UserFactory.create() self.new_user.save() self.request.user = self.old_user self.lti_consumer = LtiConsume...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_permission_denied_for_unknown_user(self, _authenticate_mock): with self.assertRaises(PermissionDenied): users.switch_user(self.request, self.lti_user, self.lti_consumer)
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_authenticate_called(self, _login_mock): with patch('lti_provider.users.authenticate', return_value=self.new_user) as authenticate: users.switch_user(self.request, self.lti_user, self.lti_consumer) authenticate.assert_called_with( username=self.new_user.username, ...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_login_called(self, login_mock): with patch('lti_provider.users.authenticate', return_value=self.new_user): users.switch_user(self.request, self.lti_user, self.lti_consumer) login_mock.assert_called_with(self.request, self.new_user)
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def setUp(self): super(AuthenticateLtiUserTest, self).setUp() self.lti_consumer = LtiConsumer( consumer_name='TestConsumer', consumer_key='TestKey', consumer_secret='TestSecret' ) self.lti_consumer.save() self.lti_user_id = 'lti_user_id' ...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_authentication_with_new_user(self, _create_user, switch_user): lti_user = MagicMock() lti_user.edx_user_id = self.edx_user_id with patch('lti_provider.users.create_lti_user', return_value=lti_user) as create_user: users.authenticate_lti_user(self.request, self.lti_user_id, s...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_authentication_with_unauthenticated_user(self, create_user, switch_user): lti_user = self.create_lti_user_model() self.request.user = lti_user.edx_user self.request.user.is_authenticated = MagicMock(return_value=False) users.authenticate_lti_user(self.request, self.lti_user_id, ...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def setUp(self): super(CreateLtiUserTest, self).setUp() self.lti_consumer = LtiConsumer( consumer_name='TestConsumer', consumer_key='TestKey', consumer_secret='TestSecret' ) self.lti_consumer.save()
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_create_lti_user_creates_correct_user(self, uuid_mock, _username_mock): users.create_lti_user('lti_user_id', self.lti_consumer) self.assertEqual(User.objects.count(), 1) user = User.objects.get(username='edx_id') self.assertEqual(user.email, 'edx_id@lti.example.com') uuid...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_unique_username_created(self, username_mock): User(username='edx_id').save() users.create_lti_user('lti_user_id', self.lti_consumer) self.assertEqual(username_mock.call_count, 2) self.assertEqual(User.objects.count(), 2) user = User.objects.get(username='new_edx_id') ...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def setUp(self): super(LtiBackendTest, self).setUp() self.edx_user = UserFactory.create() self.edx_user.save() self.lti_consumer = LtiConsumer( consumer_key="Consumer Key", consumer_secret="Consumer Secret" ) self.lti_consumer.save() self.l...
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_missing_user_returns_none(self): user = users.LtiBackend().authenticate( username=self.edx_user.username, lti_user_id='Invalid Username', lti_consumer=self.lti_consumer ) self.assertIsNone(user)
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_missing_lti_id_returns_null(self): user = users.LtiBackend().authenticate( username=self.edx_user.username, lti_consumer=self.lti_consumer ) self.assertIsNone(user)
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def test_existing_user_returned_by_get_user(self): user = users.LtiBackend().get_user(self.edx_user.id) self.assertEqual(user, self.edx_user)
miptliot/edx-platform
[ 1, 7, 1, 5, 1382087527 ]
def main(self): while 1: self.send(str(self.value), "outbox") time.sleep(self.sleep)
sparkslabs/kamaelia_
[ 13, 3, 13, 2, 1348148442 ]
def assert_same_cluster(self, lhs, rhs): self.assertEqual( server_lib.ClusterSpec(lhs).as_dict(), server_lib.ClusterSpec(rhs).as_dict())
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testClusterDefAsInput(self): cluster_def = cluster_pb2.ClusterDef() job = cluster_def.job.add() job.name = "chief" job.tasks[0] = "127.0.0.1:1234" job = cluster_def.job.add() job.name = "worker" job.tasks[0] = "127.0.0.1:8964" job.tasks[1] = "127.0.0.1:2333" job = cluster_def.j...
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testUnexpectedInput(self): cluster_spec = ["127.0.0.1:8964", "127.0.0.1:2333"] with self.assertRaisesRegex( ValueError, "`cluster_spec' should be dict or a `tf.train.ClusterSpec` or a " "`tf.train.ClusterDef` object"): multi_worker_util.normalize_cluster_spec(cluster_spec)
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testClusterWithChief(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "ps": ["127.0.0.1:1926", "127.0.0.1:3141"] } self.assertTrue(multi_worker_util.is_chief(cluster_spec, "chief", 0)) self.assertFalse(multi_worker_util.is_c...
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testEvaluatorIsChief(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "evaluator": ["127.0.0.1:2019"] } self.assertTrue(multi_worker_util.is_chief(cluster_spec, "evaluator", 0))
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testCountWorker(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "ps": ["127.0.0.1:1926", "127.0.0.1:3141"] } self.assertEqual( multi_worker_util.worker_count(cluster_spec, task_type="chief"), 3) self.assertEqual( ...
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testTaskTypeNotFound(self): cluster_spec = {} with self.assertRaisesRegex( ValueError, "`task_type` 'worker' not found in cluster_spec."): multi_worker_util.worker_count(cluster_spec, task_type="worker")
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testChiefId(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "ps": ["127.0.0.1:1926", "127.0.0.1:3141"] } self.assertEqual( multi_worker_util.id_in_cluster(cluster_spec, "chief", 0), 0)
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testEvaluatorId(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "evaluator": ["127.0.0.1:7566"] } self.assertEqual( multi_worker_util.id_in_cluster(cluster_spec, "evaluator", 0), 0)
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testMultipleChiefs(self): cluster_spec = { "chief": ["127.0.0.1:8258", "127.0.0.1:7566"], } with self.assertRaisesRegex(ValueError, "There must be at most one 'chief' job."): multi_worker_util.id_in_cluster(cluster_spec, "chief", 0)
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testChiefAsLeader(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "ps": ["127.0.0.1:1926", "127.0.0.1:3141"] } self.assertEqual( multi_worker_util.collective_leader(cluster_spec, "worker", 0), "/job:chief/replic...
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testLeaderForEvaluator(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "ps": ["127.0.0.1:1926", "127.0.0.1:3141"], "evaluator": ["127.0.0.1:2019"] } self.assertEqual( multi_worker_util.collective_leader(cluster_...
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def testEvaluatorNotInCluster(self): cluster_spec = { "chief": ["127.0.0.1:1234"], "worker": ["127.0.0.1:8964", "127.0.0.1:2333"], "ps": ["127.0.0.1:1926", "127.0.0.1:3141"] } multi_worker_util._validate_cluster_spec(cluster_spec, "chief", 0) multi_worker_util._validate_cluster_s...
tensorflow/tensorflow
[ 171949, 87931, 171949, 2300, 1446859160 ]
def add(self, x, y): return x + y
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def sub(self, x, y): return x - y
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def square(self, x): if x > 1000: ## raise a custom exception raise Exception("http://example.com/error#number_too_big", "number %d too big to square" % x) return x * x
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def sum(self, list): return reduce(lambda x, y: x + y, list)
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def pickySum(self, list): errs = [] for i in list: if i % 3 == 0: errs.append(i) if len(errs) > 0: raise Exception("http://example.com/error#invalid_numbers", "one or more numbers are multiples of 3", errs) return reduce(lambda x, y: x + y, ...
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def sqrt(self, x): return math.sqrt(x)
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def asyncSum(self, list): ## Simulate a slow function. d = defer.Deferred() reactor.callLater(3, d.callback, self.sum(list)) return d
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def __init__(self, filename): self.store = shelve.open(filename)
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def set(self, key = None, value = None): if key is not None: k = str(key) if value is not None: self.store[k] = value else: if self.store.has_key(k): del self.store[k] else: self.store.clear()
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def get(self, key = None): if key is None: return self.store.items() else: return self.store.get(str(key), None)
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def keys(self): return self.store.keys()
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def __init__(self): self.clear()
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def calc(self, arg): op = arg["op"] if op == "C": self.clear() return str(self.current) num = decimal.Decimal(arg["num"]) if self.op: if self.op == "+": self.current += num elif self.op == "-": self.current -= num elif self....
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def __init__(self, allowedTopicIds): self.allowedTopicIds = allowedTopicIds self.serial = 0
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def subscribe(self, topicUriPrefix, topicUriSuffix): """ Custom topic subscription handler. """ print "client wants to subscribe to %s%s" % (topicUriPrefix, topicUriSuffix) try: i = int(topicUriSuffix) if i in self.allowedTopicIds: print "Subscribing client to...
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def publish(self, topicUriPrefix, topicUriSuffix, event): """ Custom topic publication handler. """ print "client wants to publish to %s%s" % (topicUriPrefix, topicUriSuffix) try: i = int(topicUriSuffix) if type(event) == dict and event.has_key("count"): if ev...
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def onSessionOpen(self): self.initSimpleRpc() self.initKeyValue() self.initCalculator() self.initSimplePubSub() self.initPubSubAuth()
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def initKeyValue(self): ## Key-Value Store self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#")
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def initSimplePubSub(self): ## register a single, fixed URI as PubSub topic self.registerForPubSub("http://example.com/simple") ## register a URI and all URIs having the string as prefix as PubSub topic self.registerForPubSub("http://example.com/event#", True) ## register any URI (string...
normanmaurer/autobahntestsuite-maven-plugin
[ 5, 7, 5, 2, 1354609119 ]
def upgrade_charm(): # Trigger removal of PPA docker installation if it was previously set. set_state('config.changed.install_from_upstream') hookenv.atexit(remove_state, 'config.changed.install_from_upstream') cleanup_pre_snap_services() check_resources_for_upgrade_needed() # Remove the RC fo...
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]
def set_upgrade_needed(): set_state('kubernetes-worker.snaps.upgrade-needed') config = hookenv.config() previous_channel = config.previous('channel') require_manual = config.get('require-manual-upgrade') if previous_channel is None or not require_manual: set_state('kubernetes-worker.snaps.up...
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]
def channel_changed(): set_upgrade_needed()
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]
def upgrade_needed_status(): msg = 'Needs manual upgrade, run the upgrade action' hookenv.status_set('blocked', msg)
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]
def install_snaps(): check_resources_for_upgrade_needed() channel = hookenv.config('channel') hookenv.status_set('maintenance', 'Installing kubectl snap') snap.install('kubectl', channel=channel, classic=True) hookenv.status_set('maintenance', 'Installing kubelet snap') snap.install('kubelet', c...
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]
def shutdown(): ''' When this unit is destroyed: - delete the current node - stop the worker services ''' try: if os.path.isfile(kubeconfig_path): kubectl('delete', 'node', gethostname().lower()) except CalledProcessError: hookenv.log('Failed to unregister nod...
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]
def install_cni_plugins(): ''' Unpack the cni-plugins resource ''' charm_dir = os.getenv('CHARM_DIR') # Get the resource via resource_get try: resource_name = 'cni-{}'.format(arch()) archive = hookenv.resource_get(resource_name) except Exception: message = 'Error fetching th...
cncf/cross-cloud
[ 164, 57, 164, 40, 1494451575 ]