code stringlengths 51 2.34k | sequence stringlengths 186 3.94k | docstring stringlengths 11 171 |
|---|---|---|
def rlmb_tiny_recurrent():
hparams = rlmb_ppo_tiny()
hparams.epochs = 1
hparams.generative_model = "next_frame_basic_recurrent"
hparams.generative_model_params = "next_frame_basic_recurrent"
return hparams | module function_definition identifier parameters block expression_statement assignment identifier call identifier argument_list expression_statement assignment attribute identifier identifier integer expression_statement assignment attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier string string_start string_content string_end return_statement identifier | Tiny setting with a recurrent next-frame model. |
def legal_date(year, month, day):
if month == 2:
daysinmonth = 29 if isleap(year) else 28
else:
daysinmonth = 30 if month in HAVE_30_DAYS else 31
if not (0 < day <= daysinmonth):
raise ValueError("Month {} doesn't have a day {}".format(month, day))
return True | module function_definition identifier parameters identifier identifier identifier block if_statement comparison_operator identifier integer block expression_statement assignment identifier conditional_expression integer call identifier argument_list identifier integer else_clause block expression_statement assignment identifier conditional_expression integer comparison_operator identifier identifier integer if_statement not_operator parenthesized_expression comparison_operator integer identifier identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier return_statement true | Check if this is a legal date in the Gregorian calendar |
def _check_team_login(team):
contents = _load_auth()
for auth in itervalues(contents):
existing_team = auth.get('team')
if team and team != existing_team:
raise CommandException(
"Can't log in as team %r; log out first." % team
)
elif not team and existing_team:
raise CommandException(
"Can't log in as a public user; log out from team %r first." % existing_team
) | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list for_statement identifier call identifier argument_list identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator identifier comparison_operator identifier identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier elif_clause boolean_operator not_operator identifier identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier | Disallow simultaneous public cloud and team logins. |
def disconnect(self):
if self.r_session:
self.session_logout()
self.r_session = None
self.clear() | module function_definition identifier parameters identifier block if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier none expression_statement call attribute identifier identifier argument_list | Ends a client authentication session, performs a logout and a clean up. |
def _init_study_items_max(self):
if self.study_items is None:
return None
if self.study_items is True:
return None
if isinstance(self.study_items, int):
return self.study_items
return None | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block return_statement none if_statement comparison_operator attribute identifier identifier true block return_statement none if_statement call identifier argument_list attribute identifier identifier identifier block return_statement attribute identifier identifier return_statement none | User can limit the number of genes printed in a GO term. |
def add_header(self, key, value):
assert isinstance(key, str), 'header key must be of type str'
assert isinstance(value, str), 'header value must be of type str'
self.headers[key] = value | module function_definition identifier parameters identifier identifier identifier block assert_statement call identifier argument_list identifier identifier string string_start string_content string_end assert_statement call identifier argument_list identifier identifier string string_start string_content string_end expression_statement assignment subscript attribute identifier identifier identifier identifier | Add a response header |
def create_build_paths(context: Context):
paths = [context.app.asset_build_path, context.app.screenshots_build_path, context.app.collected_assets_path]
for path in filter(None, paths):
os.makedirs(path, exist_ok=True) | module function_definition identifier parameters typed_parameter identifier type identifier block expression_statement assignment identifier list attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier for_statement identifier call identifier argument_list none identifier block expression_statement call attribute identifier identifier argument_list identifier keyword_argument identifier true | Creates directories needed for build outputs |
def class_string(self, klass):
if isinstance(klass, string_types):
return klass
return klass.__module__ + '.' + klass.__name__ | module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block return_statement identifier return_statement binary_operator binary_operator attribute identifier identifier string string_start string_content string_end attribute identifier identifier | Return a string representative of the class |
def shell(config, type_):
from warehouse.db import Session
if type_ is None:
type_ = autodetect()
runner = {"bpython": bpython, "ipython": ipython, "plain": plain}[type_]
session = Session(bind=config.registry["sqlalchemy.engine"])
try:
runner(config=config, db=session)
except ImportError:
raise click.ClickException(
"The {!r} shell is not available.".format(type_)
) from None | module function_definition identifier parameters identifier identifier block import_from_statement dotted_name identifier identifier dotted_name identifier if_statement comparison_operator identifier none block expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier subscript dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier identifier expression_statement assignment identifier call identifier argument_list keyword_argument identifier subscript attribute identifier identifier string string_start string_content string_end try_statement block expression_statement call identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier except_clause identifier block raise_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier none | Open up a Python shell with Warehouse preconfigured in it. |
def write_path(path, s, owner=None, group=None, mode=None,
utimes=None, sync=False):
path = os.path.abspath(path)
fd, tmp_path = tempfile.mkstemp(suffix='.tmp',
prefix='.ansible_mitogen_transfer-',
dir=os.path.dirname(path))
fp = os.fdopen(fd, 'wb', mitogen.core.CHUNK_SIZE)
LOG.debug('write_path(path=%r) temporary file: %s', path, tmp_path)
try:
try:
if mode:
set_file_mode(tmp_path, mode, fd=fp.fileno())
if owner or group:
set_file_owner(tmp_path, owner, group, fd=fp.fileno())
fp.write(s)
finally:
fp.close()
if sync:
os.fsync(fp.fileno())
os.rename(tmp_path, path)
except BaseException:
os.unlink(tmp_path)
raise
if utimes:
os.utime(path, utimes) | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier false block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list keyword_argument identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier string string_start string_content string_end attribute attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier try_statement block try_statement block if_statement identifier block expression_statement call identifier argument_list identifier identifier keyword_argument identifier call attribute identifier identifier argument_list if_statement boolean_operator identifier identifier block expression_statement call identifier argument_list identifier identifier identifier keyword_argument identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier finally_clause block expression_statement call attribute identifier identifier argument_list if_statement identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier identifier except_clause identifier block expression_statement call attribute identifier identifier argument_list identifier raise_statement if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier identifier | Writes bytes `s` to a filesystem `path`. |
def datetime_from_json(js, manager):
if js is None:
return None
else:
return dt.datetime(
js['year'],
js['month'] + 1,
js['date'],
js['hours'],
js['minutes'],
js['seconds'],
js['milliseconds'] * 1000
) | module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier none block return_statement none else_clause block return_statement call attribute identifier identifier argument_list subscript identifier string string_start string_content string_end binary_operator subscript identifier string string_start string_content string_end integer subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end binary_operator subscript identifier string string_start string_content string_end integer | Deserialize a Python datetime object from json. |
def cli(ctx=None, verbose=0):
if ctx:
ctx.auto_envvar_prefix = "THOTH_SOLVER"
if verbose:
_LOG.setLevel(logging.DEBUG)
_LOG.debug("Debug mode is on") | module function_definition identifier parameters default_parameter identifier none default_parameter identifier integer block if_statement identifier block expression_statement assignment attribute identifier identifier string string_start string_content string_end if_statement identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end | Thoth solver command line interface. |
def validate_plugin(self, plugin_class, experimental=False):
valid_subclasses = [IndependentPlugin] + self.valid_subclasses
if experimental:
valid_subclasses += [ExperimentalPlugin]
return any(issubclass(plugin_class, class_) for
class_ in valid_subclasses) | module function_definition identifier parameters identifier identifier default_parameter identifier false block expression_statement assignment identifier binary_operator list identifier attribute identifier identifier if_statement identifier block expression_statement augmented_assignment identifier list identifier return_statement call identifier generator_expression call identifier argument_list identifier identifier for_in_clause identifier identifier | Verifies that the plugin_class should execute under this policy |
def validate(self) :
if not self.mustValidate :
return True
res = {}
for field in self.validators.keys() :
try :
if isinstance(self.validators[field], dict) and field not in self.store :
self.store[field] = DocumentStore(self.collection, validators = self.validators[field], initDct = {}, subStore=True, validateInit=self.validateInit)
self.validateField(field)
except InvalidDocument as e :
res.update(e.errors)
except (ValidationError, SchemaViolation) as e:
res[field] = str(e)
if len(res) > 0 :
raise InvalidDocument(res)
return True | module function_definition identifier parameters identifier block if_statement not_operator attribute identifier identifier block return_statement true expression_statement assignment identifier dictionary for_statement identifier call attribute attribute identifier identifier identifier argument_list block try_statement block if_statement boolean_operator call identifier argument_list subscript attribute identifier identifier identifier identifier comparison_operator identifier attribute identifier identifier block expression_statement assignment subscript attribute identifier identifier identifier call identifier argument_list attribute identifier identifier keyword_argument identifier subscript attribute identifier identifier identifier keyword_argument identifier dictionary keyword_argument identifier true keyword_argument identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier except_clause as_pattern tuple identifier identifier as_pattern_target identifier block expression_statement assignment subscript identifier identifier call identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block raise_statement call identifier argument_list identifier return_statement true | Validate the whole document |
def generic_adjust(colors, light):
if light:
for color in colors:
color = util.saturate_color(color, 0.60)
color = util.darken_color(color, 0.5)
colors[0] = util.lighten_color(colors[0], 0.95)
colors[7] = util.darken_color(colors[0], 0.75)
colors[8] = util.darken_color(colors[0], 0.25)
colors[15] = colors[7]
else:
colors[0] = util.darken_color(colors[0], 0.80)
colors[7] = util.lighten_color(colors[0], 0.75)
colors[8] = util.lighten_color(colors[0], 0.25)
colors[15] = colors[7]
return colors | module function_definition identifier parameters identifier identifier block if_statement identifier block for_statement identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier float expression_statement assignment identifier call attribute identifier identifier argument_list identifier float expression_statement assignment subscript identifier integer call attribute identifier identifier argument_list subscript identifier integer float expression_statement assignment subscript identifier integer call attribute identifier identifier argument_list subscript identifier integer float expression_statement assignment subscript identifier integer call attribute identifier identifier argument_list subscript identifier integer float expression_statement assignment subscript identifier integer subscript identifier integer else_clause block expression_statement assignment subscript identifier integer call attribute identifier identifier argument_list subscript identifier integer float expression_statement assignment subscript identifier integer call attribute identifier identifier argument_list subscript identifier integer float expression_statement assignment subscript identifier integer call attribute identifier identifier argument_list subscript identifier integer float expression_statement assignment subscript identifier integer subscript identifier integer return_statement identifier | Generic color adjustment for themers. |
def write_to(self, f):
f.write(self.version + "\r\n")
for name, value in self.items():
name = name.title()
name = name.replace("Warc-", "WARC-").replace("-Ip-", "-IP-").replace("-Id", "-ID").replace("-Uri", "-URI")
f.write(name)
f.write(": ")
f.write(value)
f.write("\r\n")
f.write("\r\n") | module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list binary_operator attribute identifier identifier string string_start string_content escape_sequence escape_sequence string_end for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute call attribute call attribute call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence escape_sequence string_end expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence escape_sequence string_end | Writes this header to a file, in the format specified by WARC. |
def find(self, other):
iset = self._iset
l = binsearch_left_start(iset, other[0] - self._maxlen, 0, len(iset))
r = binsearch_right_end(iset, other[1], 0, len(iset))
iopts = iset[l:r]
iiter = (s for s in iopts if s[0] <= other[1] and s[1] >= other[0])
for o in iiter: yield o | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier binary_operator subscript identifier integer attribute identifier identifier integer call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list identifier subscript identifier integer integer call identifier argument_list identifier expression_statement assignment identifier subscript identifier slice identifier identifier expression_statement assignment identifier generator_expression identifier for_in_clause identifier identifier if_clause boolean_operator comparison_operator subscript identifier integer subscript identifier integer comparison_operator subscript identifier integer subscript identifier integer for_statement identifier identifier block expression_statement yield identifier | Return an interable of elements that overlap other in the tree. |
def query_module_funcs(self, module):
funcs = self.session.query(Export).filter_by(
module=module).all()
return funcs | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute call attribute call attribute attribute identifier identifier identifier argument_list identifier identifier argument_list keyword_argument identifier identifier identifier argument_list return_statement identifier | Query the functions in the specified module. |
def conn_ali(cred, crid):
driver = get_driver(Provider.ALIYUN_ECS)
try:
ali_obj = driver(cred['ali_access_key_id'],
cred['ali_access_key_secret'],
region=cred['ali_region'])
except SSLError as e:
abort_err("\r SSL Error with AliCloud: {}".format(e))
except InvalidCredsError as e:
abort_err("\r Error with AliCloud Credentials: {}".format(e))
return {crid: ali_obj} | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier try_statement block expression_statement assignment identifier call identifier argument_list subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end keyword_argument identifier subscript identifier string string_start string_content string_end except_clause as_pattern identifier as_pattern_target identifier block expression_statement call identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier argument_list identifier return_statement dictionary pair identifier identifier | Establish connection to AliCloud service. |
def new(self, operation='no operation', **kw):
self_vars = vars(self).copy()
del self_vars['operation']
del self_vars['children']
del self_vars['counts']
del self_vars['_flush']
new = self.__class__(operation)
vars(new).update(self_vars)
vars(new).update(kw)
return new | module function_definition identifier parameters identifier default_parameter identifier string string_start string_content string_end dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier identifier argument_list delete_statement subscript identifier string string_start string_content string_end delete_statement subscript identifier string string_start string_content string_end delete_statement subscript identifier string string_start string_content string_end delete_statement subscript identifier string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call attribute call identifier argument_list identifier identifier argument_list identifier expression_statement call attribute call identifier argument_list identifier identifier argument_list identifier return_statement identifier | Return a copy of the monitor usable for a different operation. |
def process_request(self, request):
if self._is_enabled():
self._cache.set(self.guid_key, six.text_type(uuid4()))
log_prefix = self._log_prefix(u"Before", request)
self._cache.set(self.memory_data_key, self._memory_data(log_prefix)) | module function_definition identifier parameters identifier identifier block if_statement call attribute identifier identifier argument_list block expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier call attribute identifier identifier argument_list call identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier call attribute identifier identifier argument_list identifier | Store memory data to log later. |
def _one_q_sic_prep(index, qubit):
if index == 0:
return Program()
theta = 2 * np.arccos(1 / np.sqrt(3))
zx_plane_rotation = Program([
RX(-pi / 2, qubit),
RZ(theta - pi, qubit),
RX(-pi / 2, qubit),
])
if index == 1:
return zx_plane_rotation
elif index == 2:
return zx_plane_rotation + RZ(-2 * pi / 3, qubit)
elif index == 3:
return zx_plane_rotation + RZ(2 * pi / 3, qubit)
raise ValueError(f'Bad SIC index: {index}') | module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier integer block return_statement call identifier argument_list expression_statement assignment identifier binary_operator integer call attribute identifier identifier argument_list binary_operator integer call attribute identifier identifier argument_list integer expression_statement assignment identifier call identifier argument_list list call identifier argument_list binary_operator unary_operator identifier integer identifier call identifier argument_list binary_operator identifier identifier identifier call identifier argument_list binary_operator unary_operator identifier integer identifier if_statement comparison_operator identifier integer block return_statement identifier elif_clause comparison_operator identifier integer block return_statement binary_operator identifier call identifier argument_list binary_operator binary_operator unary_operator integer identifier integer identifier elif_clause comparison_operator identifier integer block return_statement binary_operator identifier call identifier argument_list binary_operator binary_operator integer identifier integer identifier raise_statement call identifier argument_list string string_start string_content interpolation identifier string_end | Prepare the index-th SIC basis state. |
def _arg2opt(arg):
res = [o for o, a in option_toggles.items() if a == arg]
res += [o for o, a in option_flags.items() if a == arg]
return res[0] if res else None | module function_definition identifier parameters identifier block expression_statement assignment identifier list_comprehension identifier for_in_clause pattern_list identifier identifier call attribute identifier identifier argument_list if_clause comparison_operator identifier identifier expression_statement augmented_assignment identifier list_comprehension identifier for_in_clause pattern_list identifier identifier call attribute identifier identifier argument_list if_clause comparison_operator identifier identifier return_statement conditional_expression subscript identifier integer identifier none | Turn a pass argument into the correct option |
def jsondump(model, fp):
fp.write('[')
links_ser = []
for link in model:
links_ser.append(json.dumps(link))
fp.write(',\n'.join(links_ser))
fp.write(']') | module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier list for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end | Dump Versa model into JSON form |
def mixed_use_of_local_and_run(self):
cxn = Connection("localhost")
result = cxn.local("echo foo", hide=True)
assert result.stdout == "foo\n"
assert not cxn.is_connected
result = cxn.run("echo foo", hide=True)
assert cxn.is_connected
assert result.stdout == "foo\n" | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end keyword_argument identifier true assert_statement comparison_operator attribute identifier identifier string string_start string_content escape_sequence string_end assert_statement not_operator attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end keyword_argument identifier true assert_statement attribute identifier identifier assert_statement comparison_operator attribute identifier identifier string string_start string_content escape_sequence string_end | Run command truly locally, and over SSH via localhost |
def open_url(self, url):
try:
c = pycurl.Curl()
c.setopt(pycurl.FAILONERROR, True)
c.setopt(pycurl.URL, "%s/api/v0/%s" % (self.url, url))
c.setopt(pycurl.HTTPHEADER, ["User-Agent: %s" % self.userAgent,
"apiToken: %s" % self.apiToken])
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
c.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_SSLv3)
c.setopt(pycurl.SSL_VERIFYPEER, 1)
c.setopt(pycurl.SSL_VERIFYHOST, 2)
c.perform()
return b.getvalue()
except pycurl.error, e:
raise MyTimetableError(e) | module function_definition identifier parameters identifier identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list attribute identifier identifier true expression_statement call attribute identifier identifier argument_list attribute identifier identifier binary_operator string string_start string_content string_end tuple attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier list binary_operator string string_start string_content string_end attribute identifier identifier binary_operator string string_start string_content string_end attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier integer expression_statement call attribute identifier identifier argument_list attribute identifier identifier integer expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier integer expression_statement call attribute identifier identifier argument_list attribute identifier identifier integer expression_statement call attribute identifier identifier argument_list return_statement call attribute identifier identifier argument_list except_clause attribute identifier identifier identifier block raise_statement call identifier argument_list identifier | Open's URL with apiToken in the headers |
def pop(self, key, *args, **kwargs):
return super(CaseInsensitiveDict, self).pop(CaseInsensitiveStr(key)) | module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block return_statement call attribute call identifier argument_list identifier identifier identifier argument_list call identifier argument_list identifier | Remove and return the value associated with case-insensitive ``key``. |
def __create_phantom_js_driver(self):
try:
return webdriver.PhantomJS(executable_path=self._config_reader.get(self.PHANTOMEJS_EXEC_PATH),
service_args=['--ignore-ssl-errors=true'])
except KeyError:
return webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true']) | module function_definition identifier parameters identifier block try_statement block return_statement call attribute identifier identifier argument_list keyword_argument identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier keyword_argument identifier list string string_start string_content string_end except_clause identifier block return_statement call attribute identifier identifier argument_list keyword_argument identifier list string string_start string_content string_end | Creates an instance of PhantomJS driver. |
def from_code(cls, code: int) -> 'ColorCode':
c = cls()
c._init_code(code)
return c | module function_definition identifier parameters identifier typed_parameter identifier type identifier type string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Return a ColorCode from a terminal code. |
def to_dict(self):
import copy
options = copy.deepcopy(self._options)
eta = options.get('task_args', {}).get('eta')
if eta:
options['task_args']['eta'] = time.mktime(eta.timetuple())
return options | module function_definition identifier parameters identifier block import_statement dotted_name identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute call attribute identifier identifier argument_list string string_start string_content string_end dictionary identifier argument_list string string_start string_content string_end if_statement identifier block expression_statement assignment subscript subscript identifier string string_start string_content string_end string string_start string_content string_end call attribute identifier identifier argument_list call attribute identifier identifier argument_list return_statement identifier | Return this message as a dict suitable for json encoding. |
def _query_systemstate(self):
def status_filter_func(event):
if event.command_class == 3 and event.command == 0:
return True
return False
try:
response = self._send_command(0, 6, [])
maxconn, = unpack("<B", response.payload)
except InternalTimeoutError:
return False, {'reason': 'Timeout waiting for command response'}
events = self._wait_process_events(0.5, status_filter_func, lambda x: False)
conns = []
for event in events:
handle, flags, addr, addr_type, interval, timeout, lat, bond = unpack("<BB6sBHHHB", event.payload)
if flags != 0:
conns.append(handle)
return True, {'max_connections': maxconn, 'active_connections': conns} | module function_definition identifier parameters identifier block function_definition identifier parameters identifier block if_statement boolean_operator comparison_operator attribute identifier identifier integer comparison_operator attribute identifier identifier integer block return_statement true return_statement false try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list integer integer list expression_statement assignment pattern_list identifier call identifier argument_list string string_start string_content string_end attribute identifier identifier except_clause identifier block return_statement expression_list false dictionary pair string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list float identifier lambda lambda_parameters identifier false expression_statement assignment identifier list for_statement identifier identifier block expression_statement assignment pattern_list identifier identifier identifier identifier identifier identifier identifier identifier call identifier argument_list string string_start string_content string_end attribute identifier identifier if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list identifier return_statement expression_list true dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier | Query the maximum number of connections supported by this adapter |
def visualize(x, y, xlabel=None, ylabel=None, title=None, ylim=None):
total_seconds = (x[-1] - x[0]).total_seconds()
if total_seconds <= 86400 * 1 * 3:
return plot_one_day(x, y, xlabel, ylabel, title, ylim)
elif total_seconds <= 86400 * 7 * 2:
return plot_one_week(x, y, xlabel, ylabel, title, ylim)
elif total_seconds <= 86400 * 30 * 1.5:
return plot_one_month(x, y, xlabel, ylabel, title, ylim)
elif total_seconds <= 86400 * 90 * 1.5:
return plot_one_quarter(x, y, xlabel, ylabel, title, ylim)
elif total_seconds <= 86400 * 365 * 1.5:
return plot_one_year(x, y, xlabel, ylabel, title, ylim) | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none block expression_statement assignment identifier call attribute parenthesized_expression binary_operator subscript identifier unary_operator integer subscript identifier integer identifier argument_list if_statement comparison_operator identifier binary_operator binary_operator integer integer integer block return_statement call identifier argument_list identifier identifier identifier identifier identifier identifier elif_clause comparison_operator identifier binary_operator binary_operator integer integer integer block return_statement call identifier argument_list identifier identifier identifier identifier identifier identifier elif_clause comparison_operator identifier binary_operator binary_operator integer integer float block return_statement call identifier argument_list identifier identifier identifier identifier identifier identifier elif_clause comparison_operator identifier binary_operator binary_operator integer integer float block return_statement call identifier argument_list identifier identifier identifier identifier identifier identifier elif_clause comparison_operator identifier binary_operator binary_operator integer integer float block return_statement call identifier argument_list identifier identifier identifier identifier identifier identifier | A universal function plot arbitrary time series data. |
def _gen_packet_setcolor(self, sequence, hue, sat, bri, kel, fade):
hue = min(max(hue, HUE_MIN), HUE_MAX)
sat = min(max(sat, SATURATION_MIN), SATURATION_MAX)
bri = min(max(bri, BRIGHTNESS_MIN), BRIGHTNESS_MAX)
kel = min(max(kel, TEMP_MIN), TEMP_MAX)
reserved1 = pack("<B", 0)
hue = pack("<H", hue)
saturation = pack("<H", sat)
brightness = pack("<H", bri)
kelvin = pack("<H", kel)
duration = pack("<I", fade)
payload = bytearray(reserved1)
payload.extend(hue)
payload.extend(saturation)
payload.extend(brightness)
payload.extend(kelvin)
payload.extend(duration)
return self._gen_packet(sequence, PayloadType.SETCOLOR, payload) | module function_definition identifier parameters identifier identifier identifier identifier identifier identifier identifier block expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier identifier identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier identifier identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier identifier identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier identifier identifier expression_statement assignment identifier call identifier argument_list string string_start string_content string_end integer expression_statement assignment identifier call identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier attribute identifier identifier identifier | Generate "setcolor" packet payload. |
def trace():
def fget(self):
return self._options.get('trace', None)
def fset(self, value):
self._options['trace'] = value
return locals() | module function_definition identifier parameters block function_definition identifier parameters identifier block return_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end none function_definition identifier parameters identifier identifier block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end identifier return_statement call identifier argument_list | Enables and disables request tracing. |
def _get_schema(self):
d={}
layout_kwargs=dict((_,'') for _ in get_layout_kwargs())
for _ in ('data','layout','theme','panels'):
d[_]={}
for __ in eval('__QUANT_FIGURE_{0}'.format(_.upper())):
layout_kwargs.pop(__,None)
d[_][__]=None
d['layout'].update(annotations=dict(values=[],
params=utils.make_dict_from_list(get_annotation_kwargs())))
d['layout'].update(shapes=utils.make_dict_from_list(get_shapes_kwargs()))
[layout_kwargs.pop(_,None) for _ in get_annotation_kwargs()+get_shapes_kwargs()]
d['layout'].update(**layout_kwargs)
return d | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary expression_statement assignment identifier call identifier generator_expression tuple identifier string string_start string_end for_in_clause identifier call identifier argument_list for_statement identifier tuple string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end block expression_statement assignment subscript identifier identifier dictionary for_statement identifier call identifier argument_list call attribute string string_start string_content string_end identifier argument_list call attribute identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list identifier none expression_statement assignment subscript subscript identifier identifier identifier none expression_statement call attribute subscript identifier string string_start string_content string_end identifier argument_list keyword_argument identifier call identifier argument_list keyword_argument identifier list keyword_argument identifier call attribute identifier identifier argument_list call identifier argument_list expression_statement call attribute subscript identifier string string_start string_content string_end identifier argument_list keyword_argument identifier call attribute identifier identifier argument_list call identifier argument_list expression_statement list_comprehension call attribute identifier identifier argument_list identifier none for_in_clause identifier binary_operator call identifier argument_list call identifier argument_list expression_statement call attribute subscript identifier string string_start string_content string_end identifier argument_list dictionary_splat identifier return_statement identifier | Returns a dictionary with the schema for a QuantFigure |
def _format_contracts(what: str, obj: Any) -> List[str]:
if what in ['function', 'method', 'attribute']:
if what == 'attribute':
if not isinstance(obj, property):
return []
return _format_property_contracts(prop=obj)
if what in ['function', 'method']:
return _format_function_contracts(func=obj)
raise NotImplementedError("Unhandled what: {}".format(what))
elif what == 'class':
invariants = getattr(obj, "__invariants__", [])
assert isinstance(invariants, list)
assert all(isinstance(inv, icontract._Contract) for inv in invariants)
return _format_invariants(invariants=invariants)
return [] | module function_definition identifier parameters typed_parameter identifier type identifier typed_parameter identifier type identifier type generic_type identifier type_parameter type identifier block if_statement comparison_operator identifier list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end block if_statement comparison_operator identifier string string_start string_content string_end block if_statement not_operator call identifier argument_list identifier identifier block return_statement list return_statement call identifier argument_list keyword_argument identifier identifier if_statement comparison_operator identifier list string string_start string_content string_end string string_start string_content string_end block return_statement call identifier argument_list keyword_argument identifier identifier raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier elif_clause comparison_operator identifier string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list identifier string string_start string_content string_end list assert_statement call identifier argument_list identifier identifier assert_statement call identifier generator_expression call identifier argument_list identifier attribute identifier identifier for_in_clause identifier identifier return_statement call identifier argument_list keyword_argument identifier identifier return_statement list | Format the contracts as reST. |
def check_no_alert(self):
try:
alert = Alert(world.browser)
raise AssertionError("Should not see an alert. Alert '%s' shown." %
alert.text)
except NoAlertPresentException:
pass | module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call identifier argument_list attribute identifier identifier raise_statement call identifier argument_list binary_operator string string_start string_content string_end attribute identifier identifier except_clause identifier block pass_statement | Assert there is no alert. |
def run_func(func, *args, **kwargs):
ray.init()
func = ray.remote(func)
result = ray.get(func.remote(*args))
caller = inspect.stack()[1][3]
print("%s: %s" % (caller, str(result)))
return result | module function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list list_splat identifier expression_statement assignment identifier subscript subscript call attribute identifier identifier argument_list integer integer expression_statement call identifier argument_list binary_operator string string_start string_content string_end tuple identifier call identifier argument_list identifier return_statement identifier | Helper function for running examples |
def reset(self):
self.pid = os.getpid()
self._created_connections = 0
self._created_connections_per_node = {}
self._available_connections = {}
self._in_use_connections = {}
self._check_lock = threading.Lock()
self.initialized = False | module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier integer expression_statement assignment attribute identifier identifier dictionary expression_statement assignment attribute identifier identifier dictionary expression_statement assignment attribute identifier identifier dictionary expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier false | Resets the connection pool back to a clean state. |
def add_log_callback(callback):
global _log_callbacks
if not callable(callback):
raise ValueError("Callback must be callable")
_log_callbacks.add(callback)
return callback | module function_definition identifier parameters identifier block global_statement identifier if_statement not_operator call identifier argument_list identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Adds a log callback. |
def DEFINE_constant_string(self, name, default, help):
self.AddOption(
type_info.String(name=name, default=default or "", description=help),
constant=True) | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier boolean_operator identifier string string_start string_end keyword_argument identifier identifier keyword_argument identifier true | A helper for defining constant strings. |
def tree(c):
ignore = ".git|*.pyc|*.swp|dist|*.egg-info|_static|_build|_templates"
c.run('tree -Ca -I "{0}" {1}'.format(ignore, c.sphinx.source)) | module function_definition identifier parameters identifier block expression_statement assignment identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier attribute attribute identifier identifier identifier | Display documentation contents with the 'tree' program. |
def delete(self, p_timestamp=None, p_write=True):
timestamp = p_timestamp or self.timestamp
index = self._get_index()
try:
del self.backup_dict[timestamp]
index.remove(index[[change[0] for change in index].index(timestamp)])
self._save_index(index)
if p_write:
self._write()
except KeyError:
pass | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier true block expression_statement assignment identifier boolean_operator identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list try_statement block delete_statement subscript attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list subscript identifier call attribute list_comprehension subscript identifier integer for_in_clause identifier identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier if_statement identifier block expression_statement call attribute identifier identifier argument_list except_clause identifier block pass_statement | Removes backup from the backup file. |
def replace(self, year=None, month=None, day=None):
if year is None:
year = self._year
if month is None:
month = self._month
if day is None:
day = self._day
_check_date_fields(year, month, day)
return date(year, month, day) | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier attribute identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier attribute identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier attribute identifier identifier expression_statement call identifier argument_list identifier identifier identifier return_statement call identifier argument_list identifier identifier identifier | Return a new date with new values for the specified fields. |
def _maybe_registered(self, failure, new_reg):
failure.trap(ServerError)
response = failure.value.response
if response.code == http.CONFLICT:
reg = new_reg.update(
resource=messages.UpdateRegistration.resource_type)
uri = self._maybe_location(response)
return self.update_registration(reg, uri=uri)
return failure | module function_definition identifier parameters identifier identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier attribute attribute identifier identifier identifier if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier attribute attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier keyword_argument identifier identifier return_statement identifier | If the registration already exists, we should just load it. |
def obtain(self):
self.check_destination()
url = self.url
cmd = ['clone', '--progress']
if self.git_shallow:
cmd.extend(['--depth', '1'])
if self.tls_verify:
cmd.extend(['-c', 'http.sslVerify=false'])
cmd.extend([url, self.path])
self.info('Cloning.')
self.run(cmd, log_in_real_time=True)
if self.remotes:
for r in self.remotes:
self.error('Adding remote %s <%s>' % (r['remote_name'], r['url']))
self.remote_set(name=r['remote_name'], url=r['url'])
self.info('Initializing submodules.')
self.run(['submodule', 'init'], log_in_real_time=True)
cmd = ['submodule', 'update', '--recursive', '--init']
cmd.extend(self.git_submodules)
self.run(cmd, log_in_real_time=True) | module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier list string string_start string_content string_end string string_start string_content string_end if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list list string string_start string_content string_end string string_start string_content string_end if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list list string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list list identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier keyword_argument identifier true if_statement attribute identifier identifier block for_statement identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list keyword_argument identifier subscript identifier string string_start string_content string_end keyword_argument identifier subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier true expression_statement assignment identifier list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier keyword_argument identifier true | Retrieve the repository, clone if doesn't exist. |
def _filter_attrs(attrs, ignored_attrs):
return dict((k, v) for k, v in attrs.items() if k not in ignored_attrs) | module function_definition identifier parameters identifier identifier block return_statement call identifier generator_expression tuple identifier identifier for_in_clause pattern_list identifier identifier call attribute identifier identifier argument_list if_clause comparison_operator identifier identifier | Return attrs that are not in ignored_attrs |
def paragraph(self, paragraph, prefix=""):
content = []
for text in paragraph.content:
content.append(self.text(text))
content = u"".join(content).encode("utf-8")
for line in content.split("\n"):
self.target.write(" " * self.indent)
self.target.write(prefix)
self.target.write(line)
self.target.write("\n")
if prefix:
prefix = " "
if any('url' in text.properties for text in paragraph.content):
self.target.write("\n")
for text in paragraph.content:
if 'url' in text.properties:
string = u"".join(text.content)
url = text.properties['url']
self.target.write(".. _%s: %s\n" % (string, url)) | module function_definition identifier parameters identifier identifier default_parameter identifier string string_start string_end block expression_statement assignment identifier list for_statement identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute call attribute string string_start string_end identifier argument_list identifier identifier argument_list string string_start string_content string_end for_statement identifier call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content escape_sequence string_end if_statement identifier block expression_statement assignment identifier string string_start string_content string_end if_statement call identifier generator_expression comparison_operator string string_start string_content string_end attribute identifier identifier for_in_clause identifier attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content escape_sequence string_end for_statement identifier attribute identifier identifier block if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement assignment identifier call attribute string string_start string_end identifier argument_list attribute identifier identifier expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content escape_sequence string_end tuple identifier identifier | process a pyth paragraph into the target |
def named_series(self, ordering=None):
series = self.series()
if ordering:
series = list(series)
todo = dict(((n, idx) for idx, n in enumerate(self.names())))
for name in ordering:
if name in todo:
idx = todo.pop(name)
yield name, series[idx]
for name in todo:
idx = todo[name]
yield name, series[idx]
else:
for name_serie in zip(self.names(), series):
yield name_serie | module function_definition identifier parameters identifier default_parameter identifier none block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list generator_expression tuple identifier identifier for_in_clause pattern_list identifier identifier call identifier argument_list call attribute identifier identifier argument_list for_statement identifier identifier block if_statement comparison_operator identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement yield expression_list identifier subscript identifier identifier for_statement identifier identifier block expression_statement assignment identifier subscript identifier identifier expression_statement yield expression_list identifier subscript identifier identifier else_clause block for_statement identifier call identifier argument_list call attribute identifier identifier argument_list identifier block expression_statement yield identifier | Generator of tuples with name and serie data. |
def add_current_text_if_valid(self):
valid = self.is_valid(self.currentText())
if valid or valid is None:
self.add_current_text()
return True
else:
self.set_current_text(self.selected_text) | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list if_statement boolean_operator identifier comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list return_statement true else_clause block expression_statement call attribute identifier identifier argument_list attribute identifier identifier | Add current text to combo box history if valid |
def getSkeletalBoneData(self, action, eTransformSpace, eMotionRange, unTransformArrayCount):
fn = self.function_table.getSkeletalBoneData
pTransformArray = VRBoneTransform_t()
result = fn(action, eTransformSpace, eMotionRange, byref(pTransformArray), unTransformArrayCount)
return result, pTransformArray | module function_definition identifier parameters identifier identifier identifier identifier identifier block expression_statement assignment identifier attribute attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call identifier argument_list identifier identifier identifier call identifier argument_list identifier identifier return_statement expression_list identifier identifier | Reads the state of the skeletal bone data associated with this action and copies it into the given buffer. |
def _calc_sampleset(w1, w2, step, minimal):
if minimal:
arr = [w1 - step, w1, w2, w2 + step]
else:
arr = np.arange(w1 - step, w2 + step + step, step)
return arr | module function_definition identifier parameters identifier identifier identifier identifier block if_statement identifier block expression_statement assignment identifier list binary_operator identifier identifier identifier identifier binary_operator identifier identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator identifier identifier binary_operator binary_operator identifier identifier identifier identifier return_statement identifier | Calculate sampleset for each model. |
def select(self, html, stype, expression):
etree = html5lib.parse(html,
treebuilder='lxml',
namespaceHTMLElements=False)
if stype == 'css':
selector = lxml.cssselect.CSSSelector(expression)
frag = list(selector(etree))
else:
frag = etree.xpath(expression)
if not frag:
raise RuntimeError("Nothing found for: %s" % expression)
return "".join([lxml.etree.tostring(x) for x in frag]) | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier false if_statement comparison_operator identifier string string_start string_content string_end block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement not_operator identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier return_statement call attribute string string_start string_end identifier argument_list list_comprehension call attribute attribute identifier identifier identifier argument_list identifier for_in_clause identifier identifier | returns WHATWG spec HTML fragment from selector expression. |
def pauli_sum(*elements: Pauli) -> Pauli:
terms = []
key = itemgetter(0)
for term, grp in groupby(heapq.merge(*elements, key=key), key=key):
coeff = sum(g[1] for g in grp)
if not isclose(coeff, 0.0):
terms.append((term, coeff))
return Pauli(tuple(terms)) | module function_definition identifier parameters typed_parameter list_splat_pattern identifier type identifier type identifier block expression_statement assignment identifier list expression_statement assignment identifier call identifier argument_list integer for_statement pattern_list identifier identifier call identifier argument_list call attribute identifier identifier argument_list list_splat identifier keyword_argument identifier identifier keyword_argument identifier identifier block expression_statement assignment identifier call identifier generator_expression subscript identifier integer for_in_clause identifier identifier if_statement not_operator call identifier argument_list identifier float block expression_statement call attribute identifier identifier argument_list tuple identifier identifier return_statement call identifier argument_list call identifier argument_list identifier | Return the sum of elements of the Pauli algebra |
def QueueDeleteTasks(self, queue, tasks):
predicates = []
for task in tasks:
task_id = getattr(task, "task_id", None) or int(task)
predicates.append(DataStore.QueueTaskIdToColumn(task_id))
self.DeleteAttributes(queue, predicates) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier list for_statement identifier identifier block expression_statement assignment identifier boolean_operator call identifier argument_list identifier string string_start string_content string_end none call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier identifier | Removes the given tasks from the queue. |
def find(self, tagtype, **kwargs):
for t in self.__tags:
if t.tagtype == tagtype:
return t
if 'default' in kwargs:
return kwargs['default']
else:
raise LookupError("Token {} is not tagged with the speficied tagtype ({})".format(self, tagtype)) | module function_definition identifier parameters identifier identifier dictionary_splat_pattern identifier block for_statement identifier attribute identifier identifier block if_statement comparison_operator attribute identifier identifier identifier block return_statement identifier if_statement comparison_operator string string_start string_content string_end identifier block return_statement subscript identifier string string_start string_content string_end else_clause block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier | Get the first tag with a type in this token |
def print_entitlements(opts, data, page_info=None, show_list_info=True):
if utils.maybe_print_as_json(opts, data, page_info):
return
headers = ["Name", "Token", "Created / Updated", "Identifier"]
rows = []
for entitlement in sorted(data, key=itemgetter("name")):
rows.append(
[
click.style(
"%(name)s (%(type)s)"
% {
"name": click.style(entitlement["name"], fg="cyan"),
"type": "user" if entitlement["user"] else "token",
}
),
click.style(entitlement["token"], fg="yellow"),
click.style(entitlement["updated_at"], fg="blue"),
click.style(entitlement["slug_perm"], fg="green"),
]
)
if data:
click.echo()
utils.pretty_print_table(headers, rows)
if not show_list_info:
return
click.echo()
num_results = len(data)
list_suffix = "entitlement%s" % ("s" if num_results != 1 else "")
utils.pretty_print_list_info(num_results=num_results, suffix=list_suffix) | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier true block if_statement call attribute identifier identifier argument_list identifier identifier identifier block return_statement expression_statement assignment identifier list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier list for_statement identifier call identifier argument_list identifier keyword_argument identifier call identifier argument_list string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list list call attribute identifier identifier argument_list binary_operator string string_start string_content string_end dictionary pair string string_start string_content string_end call attribute identifier identifier argument_list subscript identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end pair string string_start string_content string_end conditional_expression string string_start string_content string_end subscript identifier string string_start string_content string_end string string_start string_content string_end call attribute identifier identifier argument_list subscript identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end call attribute identifier identifier argument_list subscript identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end call attribute identifier identifier argument_list subscript identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end if_statement identifier block expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier identifier if_statement not_operator identifier block return_statement expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier binary_operator string string_start string_content string_end parenthesized_expression conditional_expression string string_start string_content string_end comparison_operator identifier integer string string_start string_end expression_statement call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | Print entitlements as a table or output in another format. |
def push(item, remote_addr, trg_queue, protocol=u'jsonrpc'):
if protocol == u'jsonrpc':
try:
server = Server(remote_addr, encoding=_c.FSQ_CHARSET)
return server.enqueue(item.id, trg_queue, item.item.read())
except Exception, e:
raise FSQPushError(e)
raise ValueError('Unknown protocol: {0}'.format(protocol)) | module function_definition identifier parameters identifier identifier identifier default_parameter identifier string string_start string_content string_end block if_statement comparison_operator identifier string string_start string_content string_end block try_statement block expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier attribute identifier identifier return_statement call attribute identifier identifier argument_list attribute identifier identifier identifier call attribute attribute identifier identifier identifier argument_list except_clause identifier identifier block raise_statement call identifier argument_list identifier raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier | Enqueue an FSQWorkItem at a remote queue |
def delete(self, filepath):
Filewatcher.remove_directory_to_watch(filepath)
self.write({'msg':'Watcher deleted for {}'.format(filepath)}) | module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end call attribute string string_start string_content string_end identifier argument_list identifier | Stop and delete the specified filewatcher. |
def do_tagg(self, arglist: List[str]):
if len(arglist) >= 2:
tag = arglist[0]
content = arglist[1:]
self.poutput('<{0}>{1}</{0}>'.format(tag, ' '.join(content)))
else:
self.perror("tagg requires at least 2 arguments") | module function_definition identifier parameters identifier typed_parameter identifier type generic_type identifier type_parameter type identifier block if_statement comparison_operator call identifier argument_list identifier integer block expression_statement assignment identifier subscript identifier integer expression_statement assignment identifier subscript identifier slice integer expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier call attribute string string_start string_content string_end identifier argument_list identifier else_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end | version of creating an html tag using arglist instead of argparser |
def load_default_model_sentencizer(lang):
loading_start = time.time()
lang_class = get_lang_class(lang)
nlp = lang_class()
nlp.add_pipe(nlp.create_pipe('sentencizer'))
loading_end = time.time()
loading_time = loading_end - loading_start
return nlp, loading_time, lang + "_default_" + 'sentencizer' | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier binary_operator identifier identifier return_statement expression_list identifier identifier binary_operator binary_operator identifier string string_start string_content string_end string string_start string_content string_end | Load a generic spaCy model and add the sentencizer for sentence tokenization |
def close(self):
self._execute_plugin_hooks_sync(hook='close')
if not self.session.closed:
ensure_future(self.session.close(), loop=self.loop) | module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list keyword_argument identifier string string_start string_content string_end if_statement not_operator attribute attribute identifier identifier identifier block expression_statement call identifier argument_list call attribute attribute identifier identifier identifier argument_list keyword_argument identifier attribute identifier identifier | Close service client and its plugins. |
def resolve(self, var, context):
if var is None:
return var
if var[0] in ('"', "'") and var[-1] == var[0]:
return var[1:-1]
else:
return template.Variable(var).resolve(context) | module function_definition identifier parameters identifier identifier identifier block if_statement comparison_operator identifier none block return_statement identifier if_statement boolean_operator comparison_operator subscript identifier integer tuple string string_start string_content string_end string string_start string_content string_end comparison_operator subscript identifier unary_operator integer subscript identifier integer block return_statement subscript identifier slice integer unary_operator integer else_clause block return_statement call attribute call attribute identifier identifier argument_list identifier identifier argument_list identifier | Resolves a variable out of context if it's not in quotes |
def select(self, *itms):
if not itms:
itms = ['*']
self.terms.append("select %s from %s" % (', '.join(itms), self.table))
return self | module function_definition identifier parameters identifier list_splat_pattern identifier block if_statement not_operator identifier block expression_statement assignment identifier list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end tuple call attribute string string_start string_content string_end identifier argument_list identifier attribute identifier identifier return_statement identifier | Joins the items to be selected and inserts the current table name |
def retry_func_accept_retry_state(retry_func):
if not six.callable(retry_func):
return retry_func
if func_takes_retry_state(retry_func):
return retry_func
@_utils.wraps(retry_func)
def wrapped_retry_func(retry_state):
warn_about_non_retry_state_deprecation(
'retry', retry_func, stacklevel=4)
return retry_func(retry_state.outcome)
return wrapped_retry_func | module function_definition identifier parameters identifier block if_statement not_operator call attribute identifier identifier argument_list identifier block return_statement identifier if_statement call identifier argument_list identifier block return_statement identifier decorated_definition decorator call attribute identifier identifier argument_list identifier function_definition identifier parameters identifier block expression_statement call identifier argument_list string string_start string_content string_end identifier keyword_argument identifier integer return_statement call identifier argument_list attribute identifier identifier return_statement identifier | Wrap "retry" function to accept "retry_state" parameter. |
def remove_redundant_items(items):
result = []
for item in items:
for other in items:
if item is not other and is_redundant_union_item(item, other):
break
else:
result.append(item)
return result | module function_definition identifier parameters identifier block expression_statement assignment identifier list for_statement identifier identifier block for_statement identifier identifier block if_statement boolean_operator comparison_operator identifier identifier call identifier argument_list identifier identifier block break_statement else_clause block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Filter out redundant union items. |
def embedded_preview(src_path):
try:
assert(exists(src_path) and isdir(src_path))
preview_list = glob(join(src_path, '[Q|q]uicklook', '[P|p]review.*'))
assert(preview_list)
preview_path = preview_list[0]
with NamedTemporaryFile(prefix='pyglass', suffix=extension(preview_path), delete=False) as tempfileobj:
dest_path = tempfileobj.name
shutil.copy(preview_path, dest_path)
assert(exists(dest_path))
return dest_path
except:
return None | module function_definition identifier parameters identifier block try_statement block assert_statement parenthesized_expression boolean_operator call identifier argument_list identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier string string_start string_content string_end string string_start string_content string_end assert_statement parenthesized_expression identifier expression_statement assignment identifier subscript identifier integer with_statement with_clause with_item as_pattern call identifier argument_list keyword_argument identifier string string_start string_content string_end keyword_argument identifier call identifier argument_list identifier keyword_argument identifier false as_pattern_target identifier block expression_statement assignment identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier identifier assert_statement parenthesized_expression call identifier argument_list identifier return_statement identifier except_clause block return_statement none | Returns path to temporary copy of embedded QuickLook preview, if it exists |
def _create_slice(self, key):
if isinstance(key, slice):
step = key.step
if step is None:
step = 1
if step != 1:
raise ArgumentError("You cannot slice with a step that is not equal to 1", step=key.step)
start_address = key.start
end_address = key.stop - 1
start_i, start_seg = self._find_address(start_address)
end_i, _end_seg = self._find_address(end_address)
if start_seg is None or start_i != end_i:
raise ArgumentError("Slice would span invalid data in memory",
start_address=start_address, end_address=end_address)
block_offset = start_address - start_seg.start_address
block_length = end_address - start_address + 1
return start_seg, block_offset, block_offset + block_length
elif isinstance(key, int):
start_i, start_seg = self._find_address(key)
if start_seg is None:
raise ArgumentError("Requested invalid address", address=key)
return start_seg, key - start_seg.start_address, None
else:
raise ArgumentError("Unknown type of address key", address=key) | module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier attribute identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier integer if_statement comparison_operator identifier integer block raise_statement call identifier argument_list string string_start string_content string_end keyword_argument identifier attribute identifier identifier expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier binary_operator attribute identifier identifier integer expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list identifier expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list identifier if_statement boolean_operator comparison_operator identifier none comparison_operator identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end keyword_argument identifier identifier keyword_argument identifier identifier expression_statement assignment identifier binary_operator identifier attribute identifier identifier expression_statement assignment identifier binary_operator binary_operator identifier identifier integer return_statement expression_list identifier identifier binary_operator identifier identifier elif_clause call identifier argument_list identifier identifier block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator identifier none block raise_statement call identifier argument_list string string_start string_content string_end keyword_argument identifier identifier return_statement expression_list identifier binary_operator identifier attribute identifier identifier none else_clause block raise_statement call identifier argument_list string string_start string_content string_end keyword_argument identifier identifier | Create a slice in a memory segment corresponding to a key. |
def subset_bam_by_region(in_file, region, config, out_file_base=None):
if out_file_base is not None:
base, ext = os.path.splitext(out_file_base)
else:
base, ext = os.path.splitext(in_file)
out_file = "%s-subset%s%s" % (base, region, ext)
if not file_exists(out_file):
with pysam.Samfile(in_file, "rb") as in_bam:
target_tid = in_bam.gettid(region)
assert region is not None, \
"Did not find reference region %s in %s" % \
(region, in_file)
with file_transaction(config, out_file) as tx_out_file:
with pysam.Samfile(tx_out_file, "wb", template=in_bam) as out_bam:
for read in in_bam:
if read.tid == target_tid:
out_bam.write(read)
return out_file | module function_definition identifier parameters identifier identifier identifier default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list identifier else_clause block expression_statement assignment pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier binary_operator string string_start string_content string_end tuple identifier identifier identifier if_statement not_operator call identifier argument_list identifier block with_statement with_clause with_item as_pattern call attribute identifier identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier assert_statement comparison_operator identifier none binary_operator string string_start string_content string_end line_continuation tuple identifier identifier with_statement with_clause with_item as_pattern call identifier argument_list identifier identifier as_pattern_target identifier block with_statement with_clause with_item as_pattern call attribute identifier identifier argument_list identifier string string_start string_content string_end keyword_argument identifier identifier as_pattern_target identifier block for_statement identifier identifier block if_statement comparison_operator attribute identifier identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Subset BAM files based on specified chromosome region. |
def _pnorm_diagweight(x, p, w):
order = 'F' if all(a.flags.f_contiguous for a in (x.data, w)) else 'C'
xp = np.abs(x.data.ravel(order))
if p == float('inf'):
xp *= w.ravel(order)
return np.max(xp)
else:
xp = np.power(xp, p, out=xp)
xp *= w.ravel(order)
return np.sum(xp) ** (1 / p) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier conditional_expression string string_start string_content string_end call identifier generator_expression attribute attribute identifier identifier identifier for_in_clause identifier tuple attribute identifier identifier identifier string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier if_statement comparison_operator identifier call identifier argument_list string string_start string_content string_end block expression_statement augmented_assignment identifier call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier keyword_argument identifier identifier expression_statement augmented_assignment identifier call attribute identifier identifier argument_list identifier return_statement binary_operator call attribute identifier identifier argument_list identifier parenthesized_expression binary_operator integer identifier | Diagonally weighted p-norm implementation. |
def _analyse_overview_field(content):
if "(" in content:
return content.split("(")[0], content.split("(")[0]
elif "/" in content:
return content.split("/")[0], content.split("/")[1]
return content, "" | module function_definition identifier parameters identifier block if_statement comparison_operator string string_start string_content string_end identifier block return_statement expression_list subscript call attribute identifier identifier argument_list string string_start string_content string_end integer subscript call attribute identifier identifier argument_list string string_start string_content string_end integer elif_clause comparison_operator string string_start string_content string_end identifier block return_statement expression_list subscript call attribute identifier identifier argument_list string string_start string_content string_end integer subscript call attribute identifier identifier argument_list string string_start string_content string_end integer return_statement expression_list identifier string string_start string_end | Split the field in drbd-overview |
def getfnc_qual_ev(self):
fnc_key = (
self.nd_not2desc[(self._keep_nd, self._keep_not)],
self.incexc2num[(
self.include_evcodes is not None,
self.exclude_evcodes is not None)],
)
return self.param2fnc[fnc_key] | module function_definition identifier parameters identifier block expression_statement assignment identifier tuple subscript attribute identifier identifier tuple attribute identifier identifier attribute identifier identifier subscript attribute identifier identifier tuple comparison_operator attribute identifier identifier none comparison_operator attribute identifier identifier none return_statement subscript attribute identifier identifier identifier | Keep annotaion if it passes potentially modified selection. |
def convert_path(cls, file):
if isinstance(file,str):
return file
elif isinstance(file, list) and all([isinstance(x, str) for x in file]):
return "/".join(file)
else:
print("Incorrect path specified")
return -1 | module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block return_statement identifier elif_clause boolean_operator call identifier argument_list identifier identifier call identifier argument_list list_comprehension call identifier argument_list identifier identifier for_in_clause identifier identifier block return_statement call attribute string string_start string_content string_end identifier argument_list identifier else_clause block expression_statement call identifier argument_list string string_start string_content string_end return_statement unary_operator integer | Check to see if an extended path is given and convert appropriately |
def count_replica(self, partition):
return sum(1 for b in partition.replicas if b in self.brokers) | module function_definition identifier parameters identifier identifier block return_statement call identifier generator_expression integer for_in_clause identifier attribute identifier identifier if_clause comparison_operator identifier attribute identifier identifier | Return count of replicas of given partition. |
def _params(sig):
params = []
for p in sig.parameters:
param = sig.parameters[p]
optional = param.default != inspect.Signature.empty
default = UIBuilder._safe_default(param.default) if param.default != inspect.Signature.empty else ''
annotation = param.annotation if param.annotation != inspect.Signature.empty else ''
type = UIBuilder._guess_type(default)
p_attr = {
"name": param.name,
"label": param.name,
"optional": optional,
"default": default,
"description": annotation,
"hide": False,
"type": type,
"kinds": None,
"choices": [],
"id": None,
"events": None
}
if isinstance(default, bool):
p_attr['choices'] = {
'True': 'true',
'False': 'false'
}
params.append(p_attr)
return params | module function_definition identifier parameters identifier block expression_statement assignment identifier list for_statement identifier attribute identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier identifier expression_statement assignment identifier comparison_operator attribute identifier identifier attribute attribute identifier identifier identifier expression_statement assignment identifier conditional_expression call attribute identifier identifier argument_list attribute identifier identifier comparison_operator attribute identifier identifier attribute attribute identifier identifier identifier string string_start string_end expression_statement assignment identifier conditional_expression attribute identifier identifier comparison_operator attribute identifier identifier attribute attribute identifier identifier identifier string string_start string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end false pair string string_start string_content string_end identifier pair string string_start string_content string_end none pair string string_start string_content string_end list pair string string_start string_content string_end none pair string string_start string_content string_end none if_statement call identifier argument_list identifier identifier block expression_statement assignment subscript identifier string string_start string_content string_end dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Read params, values and annotations from the signature |
def _messageFromSender(self, sender, messageID):
return self.store.findUnique(
_QueuedMessage,
AND(_QueuedMessage.senderUsername == sender.localpart,
_QueuedMessage.senderDomain == sender.domain,
_QueuedMessage.messageID == messageID),
default=None) | module function_definition identifier parameters identifier identifier identifier block return_statement call attribute attribute identifier identifier identifier argument_list identifier call identifier argument_list comparison_operator attribute identifier identifier attribute identifier identifier comparison_operator attribute identifier identifier attribute identifier identifier comparison_operator attribute identifier identifier identifier keyword_argument identifier none | Locate a previously queued message by a given sender and messageID. |
def _handle_actiondefinefunction(self, _):
obj = _make_object("ActionDefineFunction")
obj.FunctionName = self._get_struct_string()
obj.NumParams = unpack_ui16(self._src)
for i in range(1, obj.NumParams + 1):
setattr(obj, "param" + str(i), self._get_struct_string())
obj.CodeSize = unpack_ui16(self._src)
yield obj | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier for_statement identifier call identifier argument_list integer binary_operator attribute identifier identifier integer block expression_statement call identifier argument_list identifier binary_operator string string_start string_content string_end call identifier argument_list identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier expression_statement yield identifier | Handle the ActionDefineFunction action. |
def parse_description(s):
s = "".join(s.split()[1:]).replace("/", ";")
a = parse_qs(s)
return a | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute call attribute string string_start string_end identifier argument_list subscript call attribute identifier identifier argument_list slice integer identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier return_statement identifier | Returns a dictionary based on the FASTA header, assuming JCVI data |
def parse_cg(self):
line = self.readline()
while self._cg_header_re.match(line):
line = self.readline()
entry_lines = []
while not self._cg_footer_re.match(line):
if line.isspace():
self.parse_cg_entry(entry_lines)
entry_lines = []
else:
entry_lines.append(line)
line = self.readline() | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list while_statement call attribute attribute identifier identifier identifier argument_list identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier list while_statement not_operator call attribute attribute identifier identifier identifier argument_list identifier block if_statement call attribute identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier list else_clause block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list | Parse the call graph. |
def parse_from_parent(
self,
parent,
state
):
xml_value = self._processor.parse_from_parent(parent, state)
return _hooks_apply_after_parse(self._hooks, state, xml_value) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier return_statement call identifier argument_list attribute identifier identifier identifier identifier | Parse the element from the given parent element. |
def download_directory(self, bucket, key, directory, transfer_config=None, subscribers=None):
check_io_access(directory, os.W_OK)
return self._queue_task(bucket, [FilePair(key, directory)], transfer_config,
subscribers, enumAsperaDirection.RECEIVE) | module function_definition identifier parameters identifier identifier identifier identifier default_parameter identifier none default_parameter identifier none block expression_statement call identifier argument_list identifier attribute identifier identifier return_statement call attribute identifier identifier argument_list identifier list call identifier argument_list identifier identifier identifier identifier attribute identifier identifier | download a directory using Aspera |
def remove_user(self, user):
org_user = self._org_user_model.objects.get(user=user, organization=self)
org_user.delete()
user_removed.send(sender=self, user=user) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | Deletes a user from an organization. |
def _writeReplacementFiles(self, session, directory, name):
if self.replaceParamFile:
self.replaceParamFile.write(session=session, directory=directory,
name=name)
if self.replaceValFile:
self.replaceValFile.write(session=session, directory=directory,
name=name) | module function_definition identifier parameters identifier identifier identifier identifier block if_statement attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier if_statement attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier | Write the replacement files |
def import_dashboards(self):
f = request.files.get('file')
if request.method == 'POST' and f:
dashboard_import_export.import_dashboards(db.session, f.stream)
return redirect('/dashboard/list/')
return self.render_template('superset/import_dashboards.html') | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator comparison_operator attribute identifier identifier string string_start string_content string_end identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier return_statement call identifier argument_list string string_start string_content string_end return_statement call attribute identifier identifier argument_list string string_start string_content string_end | Overrides the dashboards using json instances from the file. |
def _get_removed(self):
removed, packages = [], []
if "--tag" in self.extra:
for pkg in find_package("", self.meta.pkg_path):
for tag in self.binary:
if pkg.endswith(tag):
removed.append(split_package(pkg)[0])
packages.append(pkg)
if not removed:
self.msg.pkg_not_found("", "'tag'", "Can't remove", "\n")
raise SystemExit(1)
else:
for pkg in self.binary:
name = GetFromInstalled(pkg).name()
ver = GetFromInstalled(pkg).version()
package = find_package("{0}{1}{2}".format(
name, ver, self.meta.sp), self.meta.pkg_path)
if pkg and name == pkg:
removed.append(pkg)
packages.append(package[0])
else:
self.msg.pkg_not_found("", pkg, "Can't remove", "\n")
raise SystemExit(1)
return removed, packages | module function_definition identifier parameters identifier block expression_statement assignment pattern_list identifier identifier expression_list list list if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block for_statement identifier call identifier argument_list string string_start string_end attribute attribute identifier identifier identifier block for_statement identifier attribute identifier identifier block if_statement call attribute identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list subscript call identifier argument_list identifier integer expression_statement call attribute identifier identifier argument_list identifier if_statement not_operator identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content escape_sequence string_end raise_statement call identifier argument_list integer else_clause block for_statement identifier attribute identifier identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier identifier argument_list expression_statement assignment identifier call attribute call identifier argument_list identifier identifier argument_list expression_statement assignment identifier call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier if_statement boolean_operator identifier comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list subscript identifier integer else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_end identifier string string_start string_content string_end string string_start string_content escape_sequence string_end raise_statement call identifier argument_list integer return_statement expression_list identifier identifier | Manage removed packages by extra options |
def get(key, section='main'):
return nago.settings.get_option(option_name=key, section_name=section) | module function_definition identifier parameters identifier default_parameter identifier string string_start string_content string_end block return_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | Get a single option from |
def path(self):
names = []
obj = self
while obj:
names.insert(0, obj.name)
obj = obj.parent_dir
sep = self.filesystem._path_separator(self.name)
if names[0] == sep:
names.pop(0)
dir_path = sep.join(names)
is_drive = names and len(names[0]) == 2 and names[0][1] == ':'
if not is_drive:
dir_path = sep + dir_path
else:
dir_path = sep.join(names)
dir_path = self.filesystem.absnormpath(dir_path)
return dir_path | module function_definition identifier parameters identifier block expression_statement assignment identifier list expression_statement assignment identifier identifier while_statement identifier block expression_statement call attribute identifier identifier argument_list integer attribute identifier identifier expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement comparison_operator subscript identifier integer identifier block expression_statement call attribute identifier identifier argument_list integer expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier boolean_operator boolean_operator identifier comparison_operator call identifier argument_list subscript identifier integer integer comparison_operator subscript subscript identifier integer integer string string_start string_content string_end if_statement not_operator identifier block expression_statement assignment identifier binary_operator identifier identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement identifier | Return the full path of the current object. |
def _clone(self, *args, **kwargs):
for attr in ("_search_terms", "_search_fields", "_search_ordered"):
kwargs[attr] = getattr(self, attr)
return super(SearchableQuerySet, self)._clone(*args, **kwargs) | module function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block for_statement identifier tuple string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end block expression_statement assignment subscript identifier identifier call identifier argument_list identifier identifier return_statement call attribute call identifier argument_list identifier identifier identifier argument_list list_splat identifier dictionary_splat identifier | Ensure attributes are copied to subsequent queries. |
def db_value(self, value):
if isinstance(value, string_types):
value = arrow.get(value)
if isinstance(value, arrow.Arrow):
value = value.datetime
return super(ArrowDateTimeField, self).db_value(value) | module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement call identifier argument_list identifier attribute identifier identifier block expression_statement assignment identifier attribute identifier identifier return_statement call attribute call identifier argument_list identifier identifier identifier argument_list identifier | Convert the Arrow instance to a datetime for saving in the db. |
def total(self, xbin1=1, xbin2=-2):
return self.hist.integral(xbin1=xbin1, xbin2=xbin2, error=True) | module function_definition identifier parameters identifier default_parameter identifier integer default_parameter identifier unary_operator integer block return_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier true | Return the total yield and its associated statistical uncertainty. |
def parse_band_set_name(self, message):
if message.get("name"):
self._service_name = message["name"]
else:
self.log.warning(
"Received broken record on set_name band\nMessage: %s", str(message)
) | module function_definition identifier parameters identifier identifier block if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment attribute identifier identifier subscript identifier string string_start string_content string_end else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content escape_sequence string_end call identifier argument_list identifier | Process incoming message indicating service name change. |
def store(bank, key, data, cachedir):
base = os.path.join(cachedir, os.path.normpath(bank))
try:
os.makedirs(base)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise SaltCacheError(
'The cache directory, {0}, could not be created: {1}'.format(
base, exc
)
)
outfile = os.path.join(base, '{0}.p'.format(key))
tmpfh, tmpfname = tempfile.mkstemp(dir=base)
os.close(tmpfh)
try:
with salt.utils.files.fopen(tmpfname, 'w+b') as fh_:
fh_.write(__context__['serial'].dumps(data))
salt.utils.atomicfile.atomic_rename(tmpfname, outfile)
except IOError as exc:
raise SaltCacheError(
'There was an error writing the cache file, {0}: {1}'.format(
base, exc
)
) | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier call attribute attribute identifier identifier identifier argument_list identifier try_statement block expression_statement call attribute identifier identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier call attribute string string_start string_content string_end identifier argument_list identifier expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list keyword_argument identifier identifier expression_statement call attribute identifier identifier argument_list identifier try_statement block with_statement with_clause with_item as_pattern call attribute attribute attribute identifier identifier identifier identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list call attribute subscript identifier string string_start string_content string_end identifier argument_list identifier expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier identifier except_clause as_pattern identifier as_pattern_target identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier | Store information in a file. |
def parse_timestamp(timestamp):
dt = dateutil.parser.parse(timestamp)
return dt.astimezone(dateutil.tz.tzutc()) | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list | Parse ISO8601 timestamps given by github API. |
def _call(self, x, out=None):
if out is None:
out = self.range.zero()
for i, j, op in zip(self.ops.row, self.ops.col, self.ops.data):
out[i] += op(x[j])
else:
has_evaluated_row = np.zeros(len(self.range), dtype=bool)
for i, j, op in zip(self.ops.row, self.ops.col, self.ops.data):
if not has_evaluated_row[i]:
op(x[j], out=out[i])
else:
out[i] += op(x[j])
has_evaluated_row[i] = True
for i, evaluated in enumerate(has_evaluated_row):
if not evaluated:
out[i].set_zero()
return out | module function_definition identifier parameters identifier identifier default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list for_statement pattern_list identifier identifier identifier call identifier argument_list attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier block expression_statement augmented_assignment subscript identifier identifier call identifier argument_list subscript identifier identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list attribute identifier identifier keyword_argument identifier identifier for_statement pattern_list identifier identifier identifier call identifier argument_list attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier block if_statement not_operator subscript identifier identifier block expression_statement call identifier argument_list subscript identifier identifier keyword_argument identifier subscript identifier identifier else_clause block expression_statement augmented_assignment subscript identifier identifier call identifier argument_list subscript identifier identifier expression_statement assignment subscript identifier identifier true for_statement pattern_list identifier identifier call identifier argument_list identifier block if_statement not_operator identifier block expression_statement call attribute subscript identifier identifier identifier argument_list return_statement identifier | Call the operators on the parts of ``x``. |
def add_device(self, resource_name, device):
if device.resource_name is not None:
msg = 'The device %r is already assigned to %s'
raise ValueError(msg % (device, device.resource_name))
device.resource_name = resource_name
self._internal[device.resource_name] = device | module function_definition identifier parameters identifier identifier identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement assignment identifier string string_start string_content string_end raise_statement call identifier argument_list binary_operator identifier tuple identifier attribute identifier identifier expression_statement assignment attribute identifier identifier identifier expression_statement assignment subscript attribute identifier identifier attribute identifier identifier identifier | Bind device to resource name |
def many(cls, filter=None, **kwargs):
from mongoframes.queries import Condition, Group, to_refs
kwargs['projection'], references, subs = \
cls._flatten_projection(
kwargs.get('projection', cls._default_projection)
)
if isinstance(filter, (Condition, Group)):
filter = filter.to_dict()
documents = list(cls.get_collection().find(to_refs(filter), **kwargs))
if references:
cls._dereference(documents, references)
if subs:
cls._apply_sub_frames(documents, subs)
return [cls(d) for d in documents] | module function_definition identifier parameters identifier default_parameter identifier none dictionary_splat_pattern identifier block import_from_statement dotted_name identifier identifier dotted_name identifier dotted_name identifier dotted_name identifier expression_statement assignment pattern_list subscript identifier string string_start string_content string_end identifier identifier line_continuation call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier if_statement call identifier argument_list identifier tuple identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list call attribute call attribute identifier identifier argument_list identifier argument_list call identifier argument_list identifier dictionary_splat identifier if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier identifier if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier identifier return_statement list_comprehension call identifier argument_list identifier for_in_clause identifier identifier | Return a list of documents matching the filter |
def status(context):
context.obj.find_repo_type()
context.obj.call([context.obj.vc_name, 'status']) | module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list list attribute attribute identifier identifier identifier string string_start string_content string_end | See which files have changed, checked in, and uploaded |
def promote(self, name):
return PartitionName(**dict(list(name.dict.items()) + list(self.dict.items()))) | module function_definition identifier parameters identifier identifier block return_statement call identifier argument_list dictionary_splat call identifier argument_list binary_operator call identifier argument_list call attribute attribute identifier identifier identifier argument_list call identifier argument_list call attribute attribute identifier identifier identifier argument_list | Promote to a PartitionName by combining with a bundle Name. |
def _run(*args, **kwargs):
verbose = kwargs.pop("verbose", False)
if verbose:
click.secho(" ".join([repr(i) for i in args]), bg='blue', fg='white')
executable = args[0]
if not os.path.isfile(executable):
raise RuntimeError("First argument %r is not a existing file!" % executable)
if not os.access(executable, os.X_OK):
raise RuntimeError("First argument %r exist, but is not executeable!" % executable)
return subprocess.Popen(args, **kwargs) | module function_definition identifier parameters list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end false if_statement identifier block expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list list_comprehension call identifier argument_list identifier for_in_clause identifier identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end expression_statement assignment identifier subscript identifier integer if_statement not_operator call attribute attribute identifier identifier identifier argument_list identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier if_statement not_operator call attribute identifier identifier argument_list identifier attribute identifier identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier return_statement call attribute identifier identifier argument_list identifier dictionary_splat identifier | Run current executable via subprocess and given args |
def _zip(self) -> ObjectValue:
res = ObjectValue(self.siblings.copy(), self.timestamp)
res[self.name] = self.value
return res | module function_definition identifier parameters identifier type identifier block expression_statement assignment identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement assignment subscript identifier attribute identifier identifier attribute identifier identifier return_statement identifier | Zip the receiver into an object and return it. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.