code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def action(act, config):
if not config:
pass
elif act is "list":
do_list()
else:
config_dir = os.path.join(CONFIG_ROOT, config)
globals()["do_" + act](config, config_dir) | CLI action preprocessor |
def iterativeFetch(query, batchSize=default_batch_size):
while True:
rows = query.fetchmany(batchSize)
if not rows:
break
rowDicts = sqliteRowsToDicts(rows)
for rowDict in rowDicts:
yield rowDict | Returns rows of a sql fetch query on demand |
def from_environ(cls, environ=os.environ):
base_path, unused = (environ['PATH_INFO'].rsplit('/', 1) + [''])[:2]
return cls(
environ['HTTP_X_APPENGINE_TASKNAME'],
environ['HTTP_X_APPENGINE_QUEUENAME'],
base_path) | Constructs a _PipelineContext from the task queue environment. |
def source_get(method_name):
def source_get(_value, context, **_params):
method = getattr(context["model"].source, method_name)
return _get(method, context["key"], (), {})
return source_get | Creates a getter that will drop the current value,
and call the source's method with specified name
using the context's key as first argument.
@param method_name: the name of a method belonging to the source.
@type method_name: str |
def load_configuration(yaml: yaml.ruamel.yaml.YAML, filename: str) -> DictLike:
with open(filename, "r") as f:
config = yaml.load(f)
return config | Load an analysis configuration from a file.
Args:
yaml: YAML object to use in loading the configuration.
filename: Filename of the YAML configuration file.
Returns:
dict-like object containing the loaded configuration |
def size(self):
if not self._size:
self._size = os.path.getsize(self._path)
return self._size | size in bytes |
def get_review_sh(self, revision, item):
identity = self.get_sh_identity(revision)
update = parser.parse(item[self.get_field_date()])
erevision = self.get_item_sh_fields(identity, update)
return erevision | Add sorting hat enrichment fields for the author of the revision |
def attach_db(self, db):
if db is not None:
if isinstance(db, basestring):
db = gffutils.FeatureDB(db)
if not isinstance(db, gffutils.FeatureDB):
raise ValueError(
"`db` must be a filename or a gffutils.FeatureDB")
self._kwargs[... | Attach a gffutils.FeatureDB for access to features.
Useful if you want to attach a db after this instance has already been
created.
Parameters
----------
db : gffutils.FeatureDB |
def quote_xml(text):
text = _coerce_unicode(text)
if text.startswith(CDATA_START):
return text
return saxutils.escape(text) | Format a value for display as an XML text node.
Returns:
Unicode string (str on Python 3, unicode on Python 2) |
def get_url(self, cmd, **args):
return self.http.base_url + self._mkurl(cmd, *args) | Expand the request URL for a request. |
def log_to(logger):
logger_id = id(logger)
def decorator(function):
func = add_label(function, 'log_to', logger_id=logger_id)
return func
return decorator | Wraps a function that has a connection passed such that everything that
happens on the connection is logged using the given logger.
:type logger: Logger
:param logger: The logger that handles the logging. |
def inserir(self, name):
logical_environment_map = dict()
logical_environment_map['name'] = name
code, xml = self.submit(
{'logical_environment': logical_environment_map}, 'POST', 'logicalenvironment/')
return self.response(code, xml) | Inserts a new Logical Environment and returns its identifier.
:param name: Logical Environment name. String with a minimum 2 and maximum of 80 characters
:return: Dictionary with the following structure:
::
{'logical_environment': {'id': < id_logical_environment >}}
:rai... |
def cap(self):
to_cap = (self._inputnodes, self._outputnodes, self._prov)
if to_cap == (None, None, None):
self._inputnodes = {
f: self._make_inputnode(f) for f in self.input_frequencies}
self._outputnodes = {
f: self._make_outputnode(f) for f in s... | "Caps" the construction of the pipeline, signifying that no more inputs
and outputs are expected to be added and therefore the input and output
nodes can be created along with the provenance. |
def local_bind_ports(self):
self._check_is_started()
return [_server.local_port for _server in self._server_list if
_server.local_port is not None] | Return a list containing the ports of local side of the TCP tunnels |
def get_t_factor(t1, t2):
t_factor = None
if t1 is not None and t2 is not None and t1 != t2:
dt = t2 - t1
year = timedelta(days=365.25)
t_factor = abs(dt.total_seconds() / year.total_seconds())
return t_factor | Time difference between two datetimes, expressed as decimal year |
def _get_next_buffered_row(self):
if self._iter_row == self._iter_nrows:
raise StopIteration
if self._row_buffer_index >= self._iter_row_buffer:
self._buffer_iter_rows(self._iter_row)
data = self._row_buffer[self._row_buffer_index]
self._iter_row += 1
self... | Get the next row for iteration. |
def disconnect(remote_app):
if remote_app not in current_oauthclient.disconnect_handlers:
return abort(404)
ret = current_oauthclient.disconnect_handlers[remote_app]()
db.session.commit()
return ret | Disconnect user from remote application.
Removes application as well as associated information. |
def get_drill_bits_d_metric():
return np.concatenate((np.arange(1.0, 10.0, 0.1),
np.arange(10.0, 18.0, 0.5),
np.arange(18.0, 36.0, 1.0),
np.arange(40.0, 55.0, 5.0))) * u.mm | Return array of possible drill diameters in metric. |
def apply_rows(applicators, rows):
for row in rows:
for (cols, function) in applicators:
for col in (cols or []):
value = row.get(col, '')
row[col] = function(row, value)
yield row | Yield rows after applying the applicator functions to them.
Applicators are simple unary functions that return a value, and that
value is stored in the yielded row. E.g.
`row[col] = applicator(row[col])`. These are useful to, e.g., cast
strings to numeric datatypes, to convert formats stored in a cell,... |
def _combine_core_aux_specs(self):
all_specs = []
for core_dict in self._permute_core_specs():
for aux_dict in self._permute_aux_specs():
all_specs.append(_merge_dicts(core_dict, aux_dict))
return all_specs | Combine permutations over core and auxilliary Calc specs. |
def execute(self):
self._collect_garbage()
upstream_channels = {}
for node in nx.topological_sort(self.logical_topo):
operator = self.operators[node]
downstream_channels = self._generate_channels(operator)
handles = self.__generate_actors(operator, upstream_ch... | Deploys and executes the physical dataflow. |
def _func_router(self, msg, fname, **config):
FNAME = 'handle_%s_autocloud_%s'
if ('compose_id' in msg['msg'] or 'compose_job_id' in msg['msg'] or
'autocloud.compose' in msg['topic']):
return getattr(self, FNAME % ('v2', fname))(msg, **config)
else:
return... | This method routes the messages based on the params and calls the
appropriate method to process the message. The utility of the method is
to cope up with the major message change during different releases. |
def get_job_amounts(agent, project_name, spider_name=None):
job_list = agent.get_job_list(project_name)
pending_job_list = job_list['pending']
running_job_list = job_list['running']
finished_job_list = job_list['finished']
job_amounts = {}
if spider_name is None:
job_amounts['pending'] =... | Get amounts that pending job amount, running job amount, finished job amount. |
def _process_table_cells(self, table):
rows = []
for i, tr in enumerate(table.find_all('tr')):
row = []
for c in tr.contents:
cell_type = getattr(c, 'name', None)
if cell_type not in ('td', 'th'):
continue
rowspa... | Compile all the table cells.
Returns a list of rows. The rows may have different lengths because of
column spans. |
def imshow_interact(self, canvas, plot_function, extent=None, label=None, vmin=None, vmax=None, **kwargs):
raise NotImplementedError("Implement all plot functions in AbstractPlottingLibrary in order to use your own plotting library") | This function is optional!
Create an imshow controller to stream
the image returned by the plot_function. There is an imshow controller written for
mmatplotlib, which updates the imshow on changes in axis.
The origin of the image show is (0,0), such that X[0,0] gets p... |
def _partial_extraction_fixed(self, idx, extra_idx=0):
myarray = np.array([])
with open(self.abspath) as fobj:
contents = fobj.readlines()[idx+extra_idx:]
for line in contents:
try:
vals = re.findall(r' *[\w\-\+\.]*', line)
... | Private method for a single extraction on a fixed-type tab file |
def add(self, item):
with self.lock:
if item in self.set:
return False
self.set.add(item)
return True | Add an item to the set, and return whether it was newly added |
def _render_border_line(self, t, settings):
s = self._es(settings, self.SETTING_WIDTH, self.SETTING_MARGIN, self.SETTING_MARGIN_LEFT, self.SETTING_MARGIN_RIGHT)
w = self.calculate_width_widget(**s)
s = self._es(settings, self.SETTING_BORDER_STYLE, self.SETTING_BORDER_FORMATING)
border_li... | Render box border line. |
def peek(self, offset=0):
pos = self.pos + offset
if pos >= self.end:
return None
return self.text[pos] | Looking forward in the input text without actually stepping the current position.
returns None if the current position is at the end of the input. |
def _CheckStorageFile(self, storage_file_path):
if os.path.exists(storage_file_path):
if not os.path.isfile(storage_file_path):
raise errors.BadConfigOption(
'Storage file: {0:s} already exists and is not a file.'.format(
storage_file_path))
logger.warning('Appending ... | Checks if the storage file path is valid.
Args:
storage_file_path (str): path of the storage file.
Raises:
BadConfigOption: if the storage file path is invalid. |
def createuser(self, email, name='', password=''):
self._proxy.User.create(email, name, password)
return self.getuser(email) | Return a bugzilla User for the given username
:arg email: The email address to use in bugzilla
:kwarg name: Real name to associate with the account
:kwarg password: Password to set for the bugzilla account
:raises XMLRPC Fault: Code 501 if the username already exists
Code 50... |
def arrays2wcxf(C):
d = {}
for k, v in C.items():
if np.shape(v) == () or np.shape(v) == (1,):
d[k] = v
else:
ind = np.indices(v.shape).reshape(v.ndim, v.size).T
for i in ind:
name = k + '_' + ''.join([str(int(j) + 1) for j in i])
... | Convert a dictionary with Wilson coefficient names as keys and
numbers or numpy arrays as values to a dictionary with a Wilson coefficient
name followed by underscore and numeric indices as keys and numbers as
values. This is needed for the output in WCxf format. |
def extend(self, **kwargs):
props = self.copy()
props.update(kwargs)
return TemplateData(**props) | Returns a new instance with this instance's data overlayed by the key-value args. |
def wait_for_contract(self, contract_address_hex, timeout=None):
contract_address = decode_hex(contract_address_hex)
start_time = time.time()
result = self._raiden.chain.client.web3.eth.getCode(
to_checksum_address(contract_address),
)
current_time = time.time()
... | Wait until a contract is mined
Args:
contract_address_hex (string): hex encoded address of the contract
timeout (int): time to wait for the contract to get mined
Returns:
True if the contract got mined, false otherwise |
def _locate_file(f, base_dir):
if base_dir == None:
return f
file_name = os.path.join(base_dir, f)
real = os.path.realpath(file_name)
return real | Utility method for finding full path to a filename as string |
def force_encoding(self, encoding):
if not encoding:
self.disabled = False
else:
self.write_with_encoding(encoding, None)
self.disabled = True | Sets a fixed encoding. The change is emitted right away.
From now one, this buffer will switch the code page anymore.
However, it will still keep track of the current code page. |
def setup_dictionary(self, task):
dictionary_options = task.get('dictionary', {})
output = os.path.abspath(dictionary_options.get('output', self.dict_bin))
lang = dictionary_options.get('lang', 'en_US')
wordlists = dictionary_options.get('wordlists', [])
if lang and wordlists:
... | Setup dictionary. |
def T_i(v_vars: List[fl.Var], mass: np.ndarray, i: int):
assert len(v_vars) == 3 * len(mass)
m = mass[i]
T = (0.5 * m) * flux_v2(v_vars, i)
return T | Make Fluxion with the kinetic energy of body i |
def _dataset_line(args):
if args['command'] == 'list':
filter_ = args['filter'] if args['filter'] else '*'
context = google.datalab.Context.default()
if args['project']:
context = google.datalab.Context(args['project'], context.credentials)
return _render_list([str(dataset) for dataset in bigque... | Implements the BigQuery dataset magic subcommand used to operate on datasets
The supported syntax is:
%bq datasets <command> <args>
Commands:
{list, create, delete}
Args:
args: the optional arguments following '%bq datasets command'. |
def get_in_net_id(cls, tenant_id):
if 'in' not in cls.ip_db_obj:
LOG.error("Fabric not prepared for tenant %s", tenant_id)
return None
db_obj = cls.ip_db_obj.get('in')
in_subnet_dict = cls.get_in_ip_addr(tenant_id)
sub = db_obj.get_subnet(in_subnet_dict.get('subne... | Retrieve the network ID of IN network. |
def save_object(filename, obj):
logging.info('saving {}...'.format(filename))
try:
with gzip.GzipFile(filename, 'wb') as f:
f.write(pickle.dumps(obj, 1))
except Exception as e:
logging.error('save failure: {}'.format(e))
raise | Compresses and pickles given object to the given filename. |
def _on_change(self):
font = self.__generate_font_tuple()
self._example_label.configure(font=font) | Callback if any of the values are changed. |
def log(self, sequence, infoarray) -> None:
aggregated = ((infoarray is not None) and
(infoarray.info['type'] != 'unmodified'))
descr = sequence.descr_sequence
if aggregated:
descr = '_'.join([descr, infoarray.info['type']])
if descr in self.variables:
... | Pass the given |IoSequence| to a suitable instance of
a |NetCDFVariableBase| subclass.
When writing data, the second argument should be an |InfoArray|.
When reading data, this argument is ignored. Simply pass |None|.
(1) We prepare some devices handling some sequences by applying
... |
def get_included_resources(request, serializer=None):
include_resources_param = request.query_params.get('include') if request else None
if include_resources_param:
return include_resources_param.split(',')
else:
return get_default_included_resources_from_serializer(serializer) | Build a list of included resources. |
def latinize_text(text, ascii=False):
if text is None or not isinstance(text, six.string_types) or not len(text):
return text
if ascii:
if not hasattr(latinize_text, '_ascii'):
latinize_text._ascii = Transliterator.createInstance('Any-Latin; NFKD; [:Symbol:] Remove; [:Nonspacing Mark... | Transliterate the given text to the latin script.
This attempts to convert a given text to latin script using the
closest match of characters vis a vis the original script. |
def fetch_state_data(self, states):
print("Fetching census data")
for table in CensusTable.objects.all():
api = self.get_series(table.series)
for variable in table.variables.all():
estimate = "{}_{}".format(table.code, variable.code)
print(
... | Fetch census estimates from table. |
def cc(project, detect_project=False):
from benchbuild.utils import cmd
cc_name = str(CFG["compiler"]["c"])
wrap_cc(cc_name, compiler(cc_name), project, detect_project=detect_project)
return cmd["./{}".format(cc_name)] | Return a clang that hides CFLAGS and LDFLAGS.
This will generate a wrapper script in the current directory
and return a complete plumbum command to it.
Args:
cflags: The CFLAGS we want to hide.
ldflags: The LDFLAGS we want to hide.
func (optional): A function that will be pickled a... |
def to_bytes(self):
return struct.pack(Ethernet._PACKFMT, self._dst.packed,
self._src.packed, self._ethertype.value) | Return packed byte representation of the Ethernet header. |
def fill_predictive_missing_parameters(self):
if hasattr(self, 'host_name') and not hasattr(self, 'address'):
self.address = self.host_name
if hasattr(self, 'host_name') and not hasattr(self, 'alias'):
self.alias = self.host_name
if self.initial_state == 'd':
... | Fill address with host_name if not already set
and define state with initial_state
:return: None |
def get_storage_info(self, human=False):
res = self._req_get_storage_info()
if human:
res['total'] = humanize.naturalsize(res['total'], binary=True)
res['used'] = humanize.naturalsize(res['used'], binary=True)
return res | Get storage info
:param bool human: whether return human-readable size
:return: total and used storage
:rtype: dict |
def raise_for_error(self):
if self.ok:
return self
tip = "running {0} @<{1}> error, return code {2}".format(
" ".join(self.cmd), self.cwd, self.return_code
)
logger.error("{0}\nstdout:{1}\nstderr:{2}\n".format(
tip, self._stdout.decode("utf8"), self._s... | raise `ShCmdError` if the proc's return_code is not 0
otherwise return self
..Usage::
>>> proc = shcmd.run("ls").raise_for_error()
>>> proc.return_code == 0
True |
def add_view(self, *args, **kwargs):
new_view = View(*args, **kwargs)
for view in self.views:
if view.uid == new_view.uid:
raise ValueError("View with this uid already exists")
self.views += [new_view]
return new_view | Add a new view
Parameters
----------
uid: string
The uid of new view
width: int
The width of this of view on a 12 unit grid
height: int
The height of the this view. The height is proportional
to the height of all the views present.... |
def _get_class_handlers(cls, signal_name, instance):
handlers = cls._signal_handlers_sorted[signal_name]
return [getattr(instance, hname) for hname in handlers] | Returns the handlers registered at class level. |
def run_manage_command(self, command, venv_path, verbose=True):
self.logger.debug('Running manage command `%s` for `%s` ...' % (command, venv_path))
self._run_shell_command(
'. %s/bin/activate && python %s %s' % (venv_path, self._get_manage_py_path(), command),
pipe_it=(not verbo... | Runs a given Django manage command in a given virtual environment.
:param str command:
:param str venv_path:
:param bool verbose: |
def get_current_clementine():
try:
return get_info_mpris2('clementine')
except DBusErrorResponse:
bus_name = 'org.mpris.clementine'
path = '/Player'
interface = 'org.freedesktop.MediaPlayer'
return dbus_get_metadata(path, bus_name, interface) | Get the current song from clementine. |
def unpack_message(buffer):
hdr_size = Header().get_size()
hdr_buff, msg_buff = buffer[:hdr_size], buffer[hdr_size:]
header = Header()
header.unpack(hdr_buff)
message = new_message_from_header(header)
message.unpack(msg_buff)
return message | Unpack the whole buffer, including header pack.
Args:
buffer (bytes): Bytes representation of a openflow message.
Returns:
object: Instance of openflow message. |
def is_authenticated(user):
if not hasattr(user, 'is_authenticated'):
return False
if callable(user.is_authenticated):
return user.is_authenticated()
else:
return user.is_authenticated | Return whether or not a User is authenticated.
Function provides compatibility following deprecation of method call to
`is_authenticated()` in Django 2.0.
This is *only* required to support Django < v1.10 (i.e. v1.9 and earlier),
as `is_authenticated` was introduced as a property in v1.10.s |
async def inspect(self, *, node_id: str) -> Mapping[str, Any]:
response = await self.docker._query_json(
"nodes/{node_id}".format(node_id=node_id), method="GET"
)
return response | Inspect a node
Args:
node_id: The ID or name of the node |
def validate_receiver(self, key, value):
if value not in current_webhooks.receivers:
raise ReceiverDoesNotExist(self.receiver_id)
return value | Validate receiver identifier. |
def _ConvertInteger(value):
if isinstance(value, float) and not value.is_integer():
raise ParseError('Couldn\'t parse integer: {0}.'.format(value))
if isinstance(value, six.text_type) and value.find(' ') != -1:
raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))
return int(value) | Convert an integer.
Args:
value: A scalar value to convert.
Returns:
The integer value.
Raises:
ParseError: If an integer couldn't be consumed. |
def raw(self, from_, to, body):
if isinstance(to, string_types):
raise TypeError('"to" parameter must be enumerable')
return self._session.post('{}/raw'.format(self._url), json={
'from': from_,
'to': to,
'body': body,
}).json() | Send a raw MIME message. |
def LL(n):
if (n<=0):return Context('0')
else:
LL1=LL(n-1)
r1 = C1(3**(n-1),2**(n-1)) - LL1 - LL1
r2 = LL1 - LL1 - LL1
return r1 + r2 | constructs the LL context |
def decision_function(self, X):
predictions = self.predict_proba(X)
out = np.zeros((predictions.shape[0], 1))
out[:, 0] = 1 - predictions[:, -1]
return out | Generate an inlier score for each test data example.
Parameters
----------
X : array
Test data, of dimension N times d (rows are examples, columns
are data dimensions)
Returns:
-------
scores : array
A vector of length N, where each e... |
def oidc_to_user_data(payload):
payload = payload.copy()
field_map = {
'given_name': 'first_name',
'family_name': 'last_name',
'email': 'email',
}
ret = {}
for token_attr, user_attr in field_map.items():
if token_attr not in payload:
continue
ret[u... | Map OIDC claims to Django user fields. |
def split_flanks(self, _, result):
if not result.strip():
self.left, self.right = "", ""
return result
match = self.flank_re.match(result)
assert match, "This regexp should always match"
self.left, self.right = match.group(1), match.group(3)
return match.g... | Return `result` without flanking whitespace. |
def choose(items, title_text, question_text):
print(title_text)
for i, item in enumerate(items, start=1):
print('%d) %s' % (i, item))
print('%d) Abort' % (i + 1))
selected = input(question_text)
try:
index = int(selected)
except ValueError:
index = -1
if not (index - ... | Interactively choose one of the items. |
def dumpfile(item, path):
with io.open(path, 'wb') as fd:
fd.write(en(item)) | Dump an object to a file by path.
Args:
item (object): The object to serialize.
path (str): The file path to save.
Returns:
None |
def gauge(self, *args, **kwargs):
orig_gauge = super(Nagios, self).gauge
if 'timestamp' in kwargs and 'timestamp' not in getargspec(orig_gauge).args:
del kwargs['timestamp']
orig_gauge(*args, **kwargs) | Compatability wrapper for Agents that do not submit gauge metrics with custom timestamps |
def match_rank (self, ps):
assert isinstance(ps, property_set.PropertySet)
all_requirements = self.requirements ()
property_requirements = []
feature_requirements = []
for r in all_requirements:
if get_value (r):
property_requirements.append (r)
... | Returns true if the generator can be run with the specified
properties. |
def get_num_primal_variables(self):
if self.x is not None:
return self.x.size
if self.gphi is not None:
return self.gphi.size
if self.Hphi is not None:
return self.Hphi.shape[0]
if self.A is not None:
return self.A.shape[1]
if self.... | Gets number of primal variables.
Returns
-------
num : int |
def pop_changeset(self, changeset_id: uuid.UUID) -> Dict[bytes, Union[bytes, DeletedEntry]]:
if changeset_id not in self.journal_data:
raise KeyError(changeset_id, "Unknown changeset in JournalDB")
all_ids = tuple(self.journal_data.keys())
changeset_idx = all_ids.index(changeset_id)
... | Returns all changes from the given changeset. This includes all of
the changes from any subsequent changeset, giving precidence to
later changesets. |
def nsmallest(self, n, columns, keep='first'):
return algorithms.SelectNFrame(self,
n=n,
keep=keep,
columns=columns).nsmallest() | Return the first `n` rows ordered by `columns` in ascending order.
Return the first `n` rows with the smallest values in `columns`, in
ascending order. The columns that are not specified are returned as
well, but not used for ordering.
This method is equivalent to
``df.sort_val... |
def _fusion_range_to_dsl(tokens) -> FusionRangeBase:
if FUSION_MISSING in tokens:
return missing_fusion_range()
return fusion_range(
reference=tokens[FUSION_REFERENCE],
start=tokens[FUSION_START],
stop=tokens[FUSION_STOP]
) | Convert a PyParsing data dictionary into a PyBEL.
:type tokens: ParseResult |
def element_data_from_sym(sym):
sym_lower = sym.lower()
if sym_lower not in _element_sym_map:
raise KeyError('No element data for symbol \'{}\''.format(sym))
return _element_sym_map[sym_lower] | Obtain elemental data given an elemental symbol
The given symbol is not case sensitive
An exception is thrown if the symbol is not found |
def can_map_ipa_string(self, ipa_string):
canonical = [(c.canonical_representation, ) for c in ipa_string]
split = split_using_dictionary(canonical, self, self.max_key_length, single_char_parsing=False)
for sub in split:
if not sub in self.ipa_canonical_representation_to_mapped_str:
... | Return ``True`` if the mapper can map all the IPA characters
in the given IPA string.
:param IPAString ipa_string: the IPAString to be parsed
:rtype: bool |
def gen_bisz(src, dst):
return ReilBuilder.build(ReilMnemonic.BISZ, src, ReilEmptyOperand(), dst) | Return a BISZ instruction. |
def create_env(self, interpreter, is_current, options):
if is_current:
pyvenv_options = options['pyvenv_options']
if "--system-site-packages" in pyvenv_options:
self.system_site_packages = True
logger.debug("Creating virtualenv with pyvenv. options=%s", pyvenv... | Create the virtualenv and return its info. |
def storepage(self, page):
try:
return self._api_entrypoint.storePage(self._session_token, page)
except XMLRPCError as e:
log.error('Failed to store page %s: %s' % (page.get('title', '[unknown title]'), e))
return None | Stores a page object, updating the page if it already exists.
returns the stored page, or None if the page could not be stored. |
def parse_response(self, response, header=None):
response = response.decode(self.encoding)
if header:
header = "".join((self.resp_prefix, header, self.resp_header_sep))
if not response.startswith(header):
raise IEC60488.ParsingError('Response header mismatch')
... | Parses the response message.
The following graph shows the structure of response messages.
::
+----------+
+--+ data sep +<-+
| +---------... |
def verify_fun(lazy_obj, fun):
if not fun:
raise salt.exceptions.SaltInvocationError(
'Must specify a function to run!\n'
'ex: manage.up'
)
if fun not in lazy_obj:
raise salt.exceptions.CommandExecutionError(lazy_obj.missing_fun_string(fun)) | Check that the function passed really exists |
def _getMethodNamePrefix(self, node):
targetName = node.name
for sibling in node.parent.nodes_of_class(type(node)):
if sibling is node:
continue
prefix = self._getCommonStart(targetName, sibling.name)
if not prefix.rstrip('_'):
continue... | Return the prefix of this method based on sibling methods.
@param node: the current node |
def getTmpFilename(self, tmp_dir=None, prefix='tmp', suffix='.txt',
include_class_id=False, result_constructor=FilePath):
if not tmp_dir:
tmp_dir = self.TmpDir
elif not tmp_dir.endswith("/"):
tmp_dir += "/"
if include_class_id:
class_id ... | Return a temp filename
tmp_dir: directory where temporary files will be stored
prefix: text to append to start of file name
suffix: text to append to end of file name
include_class_id: if True, will append a class identifier (built
from the class name) to th... |
def _find_address_range(addresses):
first = last = addresses[0]
last_index = 0
for ip in addresses[1:]:
if ip._ip == last._ip + 1:
last = ip
last_index += 1
else:
break
return (first, last, last_index) | Find a sequence of addresses.
Args:
addresses: a list of IPv4 or IPv6 addresses.
Returns:
A tuple containing the first and last IP addresses in the sequence,
and the index of the last IP address in the sequence. |
def annotation(args):
from jcvi.formats.base import DictFile
p = OptionParser(annotation.__doc__)
p.add_option("--queryids", help="Query IDS file to switch [default: %default]")
p.add_option("--subjectids", help="Subject IDS file to switch [default: %default]")
opts, args = p.parse_args(args)
if... | %prog annotation blastfile > annotations
Create simple two column files from the first two coluns in blastfile. Use
--queryids and --subjectids to switch IDs or descriptions. |
def maximum_address(self):
maximum_address = self._segments.maximum_address
if maximum_address is not None:
maximum_address //= self.word_size_bytes
return maximum_address | The maximum address of the data, or ``None`` if the file is empty. |
def set_setting(key, value, qsettings=None):
full_key = '%s/%s' % (APPLICATION_NAME, key)
set_general_setting(full_key, value, qsettings) | Set value to QSettings based on key in InaSAFE scope.
:param key: Unique key for setting.
:type key: basestring
:param value: Value to be saved.
:type value: QVariant
:param qsettings: A custom QSettings to use. If it's not defined, it will
use the default one.
:type qsettings: qgis.P... |
def count_dimensions(entry):
result = 0
for e in entry:
if isinstance(e, str):
sliced = e.strip(",").split(",")
result += 0 if len(sliced) == 1 and sliced[0] == "" else len(sliced)
return result | Counts the number of dimensions from a nested list of dimension assignments
that may include function calls. |
def sponsor_tagged_image(sponsor, tag):
if sponsor.files.filter(tag_name=tag).exists():
return sponsor.files.filter(tag_name=tag).first().tagged_file.item.url
return '' | returns the corresponding url from the tagged image list. |
def add_callback(self, name, callback, echo_old=False, priority=0):
if self.is_callback_property(name):
prop = getattr(type(self), name)
prop.add_callback(self, callback, echo_old=echo_old, priority=priority)
else:
raise TypeError("attribute '{0}' is not a callback pr... | Add a callback that gets triggered when a callback property of the
class changes.
Parameters
----------
name : str
The instance to add the callback to.
callback : func
The callback function to add
echo_old : bool, optional
If `True`, t... |
def get_tags(self, rev=None):
rev = rev or 'HEAD'
return set(self._invoke('tag', '--points-at', rev).splitlines()) | Return the tags for the current revision as a set |
def _get_script_args(cls, type_, name, header, script_text):
if type_ == 'gui':
launcher_type = 'gui'
ext = '-script.pyw'
old = ['.pyw']
else:
launcher_type = 'cli'
ext = '-script.py'
old = ['.py', '.pyc', '.pyo']
hdr = cls.... | For Windows, add a .py extension and an .exe launcher |
def get_payment_request(self, cart, request):
try:
self.charge(cart, request)
thank_you_url = OrderModel.objects.get_latest_url()
js_expression = 'window.location.href="{}";'.format(thank_you_url)
return js_expression
except (KeyError, stripe.error.StripeE... | From the given request, add a snippet to the page. |
def hydra_parser(in_file, options=None):
if options is None: options = {}
BedPe = namedtuple('BedPe', ["chrom1", "start1", "end1",
"chrom2", "start2", "end2",
"name", "strand1", "strand2",
"support"])
with ope... | Parse hydra input file into namedtuple of values. |
def objname(self, obj=None):
obj = obj or self.obj
_objname = self.pretty_objname(obj, color=None)
_objname = "'{}'".format(colorize(_objname, "blue"))
return _objname | Formats object names in a pretty fashion |
def _energy_evaluation(self, operator):
if self._quantum_state is not None:
input_circuit = self._quantum_state
else:
input_circuit = [self.opt_circuit]
if operator._paulis:
mean_energy, std_energy = operator.evaluate_with_result(self._operator_mode, input_cir... | Evaluate the energy of the current input circuit with respect to the given operator.
:param operator: Hamiltonian of the system
:return: Energy of the Hamiltonian |
def get_expr_summ_id(self, experiment_id, time_slide_id, veto_def_name, datatype, sim_proc_id = None):
for row in self:
if (row.experiment_id, row.time_slide_id, row.veto_def_name, row.datatype, row.sim_proc_id) == (experiment_id, time_slide_id, veto_def_name, datatype, sim_proc_id):
return row.experiment_summ... | Return the expr_summ_id for the row in the table whose experiment_id,
time_slide_id, veto_def_name, and datatype match the given. If sim_proc_id,
will retrieve the injection run matching that sim_proc_id.
If a matching row is not found, returns None. |
def figs(self):
ret = utils.DefaultOrderedDict(lambda: self[1:0])
for arr in self:
if arr.psy.plotter is not None:
ret[arr.psy.plotter.ax.get_figure()].append(arr)
return OrderedDict(ret) | A mapping from figures to data objects with the plotter in this
figure |
def create_response(version, status, headers):
message = []
message.append('HTTP/{} {}\r\n'.format(version, status))
for name, value in headers:
message.append(name)
message.append(': ')
message.append(value)
message.append('\r\n')
message.append('\r\n')
return s2b(''... | Create a HTTP response header. |
def create_channels(chan_name=None, n_chan=None):
if chan_name is not None:
n_chan = len(chan_name)
elif n_chan is not None:
chan_name = _make_chan_name(n_chan)
else:
raise TypeError('You need to specify either the channel names (chan_name) or the number of channels (n_chan)')
xy... | Create instance of Channels with random xyz coordinates
Parameters
----------
chan_name : list of str
names of the channels
n_chan : int
if chan_name is not specified, this defines the number of channels
Returns
-------
instance of Channels
where the location of the... |
def _array2cstr(arr):
out = StringIO()
np.save(out, arr)
return b64encode(out.getvalue()) | Serializes a numpy array to a compressed base64 string |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.