code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def create_sqs_policy(self, topic_name, topic_arn, topic_subs):
t = self.template
arn_endpoints = []
url_endpoints = []
for sub in topic_subs:
arn_endpoints.append(sub["Endpoint"])
split_endpoint = sub["Endpoint"].split(":")
queue_url = "https://%s.%s.... | This method creates the SQS policy needed for an SNS subscription. It
also takes the ARN of the SQS queue and converts it to the URL needed
for the subscription, as that takes a URL rather than the ARN. |
def get_object(self, request):
pattern = request.GET.get('pattern', '')
if len(pattern) < 3:
raise ObjectDoesNotExist
return pattern | The GET parameter 'pattern' is the object. |
def body(self):
self.connection = pika.BlockingConnection(self.connection_param)
self.channel = self.connection.channel()
print "Monitoring file '%s'." % self.ftp_extended_log
file_iter = process_log(
sh.tail("-f", self.ftp_extended_log, _iter=True)
)
for impo... | This method handles AMQP connection details and reacts to FTP events by
sending messages to output queue. |
def get_function_name(s):
s = s.strip()
if s.startswith("__attribute__"):
if "))" not in s:
raise ValueError("__attribute__ is present, but I cannot find double-right parenthesis in the function "
"declaration string.")
s = s[s.index("))") + 2 : ].strip()... | Get the function name from a C-style function declaration string.
:param str s: A C-style function declaration string.
:return: The function name.
:rtype: str |
def get_settings(config_uri, section=None, defaults=None):
loader = get_loader(config_uri)
return loader.get_settings(section, defaults) | Load the settings from a named section.
.. code-block:: python
settings = plaster.get_settings(...)
print(settings['foo'])
:param config_uri: Anything that can be parsed by
:func:`plaster.parse_uri`.
:param section: The name of the section in the config file. If this is
`... |
def _ensure_ifaces_tuple(ifaces):
try:
ifaces = tuple(ifaces)
except TypeError:
ifaces = (ifaces,)
for iface in ifaces:
if not _issubclass(iface, ibc.Iface):
raise TypeError('Can only compare against interfaces.')
return ifaces | Convert to a tuple of interfaces and raise if not interfaces. |
def return_dict(self):
output_dict = {}
output_dict['general'] = self._iterate_through_class(self.general.__dict__)
output_dict['figure'] = self._iterate_through_class(self.figure.__dict__)
if self.total_plots > 1:
trans_dict = ({
str(i): self._iter... | Output dictionary for ``make_plot.py`` input.
Iterates through the entire MainContainer class turning its contents
into dictionary form. This dictionary becomes the input for ``make_plot.py``.
If `print_input` attribute is True, the entire dictionary will be printed
prior to returning ... |
def write(self):
string = ''.join(self.content)
lines = string.splitlines(True)
if len(lines) == 0:
return
texts = [self.first_prefix + lines[0]]
for line in lines[1:]:
if line.strip() == '':
texts.append('\n')
else:
... | Add ``self.contents`` with current ``prefix`` and ``first_prefix``
Add processed ``self.contents`` to ``self.base``. The first line has
``first_prefix`` prepended, further lines have ``prefix`` prepended.
Empty (all whitespace) lines get written as bare carriage returns, to
avoid ugly... |
def emptyTag(self, namespace, name, attrs, hasChildren=False):
yield {"type": "EmptyTag", "name": name,
"namespace": namespace,
"data": attrs}
if hasChildren:
yield self.error("Void element has children") | Generates an EmptyTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:arg attrs: the attributes of the element as a dict
:arg hasChildren: whether or not to yield a SerializationError because
this tag shouldn't have ch... |
def save_profile(self, **params):
image = self.get_image()
if (image is None):
return
profile = image.get('profile', None)
if profile is None:
profile = Settings.SettingGroup()
image.set(profile=profile)
self.logger.debug("saving to image profi... | Save the given parameters into profile settings.
Parameters
----------
params : dict
Keywords and values to be saved. |
def create_standalone_context(require=None, **settings) -> 'Context':
backend = os.environ.get('MODERNGL_BACKEND')
if backend is not None:
settings['backend'] = backend
ctx = Context.__new__(Context)
ctx.mglo, ctx.version_code = mgl.create_standalone_context(settings)
ctx._screen = None
... | Create a standalone ModernGL context.
Example::
# Create a context with highest possible supported version
ctx = moderngl.create_context()
# Require at least OpenGL 4.3
ctx = moderngl.create_context(require=430)
Keyword Arguments:
require (... |
def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label != 'oldimporter' and obj2._meta.app_label != 'oldimporter':
return True
return None | Relations between objects are allowed between nodeshot2 objects only |
def delete(self):
if 'delete' in self._URL:
extra = {'resource': self.__class__.__name__, 'query': {
'id': self.id}}
logger.info("Deleting {} resource.".format(self), extra=extra)
self._api.delete(url=self._URL['delete'].format(id=self.id))
else:
... | Deletes the resource on the server. |
def to_str(self):
dflt = super(DataportenAccount, self).to_str()
return '%s (%s)' % (
self.account.extra_data.get('name', ''),
dflt,
) | Returns string representation of a social account. Includes the name
of the user. |
def update(backend=None):
fileserver = salt.fileserver.Fileserver(__opts__)
fileserver.update(back=backend)
return True | Update the fileserver cache. If no backend is provided, then the cache for
all configured backends will be updated.
backend
Narrow fileserver backends to a subset of the enabled ones.
.. versionchanged:: 2015.5.0
If all passed backends start with a minus sign (``-``), then these
... |
def GE(classical_reg1, classical_reg2, classical_reg3):
classical_reg1, classical_reg2, classical_reg3 = prepare_ternary_operands(classical_reg1,
classical_reg2,
... | Produce an GE instruction.
:param classical_reg1: Memory address to which to store the comparison result.
:param classical_reg2: Left comparison operand.
:param classical_reg3: Right comparison operand.
:return: A ClassicalGreaterEqual instance. |
def get(path_or_file, default=SENTINAL, mime=None, name=None, backend=None,
encoding=None, encoding_errors=None, kwargs=None,
_wtitle=False):
try:
text, title = _get(
path_or_file, default=default, mime=mime, name=name,
backend=backend, kwargs=kwargs, encoding=encodin... | Get document full text.
Accepts a path or file-like object.
* If given, `default` is returned instead of an error.
* `backend` is either a module object or a string specifying which
default backend to use (e.g. "doc"); take a look at backends
directory to see a list of default backends.
... |
def profile_url(obj, profile_app_name, profile_model_name):
try:
content_type = ContentType.objects.get(
app_label=profile_app_name,
model=profile_model_name.lower()
)
profile = content_type.get_object_for_this_type(user=obj.user)
return profile.get_absolute_u... | returns profile url of user |
def update_bindings(self):
with self._lock:
all_valid = True
for handler in self.get_handlers(handlers_const.KIND_DEPENDENCY):
self.__safe_handler_callback(handler, "try_binding")
all_valid &= self.__safe_handler_callback(
handler, "is_... | Updates the bindings of the given component
:return: True if the component can be validated |
def split_classes(X, y):
lstsclass = np.unique(y)
return [X[y == i, :].astype(np.float32) for i in lstsclass] | split samples in X by classes in y |
def trace(function, *args, **k) :
if doTrace : print ("> "+function.__name__, args, k)
result = function(*args, **k)
if doTrace : print ("< "+function.__name__, args, k, "->", result)
return result | Decorates a function by tracing the begining and
end of the function execution, if doTrace global is True |
def import_authors(self, tree):
self.write_out(self.style.STEP('- Importing authors\n'))
post_authors = set()
for item in tree.findall('channel/item'):
post_type = item.find('{%s}post_type' % WP_NS).text
if post_type == 'post':
post_authors.add(item.find(
... | Retrieve all the authors used in posts
and convert it to new or existing author and
return the conversion. |
def is_BF_hypergraph(self):
for hyperedge_id in self._hyperedge_attributes:
tail = self.get_hyperedge_tail(hyperedge_id)
head = self.get_hyperedge_head(hyperedge_id)
if len(tail) > 1 and len(head) > 1:
return False
return True | Indicates whether the hypergraph is a BF-hypergraph.
A BF-hypergraph consists of only B-hyperedges and F-hyperedges.
See "is_B_hypergraph" or "is_F_hypergraph" for more details.
:returns: bool -- True iff the hypergraph is an F-hypergraph. |
def _run_post_configure_callbacks(self, configure_args):
resulting_configuration = ImmutableDict(self.config)
multiple_callbacks = copy.copy(
self._post_configure_callbacks['multiple']
)
single_callbacks = copy.copy(self._post_configure_callbacks['single'])
self._post... | Run all post configure callbacks we have stored.
Functions are passed the configuration that resulted from the call to
:meth:`configure` as the first argument, in an immutable form; and are
given the arguments passed to :meth:`configure` for the second
argument.
Returns from ca... |
def returns_annualized(returns, geometric=True, scale=None, expanding=False):
scale = _resolve_periods_in_year(scale, returns)
if expanding:
if geometric:
n = pd.expanding_count(returns)
return ((1. + returns).cumprod() ** (scale / n)) - 1.
else:
return pd.exp... | return the annualized cumulative returns
Parameters
----------
returns : DataFrame or Series
geometric : link the returns geometrically
scale: None or scalar or string (ie 12 for months in year),
If None, attempt to resolve from returns
If scalar, then use this as the annualiz... |
def update_hash(a_hash, mv):
if mv.labels:
signing.add_dict_to_hash(a_hash, encoding.MessageToPyValue(mv.labels))
money_value = mv.get_assigned_value(u'moneyValue')
if money_value is not None:
a_hash.update(b'\x00')
a_hash.update(money_value.currencyCode.encode('utf-8')) | Adds ``mv`` to ``a_hash``
Args:
a_hash (`Hash`): the secure hash, e.g created by hashlib.md5
mv (:class:`MetricValue`): the instance to add to the hash |
def access(self, path, mode, dir_fd=None, follow_symlinks=None):
if follow_symlinks is not None and sys.version_info < (3, 3):
raise TypeError("access() got an unexpected "
"keyword argument 'follow_symlinks'")
path = self._path_with_dir_fd(path, self.access, dir_... | Check if a file exists and has the specified permissions.
Args:
path: (str) Path to the file.
mode: (int) Permissions represented as a bitwise-OR combination of
os.F_OK, os.R_OK, os.W_OK, and os.X_OK.
dir_fd: If not `None`, the file descriptor of a directory,... |
def get_response(self):
request = getattr(requests, self.request_method, None)
if request is None and self._request_method is None:
raise ValueError("A effective http request method must be set")
if self.request_url is None:
raise ValueError(
"Fatal ... | Get the original response of requests |
def find_whole_word(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search | Scan through string looking for a location where this word produces a match,
and return a corresponding MatchObject instance.
Return None if no position in the string matches the pattern;
note that this is different from finding a zero-length match at some point in the string. |
def _update_plotting_params(self, **kwargs):
scalars = kwargs.get('scalars', None)
if scalars is not None:
old = self.display_params['scalars']
self.display_params['scalars'] = scalars
if old != scalars:
self.plotter.subplot(*self.loc)
... | Some plotting parameters can be changed through the tool; this
updataes those plotting parameters. |
def get_extra_context(site, ctx):
'Returns extra data useful to the templates.'
ctx['site'] = site
ctx['feeds'] = feeds = site.active_feeds.order_by('name')
def get_mod_chk(k):
mod, chk = (
(max(vals) if vals else None) for vals in (
filter(None, it.imap(op.attrgetter(k), feeds))
for k in ['last_modifi... | Returns extra data useful to the templates. |
def format(self, obj, **kwargs):
sio = StringIO()
self.fprint(obj, stream=sio, **kwargs)
return sio.getvalue() | Return the formatted representation of the object as a string. |
def link(self, title, path):
if not isinstance(path, file):
path = salt.utils.files.fopen(path)
self.__current_section.append({title: path}) | Add a static file on the file system.
:param title:
:param path:
:return: |
def pWMWrite(fileHandle, pWM, alphabetSize=4):
for i in xrange(0, alphabetSize):
fileHandle.write("%s\n" % ' '.join([ str(pWM[j][i]) for j in xrange(0, len(pWM)) ])) | Writes file in standard PWM format, is reverse of pWMParser |
def dict_to_numpy_array(d):
return fromarrays(d.values(), np.dtype([(str(k), v.dtype) for k, v in d.items()])) | Convert a dict of 1d array to a numpy recarray |
def get_user(self, user_name=None):
params = {}
if user_name:
params['UserName'] = user_name
return self.get_response('GetUser', params) | Retrieve information about the specified user.
If the user_name is not specified, the user_name is determined
implicitly based on the AWS Access Key ID used to sign the request.
:type user_name: string
:param user_name: The name of the user to delete.
If not s... |
def _uri_to_etext(cls, uri_ref):
try:
return validate_etextno(int(os.path.basename(uri_ref.toPython())))
except InvalidEtextIdException:
return None | Converts the representation used to identify a text in the
meta-data RDF graph to a human-friendly integer text identifier. |
def _cancelScheduledUpgrade(self, justification=None) -> None:
if self.scheduledAction:
why_prefix = ": "
why = justification
if justification is None:
why_prefix = ", "
why = "cancellation reason not specified"
ev_data = self.sched... | Cancels scheduled upgrade
:param when: time upgrade was scheduled to
:param version: version upgrade scheduled for |
def read_chunk(stream):
chunk = stream.read(1)
while chunk in SKIP:
chunk = stream.read(1)
if chunk == "\"":
chunk += stream.read(1)
while not chunk.endswith("\""):
if chunk[-1] == ESCAPE:
chunk += stream.read(2)
else:
chunk += ... | Ignore whitespace outside of strings. If we hit a string, read it in
its entirety. |
def choose(self, choose_from):
for choice in self.elements:
if choice in choose_from:
return ImplementationChoice(choice, choose_from[choice])
raise LookupError(self.elements, choose_from.keys()) | given a mapping of implementations
choose one based on the current settings
returns a key value pair |
def get_info(self):
reconstructed = self.is_reconstructed()
site, site_type = self.get_site()
return reconstructed, site, site_type | Return surface reconstruction as well as primary and
secondary adsorption site labels |
def vb_destroy_machine(name=None, timeout=10000):
vbox = vb_get_box()
log.info('Destroying machine %s', name)
machine = vbox.findMachine(name)
files = machine.unregister(2)
progress = machine.deleteConfig(files)
progress.waitForCompletion(timeout)
log.info('Finished destroying machine %s', n... | Attempts to get rid of a machine and all its files from the hypervisor
@param name:
@type name: str
@param timeout int timeout in milliseconds |
def _update_font_style(self, font_style):
toggle_state = font_style & wx.FONTSTYLE_ITALIC == wx.FONTSTYLE_ITALIC
self.ToggleTool(wx.FONTFLAG_ITALIC, toggle_state) | Updates font style widget
Parameters
----------
font_style: Integer
\tButton down iif font_style == wx.FONTSTYLE_ITALIC |
def _dump_to_pages(dump):
pos = 0
ret = []
start_tag = u"<page>\n"
end_tag = u"</page>\n"
while True:
start_pos = dump.find(start_tag, pos)
if start_pos == -1:
break
start_pos += len(start_tag)
end_pos = dump.find(end_tag, start_pos)
if end_pos == -1:
break
ret.append(dump[... | Extract pages from an xml dump.
Args:
dump: a unicode string
Returns:
a list of unicode strings |
def _load_from_cache_if_available(self, key):
if key in self._cache:
entity = self._cache[key]
if entity is None or entity._key == key:
raise tasklets.Return(entity) | Returns a cached Model instance given the entity key if available.
Args:
key: Key instance.
Returns:
A Model instance if the key exists in the cache. |
def _handle_command(self, command, env, args):
plugin_obj = registration.get_command_hook(command, env.task.active)
if plugin_obj and not env.task.active:
if plugin_obj.task_only or plugin_obj.options:
plugin_obj = None
if plugin_obj:
if plugin_obj.needs_r... | Handles calling appropriate command plugin based on the arguments
provided.
`command`
Command string.
`env`
Runtime ``Environment`` instance.
`args`
List of argument strings passed.
Returns ``False`` if nothing... |
def compile_pillar(self):
load = {'id': self.minion_id,
'grains': self.grains,
'saltenv': self.opts['saltenv'],
'pillarenv': self.opts['pillarenv'],
'pillar_override': self.pillar_override,
'extra_minion_data': self.extra_minion_dat... | Return a future which will contain the pillar data from the master |
def show_image(kwargs, call=None):
if call != 'function':
raise SaltCloudSystemExit(
'The show_image action must be called with -f or --function.'
)
name = kwargs['image']
log.info("Showing image %s", name)
machine = vb_get_machine(name)
ret = {
machine["name"]: t... | Show the details of an image |
def _get_bundles_by_type(self, type):
bundles = {}
bundle_definitions = self.config.get(type)
if bundle_definitions is None:
return bundles
for bundle_name, paths in bundle_definitions.items():
bundle_files = []
for path in paths:
patte... | Get a dictionary of bundles for requested type.
Args:
type: 'javascript' or 'css' |
def DOM_node_to_XML(tree, xml_declaration=True):
result = ET.tostring(tree, encoding='utf8', method='xml').decode('utf-8')
if not xml_declaration:
result = result.split("<?xml version='1.0' encoding='utf8'?>\n")[1]
return result | Prints a DOM tree to its Unicode representation.
:param tree: the input DOM tree
:type tree: an ``xml.etree.ElementTree.Element`` object
:param xml_declaration: if ``True`` (default) prints a leading XML
declaration line
:type xml_declaration: bool
:returns: Unicode object |
def get(self, key):
if key in self and len(self[key]) > 0:
return min(self[key])
else:
return 0 | Return timings for `key`. Returns 0 if not present. |
def apply_numpy_specials(self, copy=True):
if copy:
data = self.data.astype(numpy.float64)
elif self.data.dtype != numpy.float64:
data = self.data = self.data.astype(numpy.float64)
else:
data = self.data
data[data == self.specials['Null']] = numpy.nan
... | Convert isis special pixel values to numpy special pixel values.
======= =======
Isis Numpy
======= =======
Null nan
Lrs -inf
Lis -inf
His inf
Hrs inf
======= =======
Par... |
def with_log(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
decorator_logger = logging.getLogger('@with_log')
decorator_logger.debug('Entering %s() function call.', func.__name__)
log = kwargs.get('log', logging.getLogger(func.__name__))
try:
ret = func(l... | Automatically adds a named logger to a function upon function call.
:param func: Function to decorate.
:return: Decorated function.
:rtype: function |
def guess_xml_encoding(self, content):
r
matchobj = self.__regex['xml_encoding'].match(content)
return matchobj and matchobj.group(1).lower() | r"""Guess encoding from xml header declaration.
:param content: xml content
:rtype: str or None |
def parse_s2bins(s2bins):
s2b = {}
b2s = {}
for line in s2bins:
line = line.strip().split()
s, b = line[0], line[1]
if 'UNK' in b:
continue
if len(line) > 2:
g = ' '.join(line[2:])
else:
g = 'n/a'
b = '%s\t%s' % (b, g)
... | parse ggKbase scaffold-to-bin mapping
- scaffolds-to-bins and bins-to-scaffolds |
def __FinalUrlValue(self, value, field):
if isinstance(field, messages.BytesField) and value is not None:
return base64.urlsafe_b64encode(value)
elif isinstance(value, six.text_type):
return value.encode('utf8')
elif isinstance(value, six.binary_type):
return ... | Encode value for the URL, using field to skip encoding for bytes. |
def open(self):
filename = self.dialogs.getOpenFileName(filter="*.%s" % self.FTYPE)
if filename:
self.new(filename) | open a session to define in a dialog in an extra window |
def facilityNetToMs():
a = TpPd(pd=0x3)
b = MessageType(mesType=0x3a)
c = Facility()
packet = a / b / c
return packet | FACILITY Section 9.3.9.1 |
def growth_volatility(eqdata, **kwargs):
_window = kwargs.get('window', 20)
_selection = kwargs.get('selection', 'Adj Close')
_outputcol = kwargs.get('outputcol', 'Growth Risk')
_growthdata = simple.growth(eqdata, selection=_selection)
return volatility(_growthdata, outputcol=_outputcol, window=_win... | Return the volatility of growth.
Note that, like :func:`pynance.tech.simple.growth` but in contrast to
:func:`volatility`, :func:`growth_volatility`
applies directly to a dataframe like that returned by
:func:`pynance.data.retrieve.get`, not necessarily to a single-column dataframe.
Parameters
... |
def config_oauth(app):
" Configure oauth support. "
for name in PROVIDERS:
config = app.config.get('OAUTH_%s' % name.upper())
if not config:
continue
if not name in oauth.remote_apps:
remote_app = oauth.remote_app(name, **config)
else:
remote_a... | Configure oauth support. |
def flatten_path(path, flatten_slashes=False):
if not path or path == '/':
return '/'
if path[0] == '/':
path = path[1:]
parts = path.split('/')
new_parts = collections.deque()
for part in parts:
if part == '.' or (flatten_slashes and not part):
continue
e... | Flatten an absolute URL path by removing the dot segments.
:func:`urllib.parse.urljoin` has some support for removing dot segments,
but it is conservative and only removes them as needed.
Arguments:
path (str): The URL path.
flatten_slashes (bool): If True, consecutive slashes are removed.... |
def field_to_long(value):
if isinstance(value, (int, long)):
return long(value)
elif isinstance(value, basestring):
return bytes_to_long(from_hex(value))
else:
return None | Converts given value to long if possible, otherwise None is returned.
:param value:
:return: |
def verify_signature(self, addr):
return verify(virtualchain.address_reencode(addr), self.get_plaintext_to_sign(), self.sig) | Given an address, verify whether or not it was signed by it |
def fail(self, message, status=500, **kw):
self.request.response.setStatus(status)
result = {"success": False, "errors": message, "status": status}
result.update(kw)
return result | Set a JSON error object and a status to the response |
def look_up(self, **keys: Dict[InstanceName, ScalarValue]) -> "ArrayEntry":
if not isinstance(self.schema_node, ListNode):
raise InstanceValueError(self.json_pointer(), "lookup on non-list")
try:
for i in range(len(self.value)):
en = self.value[i]
... | Return the entry with matching keys.
Args:
keys: Keys and values specified as keyword arguments.
Raises:
InstanceValueError: If the receiver's value is not a YANG list.
NonexistentInstance: If no entry with matching keys exists. |
def setSignalHeaders(self, signalHeaders):
for edfsignal in np.arange(self.n_channels):
self.channels[edfsignal] = signalHeaders[edfsignal]
self.update_header() | Sets the parameter for all signals
Parameters
----------
signalHeaders : array_like
containing dict with
'label' : str
channel label (string, <= 16 characters, must be unique)
'dimension' : str
physi... |
def socket_close(self):
if self.sock != NC.INVALID_SOCKET:
self.sock.close()
self.sock = NC.INVALID_SOCKET | Close our socket. |
def _cosmoid_request(self, resource, cosmoid, **kwargs):
params = {
'cosmoid': cosmoid,
}
params.update(kwargs)
return self.make_request(resource, params) | Maps to the Generic API method for requests who's only parameter is ``cosmoid`` |
def iter_entries(self):
for idx in range(self._entry_count):
dir_entry_offset = self._offset + 2 + (idx*12)
ifd_entry = _IfdEntryFactory(self._stream_rdr, dir_entry_offset)
yield ifd_entry | Generate an |_IfdEntry| instance corresponding to each entry in the
directory. |
def _response_value(self, response, json=True):
if json:
contentType = response.headers.get("Content-Type", "")
if not contentType.startswith(("application/json",
"text/javascript")):
if response.status_code == 200:
... | Parses the HTTP response as a the cloudstack value.
It throws an exception if the server didn't answer with a 200. |
def level_names(self):
index = self.to_index()
if isinstance(index, pd.MultiIndex):
return index.names
else:
return None | Return MultiIndex level names or None if this IndexVariable has no
MultiIndex. |
def _get_enum(self, source, bitarray):
raw_value = self._get_raw(source, bitarray)
value_desc = source.find('item', {'value': str(raw_value)}) or self._get_rangeitem(source, raw_value)
return {
source['shortcut']: {
'description': source.get('description'),
... | Get enum value, based on the data in XML |
def get_statements(self):
for k, v in self.reader_output.items():
for interaction in v['interactions']:
self._process_interaction(k, interaction, v['text'], self.pmid,
self.extra_annotations) | Process reader output to produce INDRA Statements. |
def _known_populations(row, pops):
cutoff = 0.01
out = set([])
for pop, base in [("esp", "af_esp_all"), ("1000g", "af_1kg_all"),
("exac", "af_exac_all"), ("anypop", "max_aaf_all")]:
for key in [x for x in pops if x.startswith(base)]:
val = row[key]
if va... | Find variants present in substantial frequency in population databases. |
def new(cls, ns_path, script, campaign_dir, runner_type='Auto',
overwrite=False, optimized=True, check_repo=True):
ns_path = os.path.abspath(ns_path)
campaign_dir = os.path.abspath(campaign_dir)
if Path(campaign_dir).exists() and not overwrite:
manager = CampaignManager.l... | Create a new campaign from an ns-3 installation and a campaign
directory.
This method will create a DatabaseManager, which will install a
database in the specified campaign_dir. If a database is already
available at the ns_path described in the specified campaign_dir and
its con... |
def nodeToXML(nodeObject):
xmlRoot = etree.Element(NODE + "node", nsmap=NODE_NSMAP)
nameNode = etree.SubElement(xmlRoot, NODE + "name")
nameNode.text = nodeObject.node_name
urlNode = etree.SubElement(xmlRoot, NODE + "url")
urlNode.text = nodeObject.node_url
pathNode = etree.SubElement(xmlRoot, N... | Take a Django node object from our CODA store and make an XML
representation |
def visit(self, node):
for pattern, replace in know_pattern:
check = Check(node, dict())
if check.visit(pattern):
node = PlaceholderReplace(check.placeholders).visit(replace())
self.update = True
return super(PatternTransform, self).visit(node) | Try to replace if node match the given pattern or keep going. |
def write_badge(self, file_path, overwrite=False):
if file_path.endswith('/'):
raise Exception('File location may not be a directory.')
path = os.path.abspath(file_path)
if not path.lower().endswith('.svg'):
path += '.svg'
if not overwrite and os.path.exists(path)... | Write badge to file. |
def load(self, profile_args):
for key, value in profile_args.items():
self.add(key, value) | Load provided CLI Args.
Args:
args (dict): Dictionary of args in key/value format. |
def GetFeedItemIdsForCampaign(campaign_feed):
feed_item_ids = set()
try:
lhs_operand = campaign_feed['matchingFunction']['lhsOperand']
except KeyError:
lhs_operand = None
if (lhs_operand and lhs_operand[0]['FunctionArgumentOperand.Type'] ==
'RequestContextOperand'):
request_context_operand = l... | Gets the Feed Item Ids used by a campaign through a given Campaign Feed.
Args:
campaign_feed: the Campaign Feed we are retrieving Feed Item Ids from.
Returns:
A list of Feed Item IDs. |
def get_default_gwf_api():
for lib in APIS:
try:
import_gwf_library(lib)
except ImportError:
continue
else:
return lib
raise ImportError("no GWF API available, please install a third-party GWF "
"library ({}) and try again".format... | Return the preferred GWF library
Examples
--------
If you have |LDAStools.frameCPP|_ installed:
>>> from gwpy.timeseries.io.gwf import get_default_gwf_api
>>> get_default_gwf_api()
'framecpp'
Or, if you don't have |lalframe|_:
>>> get_default_gwf_api()
'lalframe'
Otherwise:
... |
def concat_padded(base, *args):
ret = base
for n in args:
if is_string(n):
ret = "%s_%s" % (ret, n)
else:
ret = "%s_%04i" % (ret, n + 1)
return ret | Concatenate string and zero-padded 4 digit number |
def _pool_event_refresh_cb(conn, pool, opaque):
_salt_send_event(opaque, conn, {
'pool': {
'name': pool.name(),
'uuid': pool.UUIDString()
},
'event': opaque['event']
}) | Storage pool refresh events handler |
def getanymentions(idf, anidfobject):
name = anidfobject.obj[1]
foundobjs = []
keys = idfobjectkeys(idf)
idfkeyobjects = [idf.idfobjects[key.upper()] for key in keys]
for idfobjects in idfkeyobjects:
for idfobject in idfobjects:
if name.upper() in [item.upper()
... | Find out if idjobject is mentioned an any object anywhere |
def remove_external_data_field(tensor, field_key):
for (i, field) in enumerate(tensor.external_data):
if field.key == field_key:
del tensor.external_data[i] | Remove a field from a Tensor's external_data key-value store.
Modifies tensor object in place.
@params
tensor: Tensor object from which value will be removed
field_key: The key of the field to be removed |
def encode_command(*args, buf=None):
if buf is None:
buf = bytearray()
buf.extend(b'*%d\r\n' % len(args))
try:
for arg in args:
barg = _converters[type(arg)](arg)
buf.extend(b'$%d\r\n%s\r\n' % (len(barg), barg))
except KeyError:
raise TypeError("Argument {... | Encodes arguments into redis bulk-strings array.
Raises TypeError if any of args not of bytearray, bytes, float, int, or str
type. |
def capabilities(self):
response = self.get(PATH_CAPABILITIES)
return _load_atom(response, MATCH_ENTRY_CONTENT).capabilities | Returns the list of system capabilities.
:return: A ``list`` of capabilities. |
async def start_authentication(self):
_, code = await self.http.post_data(
'pair-pin-start', headers=_AIRPLAY_HEADERS)
if code != 200:
raise DeviceAuthenticationError('pair start failed') | Start the authentication process.
This method will show the expected PIN on screen. |
async def get_person(self, id_):
data = await self._get_person_json(
id_,
OrderedDict(append_to_response='movie_credits')
)
return Person.from_json(data, self.config['data'].get('images')) | Retrieve person data by ID.
Arguments:
id_ (:py:class:`int`): The person's TMDb ID.
Returns:
:py:class:`~.Person`: The requested person. |
def __get_payload(self, uuid, failed):
try:
return self.publish_uuid_store[uuid]
except Exception as exc:
msg = "Failed to load payload from publish store for UUID %s, %s: %s"
if uuid in failed:
log.error(msg, uuid, "discarding", str(exc))
... | Retry reading a message from the publish_uuid_store once, delete on the second failure. |
def remove_port_profile_to_delete(self, profile_name, device_id):
with self.session.begin(subtransactions=True):
self.session.query(ucsm_model.PortProfileDelete).filter_by(
profile_id=profile_name, device_id=device_id).delete() | Removes port profile to be deleted from table. |
def work_experience(self, working_start_age: int = 22) -> int:
age = self._store['age']
if age == 0:
age = self.age()
return max(age - working_start_age, 0) | Get a work experience.
:param working_start_age: Age then person start to work.
:return: Depend on previous generated age. |
def start_pinging(self) -> None:
assert self.ping_interval is not None
if self.ping_interval > 0:
self.last_ping = self.last_pong = IOLoop.current().time()
self.ping_callback = PeriodicCallback(
self.periodic_ping, self.ping_interval * 1000
)
... | Start sending periodic pings to keep the connection alive |
def update_user_type(self):
if self.rb_tutor.isChecked():
self.user_type = 'tutor'
elif self.rb_student.isChecked():
self.user_type = 'student'
self.accept() | Return either 'tutor' or 'student' based on which radio
button is selected. |
def cli(ctx):
wandb.try_to_set_up_global_logging()
if ctx.invoked_subcommand is None:
click.echo(ctx.get_help()) | Weights & Biases.
Run "wandb docs" for full documentation. |
def write_supercells_with_displacements(supercell, cells_with_disps, filename="geo.gen"):
write_dftbp(filename + "S", supercell)
for ii in range(len(cells_with_disps)):
write_dftbp(filename + "S-{:03d}".format(ii+1), cells_with_disps[ii]) | Writes perfect supercell and supercells with displacements
Args:
supercell: perfect supercell
cells_with_disps: supercells with displaced atoms
filename: root-filename |
def addrs_for_hash(self, h):
if h not in self._hash_mapping:
return
self._mark_updated_mapping(self._hash_mapping, h)
to_discard = set()
for e in self._hash_mapping[h]:
try:
if h == hash(self[e].object): yield e
else: to_discard.add... | Returns addresses that contain expressions that contain a variable with the hash of `h`. |
def Attach(self, pid):
if self.inferior.is_running:
answer = raw_input('Already attached to process ' +
str(self.inferior.pid) +
'. Detach? [y]/n ')
if answer and answer != 'y' and answer != 'yes':
return None
self.Detach()
for plugin i... | Attach to the process with the given pid. |
def handle_logout_response(self, response, sign_alg=None, digest_alg=None):
logger.info("state: %s", self.state)
status = self.state[response.in_response_to]
logger.info("status: %s", status)
issuer = response.issuer()
logger.info("issuer: %s", issuer)
del self.state[resp... | handles a Logout response
:param response: A response.Response instance
:return: 4-tuple of (session_id of the last sent logout request,
response message, response headers and message) |
def get_publish_path(self, obj):
return os.path.join(
obj.chat_type.publish_path, obj.publish_path.lstrip("/")
) | publish_path joins the publish_paths for the chat type and the channel. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.