code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def interactive(outdir):
print("Building your Blended files into a website!")
global outdir_type
outdir_type = outdir
reload(sys)
sys.setdefaultencoding('utf8')
build_files(outdir)
print("Watching the content and templates directories for changes, press CTRL+C to stop...\n")
w = Watcher(... | Blends the generated files and outputs a HTML website on file change |
def _compile_and_collapse(self):
self._real_regex = self._real_re_compile(*self._regex_args,
**self._regex_kwargs)
for attr in self._regex_attributes_to_copy:
setattr(self, attr, getattr(self._real_regex, attr)) | Actually compile the requested regex |
def silent_execute(self, code):
try:
self.kernel_client.execute(to_text_string(code), silent=True)
except AttributeError:
pass | Execute code in the kernel without increasing the prompt |
def stop(self):
distributed_logger.info('Stopping metrics aggregator')
self.process.terminate()
self.process.join()
distributed_logger.info('Stopped metrics aggregator') | Terminates the forked process.
Only valid if started as a fork, because... well you wouldn't get here otherwise.
:return: |
def impute_knn(df, k=3):
imputed_matrix = KNN(k=k).complete(df.values)
imputed_df = pd.DataFrame(imputed_matrix, df.index, df.columns)
return imputed_df | Nearest neighbour imputations which weights samples using the mean squared difference on features for which two rows both have observed data.
:param df: The input dataframe that contains missing values
:param k: The number of neighbours
:return: the imputed dataframe |
def vectorize(fn):
@functools.wraps(fn)
def vectorized_function(values, *vargs, **kwargs):
return [fn(value, *vargs, **kwargs) for value in values]
return vectorized_function | Allows a method to accept a list argument, but internally deal only
with a single item of that list. |
def list_nodes(**kwargs):
ret = {}
nodes = list_nodes_full()
for node in nodes:
ret[node] = {}
for prop in 'id', 'image', 'size', 'state', 'private_ips', 'public_ips':
ret[node][prop] = nodes[node][prop]
return ret | Return basic data on nodes |
def registration_function_for_optionable(self, optionable_class):
self._assert_not_frozen()
def register(*args, **kwargs):
kwargs['registering_class'] = optionable_class
self.register(optionable_class.options_scope, *args, **kwargs)
register.bootstrap = self.bootstrap_option_values()
registe... | Returns a function for registering options on the given scope. |
def clear_cache_delete_selected(modeladmin, request, queryset):
result = delete_selected(modeladmin, request, queryset)
if not result and hasattr(modeladmin, 'invalidate_cache'):
modeladmin.invalidate_cache(queryset=queryset)
return result | A delete action that will invalidate cache after being called. |
def _validate_all_tags_are_used(metadata):
tag_names = set([tag_name for tag_name, _ in metadata.tags])
filter_arg_names = set()
for location, _ in metadata.registered_locations:
for filter_info in metadata.get_filter_infos(location):
for filter_arg in filter_info.args:
i... | Ensure all tags are used in some filter. |
def sample(self, data, interval):
data_slice = dict()
for key in data:
if '_valid' in key:
continue
index = [slice(None)] * data[key].ndim
index[0] = self.rng.randint(0, data[key].shape[0])
index[0] = slice(index[0], index[0] + 1)
... | Sample a patch from the data object
Parameters
----------
data : dict
A data dict as produced by pumpp.Pump.transform
interval : slice
The time interval to sample
Returns
-------
data_slice : dict
`data` restricted to `interv... |
def ilsr_pairwise_dense(
comp_mat, alpha=0.0, initial_params=None, max_iter=100, tol=1e-8):
fun = functools.partial(
lsr_pairwise_dense, comp_mat=comp_mat, alpha=alpha)
return _ilsr(fun, initial_params, max_iter, tol) | Compute the ML estimate of model parameters given dense data.
This function computes the maximum-likelihood (ML) estimate of model
parameters given dense pairwise-comparison data.
The data is described by a pairwise-comparison matrix ``comp_mat`` such
that ``comp_mat[i,j]`` contains the number of time... |
def sam_readline(sock, partial = None):
response = b''
exception = None
while True:
try:
c = sock.recv(1)
if not c:
raise EOFError('SAM connection died. Partial response %r %r' % (partial, response))
elif c == b'\n':
break
... | read a line from a sam control socket |
def _get_token_from_headers(self, request, refresh_token):
header = request.headers.get(self.config.authorization_header(), None)
if header is None:
return None
else:
header_prefix_key = "authorization_header_prefix"
header_prefix = getattr(self.config, header... | Extract the token if present inside the headers of a request. |
def content_types(self):
return EnvironmentContentTypesProxy(self._client, self.space.id, self.id) | Provides access to content type management methods for content types of an environment.
API reference: https://www.contentful.com/developers/docs/references/content-management-api/#/reference/content-types
:return: :class:`EnvironmentContentTypesProxy <contentful_management.space_content_types_proxy.E... |
def tag(self, text):
matches = self._match(text.text)
matches = self._resolve_conflicts(matches)
if self.return_layer:
return matches
else:
text[self.layer_name] = matches | Retrieves list of regex_matches in text.
Parameters
----------
text: Text
The estnltk text object to search for events.
Returns
-------
list of matches |
def register_error(self, code=1, errmsg=None):
if errmsg is not None:
if self.errmsg is None:
self.errmsg = errmsg
elif errmsg not in self.errmsg:
self.errmsg += ", " + errmsg
if code is not None:
self.exit_code = max(self.exit_code, co... | Update the exit code. |
def update_default_iou_values(self):
try:
output = yield from gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, stderr=True)
match = re.search("-n <n>\s+Size of nvram in Kb \(default ([0-9]+)KB\)", output)
if match:
self.... | Finds the default RAM and NVRAM values for the IOU image. |
def reflect_well(value, bounds):
while value not in bounds:
value = bounds._max.reflect_left(value)
value = bounds._min.reflect_right(value)
return value | Given some boundaries, reflects the value until it falls within both
boundaries. This is done iteratively, reflecting left off of the
`boundaries.max`, then right off of the `boundaries.min`, etc.
Parameters
----------
value : float
The value to apply the reflected boundaries to.
bounds... |
def get_queryset(self):
queryset = super(IndexView, self).get_queryset()
search_form = self.get_search_form()
if search_form.is_valid():
query_str = search_form.cleaned_data.get('q', '').strip()
queryset = self.model.objects.search(query_str)
return querys... | Returns queryset instance.
:rtype: django.db.models.query.QuerySet. |
def get_tag_context(name, state):
new_contexts = 0
ctm = None
while True:
try:
ctx_key, name = name.split('.', 1)
ctm = state.context.get(ctx_key)
except ValueError:
break
if not ctm:
break
else:
state.context.push(c... | Given a tag name, return its associated value as defined in the current
context stack. |
def sendACK(self, blocknumber=None):
log.debug("In sendACK, passed blocknumber is %s", blocknumber)
if blocknumber is None:
blocknumber = self.context.next_block
log.info("Sending ack to block %d" % blocknumber)
ackpkt = TftpPacketACK()
ackpkt.blocknumber = blocknumbe... | This method sends an ack packet to the block number specified. If
none is specified, it defaults to the next_block property in the
parent context. |
def apply(self, im):
from scipy.ndimage.interpolation import shift
im = rollaxis(im, self.axis)
im.setflags(write=True)
for ind in range(0, im.shape[0]):
im[ind] = shift(im[ind], map(lambda x: -x, self.delta[ind]), mode='nearest')
im = rollaxis(im, 0, self.axis+1)
... | Apply axis-localized displacements.
Parameters
----------
im : ndarray
The image or volume to shift |
def render_css(self, fn=None, text=None, margin='', indent='\t'):
fn = fn or os.path.splitext(self.fn)[0]+'.css'
if not os.path.exists(os.path.dirname(fn)):
os.makedirs(os.path.dirname(fn))
curdir = os.path.abspath(os.curdir)
os.chdir(os.path.dirname(fn))
text = text ... | output css using the Sass processor |
def load_spectrum(filename):
import f311
f = load_with_classes(filename, f311.classes_sp())
if f:
return f.spectrum
return None | Attempts to load spectrum as one of the supported types.
Returns:
a Spectrum, or None |
def extract_bus_routine(page):
if not isinstance(page, pq):
page = pq(page)
stations = extract_stations(page)
return {
'name': extract_routine_name(page),
'stations': stations,
'current': extract_current_routine(page, stations)
} | Extract bus routine information from page.
:param page: crawled page. |
def load(name, **kwargs):
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.load'](name, **kwargs)
return ret | Loads the configuration provided onto the junos device.
.. code-block:: yaml
Install the mentioned config:
junos:
- load
- path: salt//configs/interface.set
.. code-block:: yaml
Install the mentioned config:
junos:
... |
def validate(self, val):
if val in self.values:
return True, None
else:
return False, "'%s' is not in enum: %s" % (val, str(self.values)) | Validates that the val is in the list of values for this Enum.
Returns two element tuple: (bool, string)
- `bool` - True if valid, False if not
- `string` - Description of validation error, or None if valid
:Parameters:
val
Value to validate. Should be a string. |
def fermi_dist(energy, beta):
exponent = np.asarray(beta*energy).clip(-600, 600)
return 1./(np.exp(exponent) + 1) | Fermi Dirac distribution |
def __parse_drac(output):
drac = {}
section = ''
for i in output.splitlines():
if i.strip().endswith(':') and '=' not in i:
section = i[0:-1]
drac[section] = {}
if i.rstrip() and '=' in i:
if section in drac:
drac[section].update(dict(
... | Parse Dell DRAC output |
def transform(self, context, handler, result):
handler = handler.__func__ if hasattr(handler, '__func__') else handler
annotation = getattr(handler, '__annotations__', {}).get('return', None)
if annotation:
return (annotation, result)
return result | Transform the value returned by the controller endpoint.
This extension transforms returned values if the endpoint has a return type annotation. |
def to_node(value):
if isinstance(value, Node):
return value
elif isinstance(value, str):
return Node('string', value=value, pseudo_type='String')
elif isinstance(value, int):
return Node('int', value=value, pseudo_type='Int')
elif isinstance(value, bool):
return Node('bo... | Expand to a literal node if a basic type otherwise just returns the node |
def extract_fieldnames(config):
fields = []
for x in get_fields(config):
if x in fields:
fields.append(x + '_' + str(fields.count(x) + 1))
else:
fields.append(x)
return fields | Function to return a list of unique field names from the config file
:param config: The configuration file that contains the specification of the extractor
:return: A list of field names from the config file |
def write_config(self):
json.dump(
self.config,
open(CONFIG_FILE, 'w'),
indent=4,
separators=(',', ': ')
)
return True | Write the configuration to a local file.
:return: Boolean if successful |
def list_records(self, file_const=None):
for r in self._dataset.files:
if file_const and r.minor_type != file_const:
continue
yield self.instance_from_name(r.path) | Iterate through the file records |
def _validate_install(self):
self.printer('Checking heroku installation ... ', flush=True)
from os import devnull
from subprocess import call, check_output
sys_command = 'heroku --version'
try:
call(sys_command, shell=True, stdout=open(devnull, 'wb'))
e... | a method to validate heroku is installed |
def set_status(self, enabled):
self.__manual_update_time = time.time()
if enabled:
data = self._controller.command(self._id,
'auto_conditioning_start',
wake_if_asleep=True)
if data['response']... | Enable or disable the HVAC. |
def load(self, config):
password_dict = {}
if config is None:
logger.warning("No configuration file available. Cannot load password list.")
elif not config.has_section(self._section):
logger.warning("No [%s] section in the configuration file. Cannot load password list." %... | Load the password from the configuration file. |
def kernels_push_cli(self, folder):
folder = folder or os.getcwd()
result = self.kernels_push(folder)
if result is None:
print('Kernel push error: see previous output')
elif not result.error:
if result.invalidTags:
print(
'The f... | client wrapper for kernels_push, with same arguments. |
def startAll(self):
self.logger.info("Starting all workers...")
for worker in self.getWorkers():
process = self.getWorker(worker)
self.logger.debug("Starting {0}".format(process.name))
process.start()
self.logger.info("Started all workers") | Start all registered Workers. |
def _read_channel(channel, stream, start, duration):
channel_type = lalframe.FrStreamGetTimeSeriesType(channel, stream)
read_func = _fr_type_map[channel_type][0]
d_type = _fr_type_map[channel_type][1]
data = read_func(stream, channel, start, duration, 0)
return TimeSeries(data.data.data, delta_t=dat... | Get channel using lalframe |
def any_validator(obj, validators, **kwargs):
if not len(validators) > 1:
raise ValueError(
"any_validator requires at least 2 validator. Only got "
"{0}".format(len(validators))
)
errors = ErrorDict()
for key, validator in validators.items():
try:
... | Attempt multiple validators on an object.
- If any pass, then all validation passes.
- Otherwise, raise all of the errors. |
def rotate(self):
self._index -= 1
if self._index >= 0:
return self._ring[self._index]
return None | Rotate the kill ring, then yank back the new top.
Returns
-------
A text string or None. |
def export_gpx_file(self):
gpx = create_elem('gpx', GPX_ELEM_ATTRIB)
if not self.metadata.bounds:
self.metadata.bounds = [j for i in self for j in i]
gpx.append(self.metadata.togpx())
track = create_elem('trk')
gpx.append(track)
for segment in self:
... | Generate GPX element tree from ``Trackpoints``.
Returns:
etree.ElementTree: GPX element tree depicting ``Trackpoints``
objects |
def privacy_options_view(request):
if "user" in request.GET:
user = User.objects.user_with_ion_id(request.GET.get("user"))
elif "student_id" in request.GET:
user = User.objects.user_with_student_id(request.GET.get("student_id"))
else:
user = request.user
if not user:
mess... | View and edit privacy options for a user. |
def protect_pip_from_modification_on_windows(modifying_pip):
pip_names = [
"pip.exe",
"pip{}.exe".format(sys.version_info[0]),
"pip{}.{}.exe".format(*sys.version_info[:2])
]
should_show_use_python_msg = (
modifying_pip and
WINDOWS and
os.path.basename(sys.argv... | Protection of pip.exe from modification on Windows
On Windows, any operation modifying pip should be run as:
python -m pip ... |
def close(self):
if self._connection:
self._connection_file.close()
self._connection_file = None
self._connection.close()
self._connection = None | Closes connection with the q service. |
def knapsack_iterative(items, maxweight):
weights = [t[1] for t in items]
max_exp = max([number_of_decimals(w_) for w_ in weights])
coeff = 10 ** max_exp
int_maxweight = int(maxweight * coeff)
int_items = [(v, int(w * coeff), idx) for v, w, idx in items]
return knapsack_iterative_int(int_items, ... | items = int_items
maxweight = int_maxweight |
def get_stream_formats(self, media_item):
scraper = ScraperApi(self._ajax_api._connector)
formats = scraper.get_media_formats(media_item.media_id)
return formats | Get the available media formats for a given media item
@param crunchyroll.models.Media
@return dict |
def run(self):
qry = os.path.abspath(self.qry)
ref = os.path.abspath(self.ref)
outfile = os.path.abspath(self.outfile)
tmpdir = tempfile.mkdtemp(prefix='tmp.run_nucmer.', dir=os.getcwd())
original_dir = os.getcwd()
os.chdir(tmpdir)
script = 'run_nucmer.sh'
... | Change to a temp directory
Run bash script containing commands
Place results in specified output file
Clean up temp directory |
def create_intent(self,
parent,
intent,
language_code=None,
intent_view=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
... | Creates an intent in the specified agent.
Example:
>>> import dialogflow_v2
>>>
>>> client = dialogflow_v2.IntentsClient()
>>>
>>> parent = client.project_agent_path('[PROJECT]')
>>>
>>> # TODO: Initialize ``intent``:
... |
def preprocess_cell(
self, cell: "NotebookNode", resources: dict, index: int
) -> Tuple["NotebookNode", dict]:
if cell.cell_type == "markdown":
variables = cell["metadata"].get("variables", {})
if len(variables) > 0:
cell.source = self.replace_variables(cell.s... | Preprocess cell.
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
cell_index ... |
def _main(self):
self.set_proctitle(self.name)
self.set_signal_handler()
logger.info("process for module %s is now running (pid=%d)", self.name, os.getpid())
try:
self.main()
except (IOError, EOFError):
pass
except Exception as exp:
log... | module "main" method. Only used by external modules.
:return: None |
def import_mapping(connection_id, mapping):
url = os.path.join(settings.HEROKU_CONNECT_API_ENDPOINT,
'connections', connection_id, 'actions', 'import')
response = requests.post(
url=url,
json=mapping,
headers=_get_authorization_headers()
)
response.raise_fo... | Import Heroku Connection mapping for given connection.
Args:
connection_id (str): Heroku Connection connection ID.
mapping (dict): Heroku Connect mapping.
Raises:
requests.HTTPError: If an error occurs uploading the mapping.
ValueError: If the mapping is not JSON serializable. |
def parse(
files,
config=None,
compilation_mode=COMPILATION_MODE.FILE_BY_FILE,
cache=None):
if not config:
config = xml_generator_configuration_t()
parser = project_reader_t(config=config, cache=cache)
declarations = parser.read_files(files, compilation_mode)
conf... | Parse header files.
:param files: The header files that should be parsed
:type files: list of str
:param config: Configuration object or None
:type config: :class:`parser.xml_generator_configuration_t`
:param compilation_mode: Determines whether the files are parsed
ind... |
def create_organization(self, name):
log.warning('Creating organization...')
url = 'rest/servicedeskapi/organization'
data = {'name': name}
return self.post(url, headers=self.experimental_headers, data=data) | To create an organization Jira administrator global permission or agent permission is required
depending on the settings
:param name: str
:return: Organization data |
def show_settings(self):
self.notes.config.put_values()
self.overview.config.put_values()
self.settings.config.put_values()
self.spectrum.config.put_values()
self.traces.config.put_values()
self.video.config.put_values()
self.settings.show() | Open the Setting windows, after updating the values in GUI. |
def decode(vol, filename, content):
bbox = Bbox.from_filename(filename)
content_len = len(content) if content is not None else 0
if not content:
if vol.fill_missing:
content = ''
else:
raise EmptyVolumeException(filename)
shape = list(bbox.size3()) + [ vol.num_channels ]
try:
return ch... | Decode content according to settings in a cloudvolume instance. |
def select_fields(self, *fields):
if fields:
if not isinstance(fields[0], basestring):
fields = list(fields[0]) + list(fields)[1:]
for field_name in fields:
field_name = self._normalize_field_name(field_name)
self.select_field(field_name)
retu... | set multiple fields to be selected |
def clean_value(self):
result = []
for mdl in self:
result.append(super(ListNode, mdl).clean_value())
return result | Populates json serialization ready data.
This is the method used to serialize and store the object data in to DB
Returns:
List of dicts. |
def matches(self, *specs):
for spec in specs:
if ':' in spec:
app_name, endpoint_name = spec.split(':')
else:
app_name, endpoint_name = spec, None
for endpoint in self.endpoints:
if app_name == endpoint.application.name and \
... | Check if this relation matches relationship specs.
Relation specs are strings that would be given to Juju to establish a
relation, and should be in the form ``<application>[:<endpoint_name>]``
where the ``:<endpoint_name>`` suffix is optional. If the suffix is
omitted, this relation wi... |
def encode_numeric(self):
with io.StringIO() as buf:
for triplet in self.grouper(3, self.data):
number = ''
for digit in triplet:
if isinstance(digit, int):
digit = chr(digit)
if digit:
... | This method encodes the QR code's data if its mode is
numeric. It returns the data encoded as a binary string. |
def get_chunk(self, chunk_id):
if chunk_id in self.idx:
return Cchunk(self.idx[chunk_id], self.type)
else:
return None | Returns the chunk object for the supplied identifier
@type chunk_id: string
@param chunk_id: chunk identifier |
def delete_table(self, table_name):
data = {'TableName': table_name}
json_input = json.dumps(data)
return self.make_request('DeleteTable', json_input) | Deletes the table and all of it's data. After this request
the table will be in the DELETING state until DynamoDB
completes the delete operation.
:type table_name: str
:param table_name: The name of the table to delete. |
def colored(text, color=None, on_color=None, attrs=None, ansi_code=None):
if os.getenv('ANSI_COLORS_DISABLED') is None:
if ansi_code is not None:
return "\033[38;5;{}m{}\033[0m".format(ansi_code, text)
fmt_str = '\033[%dm%s'
if color is not None:
text = re.sub(COLORS_... | Colorize text, while stripping nested ANSI color sequences.
Author: Konstantin Lepa <konstantin.lepa@gmail.com> / termcolor
Available text colors:
red, green, yellow, blue, magenta, cyan, white.
Available text highlights:
on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white... |
def list_passwords(kwargs=None, call=None):
response = _query('support', 'password/list')
ret = {}
for item in response['list']:
if 'server' in item:
server = item['server']['name']
if server not in ret:
ret[server] = []
ret[server].append(item)
... | List all password on the account
.. versionadded:: 2015.8.0 |
def init_extension(self, app):
app.config.setdefault('CACHE_VERSION', '0')
app.config.setdefault('CACHE_PREFIX', 'r')
app.config.setdefault('CACHE_BACKEND', 'rio.exts.flask_cache.NullBackend')
app.config.setdefault('CACHE_BACKEND_OPTIONS', {}) | Initialize cache instance. |
def randomEarlyShared(store, role):
for r in role.allRoles():
share = store.findFirst(Share, Share.sharedTo == r,
sort=Share.storeID.ascending)
if share is not None:
return share.sharedItem
raise NoSuchShare("Why, that user hasn't shared anything at al... | If there are no explicitly-published public index pages to display, find a
shared item to present to the user as first. |
def TokenClient(
domain,
token,
user_agent=None,
request_encoder=default_request_encoder,
response_decoder=default_response_decoder,
):
return AuthorizingClient(
domain,
transport.TokenAuthorization(token),
request_encoder,
response_decoder,
user_agent=use... | Creates a Freshbooks client for a freshbooks domain, using
token-based auth.
The optional request_encoder and response_decoder parameters can be
passed the logging_request_encoder and logging_response_decoder objects
from this module, or custom encoders, to aid debugging or change the
behaviour... |
def _removeTags(tags, objects):
for t in tags:
for o in objects:
o.tags.remove(t)
return True | Removes tags from objects |
def open_inbox_page(self, content_type):
from .inbox_page import InboxPage
with self.term.loader('Loading inbox'):
page = InboxPage(self.reddit, self.term, self.config, self.oauth,
content_type=content_type)
if not self.term.loader.exception:
... | Open an instance of the inbox page for the logged in user. |
def aggregate(self, search):
for f, facet in iteritems(self.facets):
agg = facet.get_aggregation()
agg_filter = MatchAll()
for field, filter in iteritems(self._filters):
if f == field:
continue
agg_filter &= filter
... | Add aggregations representing the facets selected, including potential
filters. |
def is_address_guard(self, address):
try:
mbi = self.mquery(address)
except WindowsError:
e = sys.exc_info()[1]
if e.winerror == win32.ERROR_INVALID_PARAMETER:
return False
raise
return mbi.is_guard() | Determines if an address belongs to a guard page.
@note: Returns always C{False} for kernel mode addresses.
@type address: int
@param address: Memory address to query.
@rtype: bool
@return: C{True} if the address belongs to a guard page.
@raise WindowsError: An exce... |
def spheres_intersect(ar, aR, br, bR):
return vector.vector_mag_sq(ar - br) < (aR + bR) ** 2 | Return whether or not two spheres intersect each other.
Parameters
----------
ar, br: array-like, shape (n,) in n dimensions
Coordinates of the centres of the spheres `a` and `b`.
aR, bR: float
Radiuses of the spheres `a` and `b`.
Returns
-------
intersecting: boolean
... |
def check_internet_on(secrets_file_path):
while True:
if internet_on() is True and not os.path.exists(secrets_file_path):
break
else:
print("Turn on your internet and unplug your USB to continue...")
time.sleep(10)
return True | If internet on and USB unplugged, returns true. Else, continues to wait... |
def load_modules(self, modules, config):
for pluginclass in get_plugin_classes(modules):
name = pluginclass.__name__
if name in config["enabledplugins"]:
if issubclass(pluginclass, _ConnectionPlugin):
log.debug(LOG_PLUGIN, "Enable connection plugin %s"... | Load plugin modules. |
def get_pkg_version():
try:
with open("PKG-INFO", "r") as fp:
rgx = re.compile(r"Version: (\d+)")
for line in fp.readlines():
match = rgx.match(line)
if match:
return match.group(1)
except IOError:
return None | Get version string by parsing PKG-INFO. |
def ip_to_int(ip):
ret = 0
for octet in ip.split('.'):
ret = ret * 256 + int(octet)
return ret | Converts an IP address to an integer |
def run_query_series(queries, conn):
results = []
for item in queries:
qry = item
kwargs = {}
if isinstance(item, tuple):
qry = item[0]
kwargs = item[1]
result = conn.update_query(qry, **kwargs)
results.append(result)
return results | Iterates through a list of queries and runs them through the connection
Args:
-----
queries: list of strings or tuples containing (query_string, kwargs)
conn: the triplestore connection to use |
def changes_found(self):
if self.dest is None:
warnings.warn("dest directory not found!")
if self.src is None:
warnings.warn("src directory not found!")
if self.src is None or self.dest is None:
return False
dest_mtime = -1
src_mtime = os.path.... | Returns True if the target folder is older than the source folder. |
def _merge_colormaps(kwargs):
from trollimage.colormap import Colormap
full_cmap = None
palette = kwargs['palettes']
if isinstance(palette, Colormap):
full_cmap = palette
else:
for itm in palette:
cmap = create_colormap(itm)
cmap.set_range(itm["min_value"], it... | Merge colormaps listed in kwargs. |
def visit_const(self, node, parent):
return nodes.Const(
node.value,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | visit a Const node by returning a fresh instance of it |
def _process_article_phene_row(self, row):
phenotype_id = self.id_hash['phene'].get(row['phene_id'])
article_id = self.id_hash['article'].get(row['article_id'])
omia_id = self._get_omia_id_from_phene_id(phenotype_id)
if self.test_mode or omia_id not in self.test_ids['disease'] \
... | Linking articles to species-specific phenes.
:param row:
:return: |
def _extract_tls_session_ticket(ssl_session: nassl._nassl.SSL_SESSION) -> str:
session_string = ((ssl_session.as_text()).split('TLS session ticket:'))[1]
session_tls_ticket = (session_string.split('Compression:'))[0]
return session_tls_ticket | Extract the TLS session ticket from a SSL session object or raises IndexError if the ticket was not set. |
def crop_resize_image(image: np.ndarray, size) -> np.ndarray:
width, height = image.size
if width > height:
left = (width - height) / 2
right = width - left
top = 0
bottom = height
else:
top = (height - width) / 2
bottom = height - top
left = 0
... | Resize the input image.
:param image: Original image which is a PIL object.
:param size: Tuple of height and width to resize the image to.
:return: Resized image which is a PIL object |
def attach_remote_media(self, url, username=None, password=None):
self.oem_init()
return self._oem.attach_remote_media(url, username, password) | Attach remote media by url
Given a url, attach remote media (cd/usb image) to the target system.
:param url: URL to indicate where to find image (protocol support
varies by BMC)
:param username: Username for endpoint to use when accessing the URL.
... |
def _cost_method(self, *args, **kwargs):
cost_val = self.thresh * nuclear_norm(cube2matrix(args[0]))
if 'verbose' in kwargs and kwargs['verbose']:
print(' - NUCLEAR NORM (X):', cost_val)
return cost_val | Calculate low-rank component of the cost
This method returns the nuclear norm error of the deconvolved data in
matrix form
Returns
-------
float low-rank cost component |
def timex_starts(self):
if not self.is_tagged(TIMEXES):
self.tag_timexes()
return self.starts(TIMEXES) | The list of start positions of ``timexes`` layer elements. |
def invert_projection(self, X, identities):
distances = self.transform(X)
if len(distances) != len(identities):
raise ValueError("X and identities are not the same length: "
"{0} and {1}".format(len(X), len(identities)))
node_match = []
for d in d... | Calculate the inverted projection.
The inverted projectio of a SOM is created by association each weight
with the input which matches it the most, thus giving a good
approximation of the "influence" of each input item.
Works best for symbolic (instead of continuous) input data.
... |
def visit_augassign(self, node, parent):
newnode = nodes.AugAssign(
self._bin_op_classes[type(node.op)] + "=",
node.lineno,
node.col_offset,
parent,
)
newnode.postinit(
self.visit(node.target, newnode), self.visit(node.value, newnode)
... | visit a AugAssign node by returning a fresh instance of it |
def get_dict_for_mongodb_queries(self):
d = {}
return d
all_structures = [task.input.structure for task in self.iflat_tasks()]
all_pseudos = [task.input.pseudos for task in self.iflat_tasks()] | This function returns a dictionary with the attributes that will be
put in the mongodb document to facilitate the query.
Subclasses may want to replace or extend the default behaviour. |
def _validate_planar_fault_geometry(self, node, _float_re):
valid_spacing = node["spacing"]
for key in ["topLeft", "topRight", "bottomLeft", "bottomRight"]:
lon = getattr(node, key)["lon"]
lat = getattr(node, key)["lat"]
depth = getattr(node, key)["depth"]
... | Validares a node representation of a planar fault geometry |
def backward_delete_char(event):
" Delete the character behind the cursor. "
if event.arg < 0:
deleted = event.current_buffer.delete(count=-event.arg)
else:
deleted = event.current_buffer.delete_before_cursor(count=event.arg)
if not deleted:
event.cli.output.bell() | Delete the character behind the cursor. |
def setduration(self, **duration):
if len(duration) == 1:
arg = [x[0] for x in duration.items()]
if not arg[0] in self.units:
raise Exception('must be: %s' % str(self.units))
self.duration = arg
return self | Set the caching duration which defines how long the
file will be cached.
@param duration: The cached file duration which defines how
long the file will be cached. A duration=0 means forever.
The duration may be: (months|weeks|days|hours|minutes|seconds).
@type duration: ... |
def structure(cls):
downstream = cls.cutter.elucidate()
upstream = str(Seq(downstream).reverse_complement())
return "".join(
[
upstream.replace("^", ")(").replace("_", "("),
"N*",
downstream.replace("^", ")(").replace("_", ")"),
... | Get the vector structure, as a DNA regex pattern.
Warning:
If overloading this method, the returned pattern must include 3
capture groups to capture the following features:
1. The downstream (3') overhang sequence
2. The vector placeholder sequence
3... |
def wait_for_save(filename, timeout=5):
modification_time = os.path.getmtime(filename)
start_time = time.time()
while time.time() < start_time + timeout:
if (os.path.getmtime(filename) > modification_time and
os.path.getsize(filename) > 0):
return True
time.sleep(0.2)... | Waits for FILENAME to update, waiting up to TIMEOUT seconds.
Returns True if a save was detected, and False otherwise. |
def geolocate(client, home_mobile_country_code=None,
home_mobile_network_code=None, radio_type=None, carrier=None,
consider_ip=None, cell_towers=None, wifi_access_points=None):
params = {}
if home_mobile_country_code is not None:
params["homeMobileCountryCode"] = home_mobile_... | The Google Maps Geolocation API returns a location and accuracy
radius based on information about cell towers and WiFi nodes given.
See https://developers.google.com/maps/documentation/geolocation/intro
for more info, including more detail for each parameter below.
:param home_mobile_country_code: The... |
def bitswap_unwant(self, key, **kwargs):
args = (key,)
return self._client.request('/bitswap/unwant', args, **kwargs) | Remove a given block from wantlist.
Parameters
----------
key : str
Key to remove from wantlist. |
def accepts_kwarg(func, kwarg):
signature = inspect.signature(func)
try:
signature.bind_partial(**{kwarg: None})
return True
except TypeError:
return False | Determine whether the callable `func` has a signature that accepts the
keyword argument `kwarg` |
def delete(stack_ref: List[str],
region: str, dry_run: bool, force: bool, remote: str):
lizzy = setup_lizzy_client(remote)
stack_refs = get_stack_refs(stack_ref)
all_with_version = all(stack.version is not None
for stack in stack_refs)
if (not all_with_version and n... | Delete Cloud Formation stacks |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.