_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q41100 | get_match_info | train | def get_match_info(template, match, state):
"""
Given a template and a regex match within said template, return a
dictionary of information about the match to be used to help parse the
template.
"""
info = match.groupdict()
# Put special delimiter cases in terms of normal ones
if info['... | python | {
"resource": ""
} |
q41101 | get_tag_context | train | def get_tag_context(name, state):
"""
Given a tag name, return its associated value as defined in the current
context stack.
"""
new_contexts = 0
ctm = None
while True:
try:
ctx_key, name = name.split('.', 1)
ctm = state.context.get(ctx_key)
except Val... | python | {
"resource": ""
} |
q41102 | render | train | def render(template, context, partials={}, state=None):
""" Renders a given mustache template, with sane defaults. """
# Create a new state by default
state = state or State()
# Add context to the state dict
if isinstance(context, Context):
state.context = context
else:
state.co... | python | {
"resource": ""
} |
q41103 | parallel | train | def parallel(func, inputs, n_jobs, expand_args=False):
"""
Convenience wrapper around joblib's parallelization.
"""
if expand_args:
return Parallel(n_jobs=n_jobs)(delayed(func)(*args) for args in inputs)
else:
return Parallel(n_jobs=n_jobs)(delayed(func)(arg) for arg in inputs) | python | {
"resource": ""
} |
q41104 | breeding_plugevent | train | def breeding_plugevent(request, breeding_id):
"""This view defines a form for adding new plug events from a breeding cage.
This form requires a breeding_id from a breeding set and restricts the PlugFemale and PlugMale to animals that are defined in that breeding cage."""
breeding = get_object_or_404(Breedi... | python | {
"resource": ""
} |
q41105 | PlugEventsListStrain.get_queryset | train | def get_queryset(self):
"""The queryset is over-ridden to show only plug events in which the strain matches the breeding strain."""
self.strain = get_object_or_404(Strain, Strain_slug__iexact=self.kwargs['slug'])
return PlugEvents.objects.filter(Breeding__Strain=self.strain) | python | {
"resource": ""
} |
q41106 | command | train | def command(state, args):
"""Fix cache issues caused by schema pre-v4."""
if len(args) > 1:
print(f'Usage: {args[0]}')
return
db = state.db
_refresh_incomplete_anime(db)
_fix_cached_completed(db) | python | {
"resource": ""
} |
q41107 | sync_local_to_remote | train | def sync_local_to_remote(force="no"):
"""
Sync your local postgres database with remote
Example:
fabrik prod sync_local_to_remote:force=yes
"""
_check_requirements()
if force != "yes":
message = "This will replace the remote database '%s' with your "\
"local '%s', ... | python | {
"resource": ""
} |
q41108 | sync_remote_to_local | train | def sync_remote_to_local(force="no"):
"""
Sync your remote postgres database with local
Example:
fabrik prod sync_remote_to_local
"""
_check_requirements()
if force != "yes":
message = "This will replace your local database '%s' with the "\
"remote '%s', are you su... | python | {
"resource": ""
} |
q41109 | TCPCheck.apply_check_config | train | def apply_check_config(self, config):
"""
Takes the `query` and `response` fields from a validated config
dictionary and sets the proper instance attributes.
"""
self.query = config.get("query")
self.expected_response = config.get("response") | python | {
"resource": ""
} |
q41110 | TCPCheck.perform | train | def perform(self):
"""
Performs a straightforward TCP request and response.
Sends the TCP `query` to the proper host and port, and loops over the
socket, gathering response chunks until a full line is acquired.
If the response line matches the expected value, the check passes. ... | python | {
"resource": ""
} |
q41111 | RLConfig._get_section_values | train | def _get_section_values(self, config, section):
""" extract src and dst values from a section
"""
src_host = self._get_hosts_from_names(config.get(section, 'src.host')) \
if config.has_option(section, 'src.host') else None
src_file = [self._get_abs_filepath(config.get(section... | python | {
"resource": ""
} |
q41112 | RLConfig._assemble_flowtable | train | def _assemble_flowtable(self, values):
""" generate a flowtable from a tuple of descriptors.
"""
values = map(lambda x: [] if x is None else x, values)
src = values[0] + values[1]
dst = values[2] + values[3]
thistable = dict()
for s in src:
thistable[... | python | {
"resource": ""
} |
q41113 | RLConfig._detect_loop | train | def _detect_loop(self):
""" detect loops in flow table, raise error if being present
"""
for source, dests in self.flowtable.items():
if source in dests:
raise conferr('Loops detected: %s --> %s' % (source, source)) | python | {
"resource": ""
} |
q41114 | RLConfig._get_hosts_from_ports | train | def _get_hosts_from_ports(self, ports):
""" validate hostnames from a list of ports
"""
hosts = map(lambda x: 'localhost:%d' % int(x.strip()), ports.split(','))
return list(set(hosts)) | python | {
"resource": ""
} |
q41115 | RLConfig._get_hosts_from_names | train | def _get_hosts_from_names(self, names):
""" validate hostnames from a list of names
"""
result = set()
hosts = map(lambda x: x.strip(), names.split(','))
for h in hosts:
if valid_hostname(h.split(':')[0]):
result.add(h if ':' in h else '%s:%d' % (h, se... | python | {
"resource": ""
} |
q41116 | RLConfig._get_abs_filepath | train | def _get_abs_filepath(self, ifile):
""" validate src or dst file path with self.config_file
"""
assert ifile is not None
ifile = ifile[7:] if ifile.startswith('file://') else ifile
if ifile[0] != '/':
basedir = os.path.abspath(os.path.dirname(self.config_file))
... | python | {
"resource": ""
} |
q41117 | RLConfig.flowtable | train | def flowtable(self):
""" get a flat flow table globally
"""
ftable = dict()
for table in self.flow_table:
for k, v in table.items():
if k not in ftable:
ftable[k] = set(v)
else:
[ftable[k].add(i) for i in... | python | {
"resource": ""
} |
q41118 | _set_last_aid | train | def _set_last_aid(func):
"""Decorator for setting last_aid."""
@functools.wraps(func)
def new_func(self, *args, **kwargs):
# pylint: disable=missing-docstring
aid = func(self, *args, **kwargs)
self.last_aid = aid
return aid
return new_func | python | {
"resource": ""
} |
q41119 | AIDResultsManager.parse_aid | train | def parse_aid(self, text, default_key):
"""Parse argument text for aid.
May retrieve the aid from search result tables as necessary. aresults
determines which search results to use by default; True means aresults
is the default.
The last aid when no aid has been parsed yet is ... | python | {
"resource": ""
} |
q41120 | _connect | train | def _connect(dbfile: 'PathLike') -> apsw.Connection:
"""Connect to SQLite database file."""
conn = apsw.Connection(os.fspath(dbfile))
_set_foreign_keys(conn, 1)
assert _get_foreign_keys(conn) == 1
return conn | python | {
"resource": ""
} |
q41121 | AnimeCmd.cmdloop | train | def cmdloop(self):
"""Start CLI REPL."""
while True:
cmdline = input(self.prompt)
tokens = shlex.split(cmdline)
if not tokens:
if self.last_cmd:
tokens = self.last_cmd
else:
print('No previous com... | python | {
"resource": ""
} |
q41122 | Volume.to_array | train | def to_array(self, channels=2):
"""Generate the array of multipliers for the dynamic"""
return np.linspace(self.volume, self.volume,
self.duration * channels).reshape(self.duration, channels) | python | {
"resource": ""
} |
q41123 | add_measurement | train | def add_measurement(request, experiment_id):
"""This is a view to display a form to add single measurements to an experiment.
It calls the object MeasurementForm, which has an autocomplete field for animal."""
experiment = get_object_or_404(Experiment, pk=experiment_id)
if request.method == 'POST':
form = Measu... | python | {
"resource": ""
} |
q41124 | litters_csv | train | def litters_csv(request):
"""This view generates a csv output file of all animal data for use in litter analysis.
The view writes to a csv table the birthdate, breeding cage and strain."""
animal_list = Animal.objects.all()
response = HttpResponse(content_type='text/csv')
response['Content-Dispositio... | python | {
"resource": ""
} |
q41125 | data_csv | train | def data_csv(request, measurement_list):
"""This view generates a csv output of all data for a strain.
For this function to work, you have to provide the filtered set of measurements."""
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=data.c... | python | {
"resource": ""
} |
q41126 | MeasurementListCSV.get | train | def get(self, request, *args, **kwargs):
'''The queryset returns all measurement objects'''
measurements = Measurement.objects.all()
return data_csv(self.request, measurements) | python | {
"resource": ""
} |
q41127 | Doc2VecVectorizer.train | train | def train(self, docs, retrain=False):
'''
Train Doc2Vec on a series of docs. Train from scratch or update.
Args:
docs: list of tuples (assetid, body_text) or dictionary {assetid : body_text}
retrain: boolean, retrain from scratch or update model
saves model in c... | python | {
"resource": ""
} |
q41128 | Doc2VecVectorizer._process | train | def _process(self, input):
'''
Takes in html-mixed body text as a string and returns a list of strings,
lower case and with punctuation given spacing.
Called by self._gen_sentence()
Args:
inpnut (string): body text
'''
input = re.sub("<[^>]*>", " "... | python | {
"resource": ""
} |
q41129 | Doc2VecVectorizer._gen_sentence | train | def _gen_sentence(self, assetid_body_tuple):
'''
Takes an assetid_body_tuple and returns a Doc2Vec LabeledSentence
Args:
assetid_body_tuple (tuple): (assetid, bodytext) pair
'''
asset_id, body = assetid_body_tuple
text = self._process(body)
sentence... | python | {
"resource": ""
} |
q41130 | Doc2VecVectorizer._add_new_labels | train | def _add_new_labels(self, sentences):
'''
Adds new sentences to the internal indexing of the model.
Args:
sentences (list): LabeledSentences for each doc to be added
Returns:
int: number of sentences added to the model
'''
sentence_no = -1
... | python | {
"resource": ""
} |
q41131 | run | train | def run(targets, config_dir='.', check_licenses=False):
# type: (List[str], str, bool) -> None
"""Runs `pylint` and `flake8` commands and exits based off the evaluation
of both command results.
:param targets: List[str]
:param config_dir: str
:param check_licenses: bool
:return:
"""
... | python | {
"resource": ""
} |
q41132 | _run_command | train | def _run_command(command, targets, options):
# type: (str, List[str], List[str]) -> bool
"""Runs `command` + `targets` + `options` in a
subprocess and returns a boolean determined by the
process return code.
>>> result = run_command('pylint', ['foo.py', 'some_module'], ['-E'])
>>> result
Tr... | python | {
"resource": ""
} |
q41133 | ynnm | train | def ynnm(n, m):
"""Initial value for recursion formula"""
a = 1.0 / np.sqrt(4.0 * np.pi)
pm = np.abs(m)
out = 0.0
if(n < pm):
out = 0.0
elif(n == 0):
out = a
else:
out = a
for k in xrange(1, n + 1):
out *= np.sqrt((2.0 * k + 1.0) /... | python | {
"resource": ""
} |
q41134 | ynunm | train | def ynunm(n, m, L):
"""Fourier coefficients for spherical harmonics"""
out = np.zeros(L, dtype=np.float64)
tmp1 = 0
tmp2 = 0
tmp3 = 0
tmp4 = 0
if(np.abs(m) <= n):
out[n] = ynnm(n, m)
k = n - 2
if(k >= 0):
tmp1 = (n - k - 1.0) * (n + k ... | python | {
"resource": ""
} |
q41135 | smallest_prime_factor | train | def smallest_prime_factor(Q):
"""Find the smallest number factorable by the small primes 2, 3, 4, and 7
that is larger than the argument Q"""
A = Q;
while(A != 1):
if(np.mod(A, 2) == 0):
A = A / 2
elif(np.mod(A, 3) == 0):
A = A / 3
elif(np.mod(... | python | {
"resource": ""
} |
q41136 | hkm_fc | train | def hkm_fc(fdata, Nmax, m, s):
""" Assume fdata has even rows"""
f = fdata[:, m]
L1 = f.size
MM = int(L1 / 2)
Q = s.size
ff = np.zeros(Q, dtype=np.complex128)
for n in xrange(MM, L1):
ff[n] = f[n - MM]
for n in xrange(0, MM):
ff[n] = f[n + MM]
# For... | python | {
"resource": ""
} |
q41137 | mindx | train | def mindx(m, nmax, mmax):
"""index to the first n value for a give m within the spherical
coefficients vector. Used by sc_to_fc"""
ind = 0
NN = nmax + 1
if np.abs(m) > mmax:
raise Exception("|m| cannot be larger than mmax")
if (m != 0):
ind = NN
ii = 1
... | python | {
"resource": ""
} |
q41138 | sc_to_fc | train | def sc_to_fc(spvec, nmax, mmax, nrows, ncols):
"""assume Ncols is even"""
fdata = np.zeros([int(nrows), ncols], dtype=np.complex128)
for k in xrange(0, int(ncols / 2)):
if k < mmax:
kk = k
ind = mindx(kk, nmax, mmax)
vec = spvec[ind:ind + nmax - np.abs(... | python | {
"resource": ""
} |
q41139 | set_status | train | def set_status(
db,
aid: int,
complete: Any,
watched_episodes: int,
) -> None:
"""Set anime status."""
upsert(db, 'cache_anime', ['aid'], {
'aid': aid,
'complete': 1 if complete else 0,
'watched_episodes': watched_episodes,
}) | python | {
"resource": ""
} |
q41140 | Manager.create_component | train | def create_component(self, module_name):
'''Create a component out of a loaded module.
Turns a previously-loaded shared module into a component in the
manager. This will invalidate any objects that are children of this
node.
The @ref module_name argument can contain options tha... | python | {
"resource": ""
} |
q41141 | Manager.delete_component | train | def delete_component(self, instance_name):
'''Delete a component.
Deletes the component specified by @ref instance_name from the manager.
This will invalidate any objects that are children of this node.
@param instance_name The instance name of the component to delete.
@raises ... | python | {
"resource": ""
} |
q41142 | Manager.load_module | train | def load_module(self, path, init_func):
'''Load a shared library.
Call this function to load a shared library (DLL file under Windows,
shared object under UNIX) into the manager.
@param path The path to the shared library.
@param init_func The name entry function in the library... | python | {
"resource": ""
} |
q41143 | Manager.unload_module | train | def unload_module(self, path):
'''Unload a loaded shared library.
Call this function to remove a shared library (e.g. a component) that
was previously loaded.
@param path The path to the shared library.
@raises FailedToUnloadModuleError
'''
with self._mutex:
... | python | {
"resource": ""
} |
q41144 | Manager.components | train | def components(self):
'''The list of components in this manager, if any.
This information can also be found by listing the children of this node
that are of type @ref Component. That method is more useful as it returns
the tree entries for the components.
'''
with self.... | python | {
"resource": ""
} |
q41145 | Manager.factory_profiles | train | def factory_profiles(self):
'''The factory profiles of all loaded modules.'''
with self._mutex:
if not self._factory_profiles:
self._factory_profiles = []
for fp in self._obj.get_factory_profiles():
self._factory_profiles.append(utils.nvlis... | python | {
"resource": ""
} |
q41146 | Manager.set_config_parameter | train | def set_config_parameter(self, param, value):
'''Set a configuration parameter of the manager.
@param The parameter to set.
@value The new value for the parameter.
@raises FailedToSetConfigurationError
'''
with self._mutex:
if self._obj.set_configuration(par... | python | {
"resource": ""
} |
q41147 | Manager.configuration | train | def configuration(self):
'''The configuration dictionary of the manager.'''
with self._mutex:
if not self._configuration:
self._configuration = utils.nvlist_to_dict(self._obj.get_configuration())
return self._configuration | python | {
"resource": ""
} |
q41148 | Manager.profile | train | def profile(self):
'''The manager's profile.'''
with self._mutex:
if not self._profile:
profile = self._obj.get_profile()
self._profile = utils.nvlist_to_dict(profile.properties)
return self._profile | python | {
"resource": ""
} |
q41149 | Manager.loadable_modules | train | def loadable_modules(self):
'''The list of loadable module profile dictionaries.'''
with self._mutex:
if not self._loadable_modules:
self._loadable_modules = []
for mp in self._obj.get_loadable_modules():
self._loadable_modules.append(utils... | python | {
"resource": ""
} |
q41150 | Manager.loaded_modules | train | def loaded_modules(self):
'''The list of loaded module profile dictionaries.'''
with self._mutex:
if not self._loaded_modules:
self._loaded_modules = []
for mp in self._obj.get_loaded_modules():
self._loaded_modules.append(utils.nvlist_to_d... | python | {
"resource": ""
} |
q41151 | Manager.slaves | train | def slaves(self):
'''The list of slave managers of this manager, if any.
This information can also be found by listing the children of this node
that are of type @ref Manager.
'''
with self._mutex:
if not self._slaves:
self._slaves = [c for c in self... | python | {
"resource": ""
} |
q41152 | OAuth2Authentication.authenticate_credentials | train | def authenticate_credentials(self, request, access_token):
"""
Authenticate the request, given the access token.
"""
try:
token = oauth2_provider.oauth2.models.AccessToken.objects.select_related('user')
# provider_now switches to timezone aware datetime when
... | python | {
"resource": ""
} |
q41153 | Cloud.request | train | def request(self, *args, **kwargs):
"""
The main purpose of this is to be a wrapper-like function to pass the api_token and all the other params to the
requests that are being made
:returns: An instance of RequestsHandler
"""
return RequestsHandler(*args, api_token=self.... | python | {
"resource": ""
} |
q41154 | Cloud.delete | train | def delete(self):
"""
Delete the cloud from the list of added clouds in mist.io service.
:returns: A list of mist.clients' updated clouds.
"""
req = self.request(self.mist_client.uri + '/clouds/' + self.id)
req.delete()
self.mist_client.update_clouds() | python | {
"resource": ""
} |
q41155 | Cloud.enable | train | def enable(self):
"""
Enable the Cloud.
:returns: A list of mist.clients' updated clouds.
"""
payload = {
"new_state": "1"
}
data = json.dumps(payload)
req = self.request(self.mist_client.uri+'/clouds/'+self.id, data=data)
req.post()
... | python | {
"resource": ""
} |
q41156 | Cloud.disable | train | def disable(self):
"""
Disable the Cloud.
:returns: A list of mist.clients' updated clouds.
"""
payload = {
"new_state": "0"
}
data = json.dumps(payload)
req = self.request(self.mist_client.uri+'/clouds/'+self.id, data=data)
req.post(... | python | {
"resource": ""
} |
q41157 | Cloud.sizes | train | def sizes(self):
"""
Available machine sizes to be used when creating a new machine.
:returns: A list of available machine sizes.
"""
req = self.request(self.mist_client.uri+'/clouds/'+self.id+'/sizes')
sizes = req.get().json()
return sizes | python | {
"resource": ""
} |
q41158 | Cloud.locations | train | def locations(self):
"""
Available locations to be used when creating a new machine.
:returns: A list of available locations.
"""
req = self.request(self.mist_client.uri+'/clouds/'+self.id+'/locations')
locations = req.get().json()
return locations | python | {
"resource": ""
} |
q41159 | Cloud.networks | train | def networks(self):
"""
Available networks.
:returns: A list of available networks associated to a provider.
"""
if self.provider in ['openstack', 'nephoscale']:
req = self.request(self.mist_client.uri+'/clouds/'+self.id+'/networks')
networks = req.get().... | python | {
"resource": ""
} |
q41160 | Cloud.images | train | def images(self):
"""
Available images to be used when creating a new machine.
:returns: A list of all available images.
"""
req = self.request(self.mist_client.uri+'/clouds/'+self.id+'/images')
images = req.get().json()
return images | python | {
"resource": ""
} |
q41161 | Cloud._list_machines | train | def _list_machines(self):
"""
Request a list of all added machines.
Populates self._machines dict with mist.client.model.Machine instances
"""
try:
req = self.request(self.mist_client.uri+'/clouds/'+self.id+'/machines')
machines = req.get().json()
... | python | {
"resource": ""
} |
q41162 | Cloud.machines | train | def machines(self, id=None, name=None, search=None):
"""
Property-like function to call the _list_machines function in order to populate self._machines dict
:returns: A list of Machine instances.
"""
if self._machines is None:
self._machines = {}
self._li... | python | {
"resource": ""
} |
q41163 | Machine._toggle_monitoring | train | def _toggle_monitoring(self, action, no_ssh=False):
"""
Enable or disable monitoring on a machine
:param action: Can be either "enable" or "disable"
"""
payload = {
'action': action,
'name': self.name,
'no_ssh': no_ssh,
'public_ips... | python | {
"resource": ""
} |
q41164 | Machine.get_stats | train | def get_stats(self, start=int(time()), stop=int(time())+10, step=10):
"""
Get stats of a monitored machine
:param start: Time formatted as integer, from when to fetch stats (default now)
:param stop: Time formatted as integer, until when to fetch stats (default +10 seconds)
:par... | python | {
"resource": ""
} |
q41165 | Machine.available_metrics | train | def available_metrics(self):
"""
List all available metrics that you can add to this machine
:returns: A list of dicts, each of which is a metric that you can add to a monitored machine
"""
req = self.request(self.mist_client.uri+"/clouds/"+self.cloud.id+"/machines/"+self.id+"/m... | python | {
"resource": ""
} |
q41166 | Machine.add_metric | train | def add_metric(self, metric_id):
"""
Add a metric to a monitored machine
:param metric_id: Metric_id (provided by self.available_metrics)
"""
payload = {
'metric_id': metric_id
}
data = json.dumps(payload)
req = self.request(self.mist_client.u... | python | {
"resource": ""
} |
q41167 | Machine.remove_metric | train | def remove_metric(self, metric_id):
"""
Remove a metric from a monitored machine
:param metric_id: Metric_id (provided by self.get_stats() )
"""
payload = {
'metric_id': metric_id
}
data = json.dumps(payload)
req = self.request(self.mist_cli... | python | {
"resource": ""
} |
q41168 | Machine.add_python_plugin | train | def add_python_plugin(self, name, python_file, value_type="gauge", unit=None):
"""
Add a custom python plugin to the collectd instance of a monitored plugin
:param python_file: Path of the python file to be added as custom python plugin
:param name: Name of the plugin
:param val... | python | {
"resource": ""
} |
q41169 | Key.private | train | def private(self):
"""
Return the private ssh-key
:returns: The private ssh-key as string
"""
req = self.request(self.mist_client.uri+'/keys/'+self.id+"/private")
private = req.get().json()
return private | python | {
"resource": ""
} |
q41170 | Key.public | train | def public(self):
"""
Return the public ssh-key
:returns: The public ssh-key as string
"""
req = self.request(self.mist_client.uri+'/keys/'+self.id+"/public")
public = req.get().json()
return public | python | {
"resource": ""
} |
q41171 | Key.rename | train | def rename(self, new_name):
"""
Rename a key
:param new_name: New name for the key (will also serve as the key's id)
:returns: An updated list of added keys
"""
payload = {
'new_name': new_name
}
data = json.dumps(payload)
req = self.r... | python | {
"resource": ""
} |
q41172 | Key.set_default | train | def set_default(self):
"""
Set this key as the default key
:returns: An updated list of added keys
"""
req = self.request(self.mist_client.uri+'/keys/'+self.id)
req.post()
self.is_default = True
self.mist_client.update_keys() | python | {
"resource": ""
} |
q41173 | Key.delete | train | def delete(self):
"""
Delete this key from mist.io
:returns: An updated list of added keys
"""
req = self.request(self.mist_client.uri+'/keys/'+self.id)
req.delete()
self.mist_client.update_keys() | python | {
"resource": ""
} |
q41174 | Bug.status | train | def status(self, value):
"""
Property for getting or setting the bug status
>>> bug.status = "REOPENED"
"""
if self._bug.get('id', None):
if value in VALID_STATUS:
self._bug['status'] = value
else:
raise BugExceptio... | python | {
"resource": ""
} |
q41175 | Bug.update | train | def update(self):
"""
Update this object with the latest changes from Bugzilla
>>> bug.status
'NEW'
#Changes happen on Bugzilla
>>> bug.update()
>>> bug.status
'FIXED'
"""
if 'id' in self._bug:
resul... | python | {
"resource": ""
} |
q41176 | Bug.get_comments | train | def get_comments(self):
"""
Obtain comments for this bug.
Returns a list of Comment instances.
"""
bug = str(self._bug['id'])
res = self._bugsy.request('bug/%s/comment' % bug)
return [Comment(bugsy=self._bugsy, **comments) for comments
in... | python | {
"resource": ""
} |
q41177 | Comment.add_tags | train | def add_tags(self, tags):
"""
Add tags to the comments
"""
if not isinstance(tags, list):
tags = [tags]
self._bugsy.request('bug/comment/%s/tags' % self._comment['id'],
method='PUT', json={"add": tags}) | python | {
"resource": ""
} |
q41178 | _readuntil | train | def _readuntil(f, end=_TYPE_END):
"""Helper function to read bytes until a certain end byte is hit"""
buf = bytearray()
byte = f.read(1)
while byte != end:
if byte == b'':
raise ValueError('File ended unexpectedly. Expected end byte {}.'.format(end))
buf += byte
byte = f.read(1)
return buf | python | {
"resource": ""
} |
q41179 | _encode_buffer | train | def _encode_buffer(string, f):
"""Writes the bencoded form of the input string or bytes"""
if isinstance(string, str):
string = string.encode()
f.write(str(len(string)).encode())
f.write(_TYPE_SEP)
f.write(string) | python | {
"resource": ""
} |
q41180 | bencode | train | def bencode(data, f=None):
"""
Writes a serializable data piece to f
The order of tests is nonarbitrary,
as strings and mappings are iterable.
If f is None, it writes to a byte buffer
and returns a bytestring
"""
if f is None:
f = BytesIO()
_bencode_to_file(data, f)
return f.getvalue()
else:
_bencode... | python | {
"resource": ""
} |
q41181 | command | train | def command(state, args):
"""Watch an anime."""
if len(args) < 2:
print(f'Usage: {args[0]} {{ID|aid:AID}} [EPISODE]')
return
aid = state.results.parse_aid(args[1], default_key='db')
anime = query.select.lookup(state.db, aid)
if len(args) < 3:
episode = anime.watched_episodes ... | python | {
"resource": ""
} |
q41182 | sin_fc | train | def sin_fc(fdata):
"""Apply sine in the Fourier domain."""
nrows = fdata.shape[0]
ncols = fdata.shape[1]
M = nrows / 2
fdata[int(M - 1), :] = 0
fdata[int(M + 1), :] = 0
work1 = np.zeros([nrows, ncols], dtype=np.complex128)
work2 = np.zeros([nrows, ncols], dtype=np.complex128)
... | python | {
"resource": ""
} |
q41183 | divsin_fc | train | def divsin_fc(fdata):
"""Apply divide by sine in the Fourier domain."""
nrows = fdata.shape[0]
ncols = fdata.shape[1]
L = int(nrows / 2) # Assuming nrows is even, which it should be.
L2 = L - 2 # This is the last index in the recursion for division by sine.
g = np.zeros([nrows, ncol... | python | {
"resource": ""
} |
q41184 | dphi_fc | train | def dphi_fc(fdata):
"""Apply phi derivative in the Fourier domain."""
nrows = fdata.shape[0]
ncols = fdata.shape[1]
B = int(ncols / 2) # As always, we assume nrows and ncols are even
a = list(range(0, int(B)))
ap = list(range(-int(B), 0))
a.extend(ap)
dphi = np.zeros... | python | {
"resource": ""
} |
q41185 | sinLdot_fc | train | def sinLdot_fc(tfdata, pfdata):
"""Apply sin of theta times the L operator to the data in the Fourier
domain."""
dphi_fc(tfdata)
sin_fc(pfdata)
dtheta_fc(pfdata)
return 1j * (tfdata - pfdata) | python | {
"resource": ""
} |
q41186 | L_fc | train | def L_fc(fdata):
"""Apply L in the Fourier domain."""
fd = np.copy(fdata)
dphi_fc(fdata)
divsin_fc(fdata)
dtheta_fc(fd)
return (1j * fdata, -1j * fd) | python | {
"resource": ""
} |
q41187 | extract | train | def extract(dump_files, extractors=ALL_EXTRACTORS):
"""
Extracts cites from a set of `dump_files`.
:Parameters:
dump_files : str | `file`
A set of files MediaWiki XML dump files
(expects: pages-meta-history)
extractors : `list`(`extractor`)
A list of extr... | python | {
"resource": ""
} |
q41188 | extract_ids | train | def extract_ids(text, extractors):
"""
Uses `extractors` to extract citation identifiers from a text.
:Parameters:
text : str
The text to process
extractors : `list`(`extractor`)
A list of extractors to apply to the text
:Returns:
`iterable` -- a generat... | python | {
"resource": ""
} |
q41189 | Component.add_members | train | def add_members(self, rtcs):
'''Add other RT Components to this composite component as members.
This component must be a composite component.
'''
if not self.is_composite:
raise exceptions.NotCompositeError(self.name)
for rtc in rtcs:
if self.is_member(r... | python | {
"resource": ""
} |
q41190 | Component.remove_members | train | def remove_members(self, rtcs):
'''Remove other RT Components from this composite component.
rtcs is a list of components to remove. Each element must be either an
rtctree.Component object or a string containing a component's instance
name. rtctree.Component objects are more reliable.
... | python | {
"resource": ""
} |
q41191 | Component.is_member | train | def is_member(self, rtc):
'''Is the given component a member of this composition?
rtc may be a Component object or a string containing a component's
instance name. Component objects are more reliable.
Returns False if the given component is not a member of this
composition.
... | python | {
"resource": ""
} |
q41192 | Component.members | train | def members(self):
'''Member components if this component is composite.'''
with self._mutex:
if not self._members:
self._members = {}
for o in self.organisations:
# TODO: Search for these in the tree
self._members[o.org_... | python | {
"resource": ""
} |
q41193 | Component.organisations | train | def organisations(self):
'''The organisations of this composition.'''
class Org:
def __init__(self, sdo_id, org_id, members, obj):
self.sdo_id = sdo_id
self.org_id = org_id
self.members = members
self.obj = obj
with sel... | python | {
"resource": ""
} |
q41194 | Component.parent_org_sdo_ids | train | def parent_org_sdo_ids(self):
'''The SDO IDs of the compositions this RTC belongs to.'''
return [sdo.get_owner()._narrow(SDOPackage.SDO).get_sdo_id() \
for sdo in self._obj.get_organizations() if sdo] | python | {
"resource": ""
} |
q41195 | Component.parent_organisations | train | def parent_organisations(self):
'''The organisations this RTC belongs to.'''
class ParentOrg:
def __init__(self, sdo_id, org_id):
self.sdo_id = sdo_id
self.org_id = org_id
with self._mutex:
if not self._parent_orgs:
for sdo... | python | {
"resource": ""
} |
q41196 | Component.activate_in_ec | train | def activate_in_ec(self, ec_index):
'''Activate this component in an execution context.
@param ec_index The index of the execution context to activate in.
This index is into the total array of contexts, that
is both owned and participating contexts. If th... | python | {
"resource": ""
} |
q41197 | Component.deactivate_in_ec | train | def deactivate_in_ec(self, ec_index):
'''Deactivate this component in an execution context.
@param ec_index The index of the execution context to deactivate in.
This index is into the total array of contexts, that
is both owned and participating contexts.... | python | {
"resource": ""
} |
q41198 | Component.get_ec | train | def get_ec(self, ec_handle):
'''Get a reference to the execution context with the given handle.
@param ec_handle The handle of the execution context to look for.
@type ec_handle str
@return A reference to the ExecutionContext object corresponding to
the ec_handle.
@raise... | python | {
"resource": ""
} |
q41199 | Component.get_ec_index | train | def get_ec_index(self, ec_handle):
'''Get the index of the execution context with the given handle.
@param ec_handle The handle of the execution context to look for.
@type ec_handle str
@return The index into the owned + participated arrays, suitable for
use in methods such as @... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.