id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2,900 | ontio/ontology-python-sdk | ontology/smart_contract/native_contract/asset.py | Asset.new_withdraw_ong_transaction | def new_withdraw_ong_transaction(self, b58_claimer_address: str, b58_recv_address: str, amount: int,
b58_payer_address: str, gas_limit: int, gas_price: int) -> Transaction:
"""
This interface is used to generate a Transaction object that
allow one account to ... | python | def new_withdraw_ong_transaction(self, b58_claimer_address: str, b58_recv_address: str, amount: int,
b58_payer_address: str, gas_limit: int, gas_price: int) -> Transaction:
if not isinstance(b58_claimer_address, str) or not isinstance(b58_recv_address, str) or not isinstance... | [
"def",
"new_withdraw_ong_transaction",
"(",
"self",
",",
"b58_claimer_address",
":",
"str",
",",
"b58_recv_address",
":",
"str",
",",
"amount",
":",
"int",
",",
"b58_payer_address",
":",
"str",
",",
"gas_limit",
":",
"int",
",",
"gas_price",
":",
"int",
")",
... | This interface is used to generate a Transaction object that
allow one account to withdraw an amount of ong and transfer them to receive address.
:param b58_claimer_address: a base58 encode address which is used to indicate who is the claimer.
:param b58_recv_address: a base58 encode address wh... | [
"This",
"interface",
"is",
"used",
"to",
"generate",
"a",
"Transaction",
"object",
"that",
"allow",
"one",
"account",
"to",
"withdraw",
"an",
"amount",
"of",
"ong",
"and",
"transfer",
"them",
"to",
"receive",
"address",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/smart_contract/native_contract/asset.py#L226-L257 |
2,901 | ontio/ontology-python-sdk | ontology/smart_contract/native_contract/asset.py | Asset.transfer | def transfer(self, asset: str, from_acct: Account, b58_to_address: str, amount: int, payer: Account,
gas_limit: int, gas_price: int):
"""
This interface is used to send a transfer transaction that only for ONT or ONG.
:param asset: a string which is used to indicate which asset... | python | def transfer(self, asset: str, from_acct: Account, b58_to_address: str, amount: int, payer: Account,
gas_limit: int, gas_price: int):
tx = self.new_transfer_transaction(asset, from_acct.get_address_base58(), b58_to_address, amount,
payer.get_address_ba... | [
"def",
"transfer",
"(",
"self",
",",
"asset",
":",
"str",
",",
"from_acct",
":",
"Account",
",",
"b58_to_address",
":",
"str",
",",
"amount",
":",
"int",
",",
"payer",
":",
"Account",
",",
"gas_limit",
":",
"int",
",",
"gas_price",
":",
"int",
")",
"... | This interface is used to send a transfer transaction that only for ONT or ONG.
:param asset: a string which is used to indicate which asset we want to transfer.
:param from_acct: a Account object which indicate where the asset from.
:param b58_to_address: a base58 encode address which indicate... | [
"This",
"interface",
"is",
"used",
"to",
"send",
"a",
"transfer",
"transaction",
"that",
"only",
"for",
"ONT",
"or",
"ONG",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/smart_contract/native_contract/asset.py#L259-L278 |
2,902 | ontio/ontology-python-sdk | ontology/smart_contract/native_contract/asset.py | Asset.withdraw_ong | def withdraw_ong(self, claimer: Account, b58_recv_address: str, amount: int, payer: Account,
gas_limit: int, gas_price: int) -> str:
"""
This interface is used to withdraw a amount of ong and transfer them to receive address.
:param claimer: the owner of ong that remained t... | python | def withdraw_ong(self, claimer: Account, b58_recv_address: str, amount: int, payer: Account,
gas_limit: int, gas_price: int) -> str:
if claimer is None:
raise SDKException(ErrorCode.param_err('the claimer should not be None.'))
if payer is None:
raise SDKExce... | [
"def",
"withdraw_ong",
"(",
"self",
",",
"claimer",
":",
"Account",
",",
"b58_recv_address",
":",
"str",
",",
"amount",
":",
"int",
",",
"payer",
":",
"Account",
",",
"gas_limit",
":",
"int",
",",
"gas_price",
":",
"int",
")",
"->",
"str",
":",
"if",
... | This interface is used to withdraw a amount of ong and transfer them to receive address.
:param claimer: the owner of ong that remained to claim.
:param b58_recv_address: the address that received the ong.
:param amount: the amount of ong want to claim.
:param payer: an Account class th... | [
"This",
"interface",
"is",
"used",
"to",
"withdraw",
"a",
"amount",
"of",
"ong",
"and",
"transfer",
"them",
"to",
"receive",
"address",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/smart_contract/native_contract/asset.py#L280-L309 |
2,903 | ontio/ontology-python-sdk | ontology/smart_contract/native_contract/asset.py | Asset.approve | def approve(self, asset, sender: Account, b58_recv_address: str, amount: int, payer: Account, gas_limit: int,
gas_price: int) -> str:
"""
This is an interface used to send an approve transaction
which allow receiver to spend a amount of ONT or ONG asset in sender's account.
... | python | def approve(self, asset, sender: Account, b58_recv_address: str, amount: int, payer: Account, gas_limit: int,
gas_price: int) -> str:
if sender is None:
raise SDKException(ErrorCode.param_err('the sender should not be None.'))
if payer is None:
raise SDKException(... | [
"def",
"approve",
"(",
"self",
",",
"asset",
",",
"sender",
":",
"Account",
",",
"b58_recv_address",
":",
"str",
",",
"amount",
":",
"int",
",",
"payer",
":",
"Account",
",",
"gas_limit",
":",
"int",
",",
"gas_price",
":",
"int",
")",
"->",
"str",
":... | This is an interface used to send an approve transaction
which allow receiver to spend a amount of ONT or ONG asset in sender's account.
:param asset: a string which is used to indicate what asset we want to approve.
:param sender: an Account class that send the approve transaction.
:pa... | [
"This",
"is",
"an",
"interface",
"used",
"to",
"send",
"an",
"approve",
"transaction",
"which",
"allow",
"receiver",
"to",
"spend",
"a",
"amount",
"of",
"ONT",
"or",
"ONG",
"asset",
"in",
"sender",
"s",
"account",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/smart_contract/native_contract/asset.py#L311-L343 |
2,904 | ontio/ontology-python-sdk | ontology/wallet/wallet.py | WalletData.remove_account | def remove_account(self, address: str):
"""
This interface is used to remove account from WalletData.
:param address: a string address.
"""
account = self.get_account_by_b58_address(address)
if account is None:
raise SDKException(ErrorCode.get_account_by_addr... | python | def remove_account(self, address: str):
account = self.get_account_by_b58_address(address)
if account is None:
raise SDKException(ErrorCode.get_account_by_address_err)
self.accounts.remove(account) | [
"def",
"remove_account",
"(",
"self",
",",
"address",
":",
"str",
")",
":",
"account",
"=",
"self",
".",
"get_account_by_b58_address",
"(",
"address",
")",
"if",
"account",
"is",
"None",
":",
"raise",
"SDKException",
"(",
"ErrorCode",
".",
"get_account_by_addr... | This interface is used to remove account from WalletData.
:param address: a string address. | [
"This",
"interface",
"is",
"used",
"to",
"remove",
"account",
"from",
"WalletData",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/wallet/wallet.py#L101-L110 |
2,905 | ontio/ontology-python-sdk | ontology/wallet/wallet.py | WalletData.set_default_account_by_index | def set_default_account_by_index(self, index: int):
"""
This interface is used to set default account by given index.
:param index: an int value that indicate the account object in account list.
"""
if index >= len(self.accounts):
raise SDKException(ErrorCode.param_e... | python | def set_default_account_by_index(self, index: int):
if index >= len(self.accounts):
raise SDKException(ErrorCode.param_error)
for acct in self.accounts:
acct.is_default = False
self.accounts[index].is_default = True
self.default_account_address = self.accounts[ind... | [
"def",
"set_default_account_by_index",
"(",
"self",
",",
"index",
":",
"int",
")",
":",
"if",
"index",
">=",
"len",
"(",
"self",
".",
"accounts",
")",
":",
"raise",
"SDKException",
"(",
"ErrorCode",
".",
"param_error",
")",
"for",
"acct",
"in",
"self",
"... | This interface is used to set default account by given index.
:param index: an int value that indicate the account object in account list. | [
"This",
"interface",
"is",
"used",
"to",
"set",
"default",
"account",
"by",
"given",
"index",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/wallet/wallet.py#L120-L131 |
2,906 | ontio/ontology-python-sdk | ontology/wallet/wallet.py | WalletData.set_default_account_by_address | def set_default_account_by_address(self, b58_address: str):
"""
This interface is used to set default account by given base58 encode address.
:param b58_address: a base58 encode address.
"""
flag = True
index = -1
for acct in self.accounts:
index += 1... | python | def set_default_account_by_address(self, b58_address: str):
flag = True
index = -1
for acct in self.accounts:
index += 1
if acct.b58_address == b58_address:
flag = False
break
if flag:
raise SDKException(ErrorCode.get_ac... | [
"def",
"set_default_account_by_address",
"(",
"self",
",",
"b58_address",
":",
"str",
")",
":",
"flag",
"=",
"True",
"index",
"=",
"-",
"1",
"for",
"acct",
"in",
"self",
".",
"accounts",
":",
"index",
"+=",
"1",
"if",
"acct",
".",
"b58_address",
"==",
... | This interface is used to set default account by given base58 encode address.
:param b58_address: a base58 encode address. | [
"This",
"interface",
"is",
"used",
"to",
"set",
"default",
"account",
"by",
"given",
"base58",
"encode",
"address",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/wallet/wallet.py#L133-L151 |
2,907 | ontio/ontology-python-sdk | ontology/wallet/wallet.py | WalletData.set_default_identity_by_index | def set_default_identity_by_index(self, index: int):
"""
This interface is used to set default account by given an index value.
:param index: an int value that indicate the position of an account object in account list.
"""
identities_len = len(self.identities)
if index ... | python | def set_default_identity_by_index(self, index: int):
identities_len = len(self.identities)
if index >= identities_len:
raise SDKException(ErrorCode.param_error)
for i in range(identities_len):
self.identities[i].is_default = False
if i == index:
... | [
"def",
"set_default_identity_by_index",
"(",
"self",
",",
"index",
":",
"int",
")",
":",
"identities_len",
"=",
"len",
"(",
"self",
".",
"identities",
")",
"if",
"index",
">=",
"identities_len",
":",
"raise",
"SDKException",
"(",
"ErrorCode",
".",
"param_error... | This interface is used to set default account by given an index value.
:param index: an int value that indicate the position of an account object in account list. | [
"This",
"interface",
"is",
"used",
"to",
"set",
"default",
"account",
"by",
"given",
"an",
"index",
"value",
"."
] | ac88bdda941896c5d2ced08422a9c5179d3f9b19 | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/wallet/wallet.py#L230-L242 |
2,908 | openvax/gtfparse | gtfparse/read_gtf.py | read_gtf | def read_gtf(
filepath_or_buffer,
expand_attribute_column=True,
infer_biotype_column=False,
column_converters={},
usecols=None,
features=None,
chunksize=1024 * 1024):
"""
Parse a GTF into a dictionary mapping column names to sequences of values.
Param... | python | def read_gtf(
filepath_or_buffer,
expand_attribute_column=True,
infer_biotype_column=False,
column_converters={},
usecols=None,
features=None,
chunksize=1024 * 1024):
if isinstance(filepath_or_buffer, string_types) and not exists(filepath_or_buffer):
r... | [
"def",
"read_gtf",
"(",
"filepath_or_buffer",
",",
"expand_attribute_column",
"=",
"True",
",",
"infer_biotype_column",
"=",
"False",
",",
"column_converters",
"=",
"{",
"}",
",",
"usecols",
"=",
"None",
",",
"features",
"=",
"None",
",",
"chunksize",
"=",
"10... | Parse a GTF into a dictionary mapping column names to sequences of values.
Parameters
----------
filepath_or_buffer : str or buffer object
Path to GTF file (may be gzip compressed) or buffer object
such as StringIO
expand_attribute_column : bool
Replace strings of semi-colon se... | [
"Parse",
"a",
"GTF",
"into",
"a",
"dictionary",
"mapping",
"column",
"names",
"to",
"sequences",
"of",
"values",
"."
] | c79cab0c2a5ac3d08de9f932fa29a56d334a712b | https://github.com/openvax/gtfparse/blob/c79cab0c2a5ac3d08de9f932fa29a56d334a712b/gtfparse/read_gtf.py#L165-L247 |
2,909 | openvax/gtfparse | gtfparse/create_missing_features.py | create_missing_features | def create_missing_features(
dataframe,
unique_keys={},
extra_columns={},
missing_value=None):
"""
Helper function used to construct a missing feature such as 'transcript'
or 'gene'. Some GTF files only have 'exon' and 'CDS' entries, but have
transcript_id and gene_id ann... | python | def create_missing_features(
dataframe,
unique_keys={},
extra_columns={},
missing_value=None):
extra_dataframes = []
existing_features = set(dataframe["feature"])
existing_columns = set(dataframe.keys())
for (feature_name, groupby_key) in unique_keys.items():
if... | [
"def",
"create_missing_features",
"(",
"dataframe",
",",
"unique_keys",
"=",
"{",
"}",
",",
"extra_columns",
"=",
"{",
"}",
",",
"missing_value",
"=",
"None",
")",
":",
"extra_dataframes",
"=",
"[",
"]",
"existing_features",
"=",
"set",
"(",
"dataframe",
"["... | Helper function used to construct a missing feature such as 'transcript'
or 'gene'. Some GTF files only have 'exon' and 'CDS' entries, but have
transcript_id and gene_id annotations which allow us to construct those
missing features.
Parameters
----------
dataframe : pandas.DataFrame
Sh... | [
"Helper",
"function",
"used",
"to",
"construct",
"a",
"missing",
"feature",
"such",
"as",
"transcript",
"or",
"gene",
".",
"Some",
"GTF",
"files",
"only",
"have",
"exon",
"and",
"CDS",
"entries",
"but",
"have",
"transcript_id",
"and",
"gene_id",
"annotations",... | c79cab0c2a5ac3d08de9f932fa29a56d334a712b | https://github.com/openvax/gtfparse/blob/c79cab0c2a5ac3d08de9f932fa29a56d334a712b/gtfparse/create_missing_features.py#L25-L121 |
2,910 | MichaelAquilina/S4 | s4/clients/__init__.py | SyncClient.get_action | def get_action(self, key):
"""
returns the action to perform on this key based on its
state before the last sync.
"""
index_local_timestamp = self.get_index_local_timestamp(key)
real_local_timestamp = self.get_real_local_timestamp(key)
remote_timestamp = self.get_... | python | def get_action(self, key):
index_local_timestamp = self.get_index_local_timestamp(key)
real_local_timestamp = self.get_real_local_timestamp(key)
remote_timestamp = self.get_remote_timestamp(key)
return get_sync_state(
index_local_timestamp, real_local_timestamp, remote_timest... | [
"def",
"get_action",
"(",
"self",
",",
"key",
")",
":",
"index_local_timestamp",
"=",
"self",
".",
"get_index_local_timestamp",
"(",
"key",
")",
"real_local_timestamp",
"=",
"self",
".",
"get_real_local_timestamp",
"(",
"key",
")",
"remote_timestamp",
"=",
"self",... | returns the action to perform on this key based on its
state before the last sync. | [
"returns",
"the",
"action",
"to",
"perform",
"on",
"this",
"key",
"based",
"on",
"its",
"state",
"before",
"the",
"last",
"sync",
"."
] | 05d74697e6ec683f0329c983f7c3f05ab75fd57e | https://github.com/MichaelAquilina/S4/blob/05d74697e6ec683f0329c983f7c3f05ab75fd57e/s4/clients/__init__.py#L191-L201 |
2,911 | MichaelAquilina/S4 | s4/clients/local.py | LocalSyncClient.lock | def lock(self, timeout=10):
"""
Advisory lock.
Use to ensure that only one LocalSyncClient is working on the Target at the same time.
"""
logger.debug("Locking %s", self.lock_file)
if not os.path.exists(self.lock_file):
self.ensure_path(self.lock_file)
... | python | def lock(self, timeout=10):
logger.debug("Locking %s", self.lock_file)
if not os.path.exists(self.lock_file):
self.ensure_path(self.lock_file)
with open(self.lock_file, "w"):
os.utime(self.lock_file)
self._lock.acquire(timeout=timeout) | [
"def",
"lock",
"(",
"self",
",",
"timeout",
"=",
"10",
")",
":",
"logger",
".",
"debug",
"(",
"\"Locking %s\"",
",",
"self",
".",
"lock_file",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"lock_file",
")",
":",
"self",
".",... | Advisory lock.
Use to ensure that only one LocalSyncClient is working on the Target at the same time. | [
"Advisory",
"lock",
".",
"Use",
"to",
"ensure",
"that",
"only",
"one",
"LocalSyncClient",
"is",
"working",
"on",
"the",
"Target",
"at",
"the",
"same",
"time",
"."
] | 05d74697e6ec683f0329c983f7c3f05ab75fd57e | https://github.com/MichaelAquilina/S4/blob/05d74697e6ec683f0329c983f7c3f05ab75fd57e/s4/clients/local.py#L65-L75 |
2,912 | MichaelAquilina/S4 | s4/clients/local.py | LocalSyncClient.unlock | def unlock(self):
"""
Unlock the active advisory lock.
"""
logger.debug("Releasing lock %s", self.lock_file)
self._lock.release()
try:
os.unlink(self.lock_file)
except FileNotFoundError:
pass | python | def unlock(self):
logger.debug("Releasing lock %s", self.lock_file)
self._lock.release()
try:
os.unlink(self.lock_file)
except FileNotFoundError:
pass | [
"def",
"unlock",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"\"Releasing lock %s\"",
",",
"self",
".",
"lock_file",
")",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"try",
":",
"os",
".",
"unlink",
"(",
"self",
".",
"lock_file",
")",
"ex... | Unlock the active advisory lock. | [
"Unlock",
"the",
"active",
"advisory",
"lock",
"."
] | 05d74697e6ec683f0329c983f7c3f05ab75fd57e | https://github.com/MichaelAquilina/S4/blob/05d74697e6ec683f0329c983f7c3f05ab75fd57e/s4/clients/local.py#L77-L86 |
2,913 | gazpachoking/jsonref | proxytypes.py | ProxyMetaClass._no_proxy | def _no_proxy(method):
"""
Returns a wrapped version of `method`, such that proxying is turned off
during the method call.
"""
@wraps(method)
def wrapper(self, *args, **kwargs):
notproxied = _oga(self, "__notproxied__")
_osa(self, "__notproxied__... | python | def _no_proxy(method):
@wraps(method)
def wrapper(self, *args, **kwargs):
notproxied = _oga(self, "__notproxied__")
_osa(self, "__notproxied__", True)
try:
return method(self, *args, **kwargs)
finally:
_osa(self, "__notproxi... | [
"def",
"_no_proxy",
"(",
"method",
")",
":",
"@",
"wraps",
"(",
"method",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"notproxied",
"=",
"_oga",
"(",
"self",
",",
"\"__notproxied__\"",
")",
"_osa",
"(",
... | Returns a wrapped version of `method`, such that proxying is turned off
during the method call. | [
"Returns",
"a",
"wrapped",
"version",
"of",
"method",
"such",
"that",
"proxying",
"is",
"turned",
"off",
"during",
"the",
"method",
"call",
"."
] | 066132e527f8115f75bcadfd0eca12f8973a6309 | https://github.com/gazpachoking/jsonref/blob/066132e527f8115f75bcadfd0eca12f8973a6309/proxytypes.py#L122-L138 |
2,914 | gazpachoking/jsonref | proxytypes.py | Proxy._should_proxy | def _should_proxy(self, attr):
"""
Determines whether `attr` should be looked up on the proxied object, or
the proxy itself.
"""
if attr in type(self).__notproxied__:
return False
if _oga(self, "__notproxied__") is True:
return False
retur... | python | def _should_proxy(self, attr):
if attr in type(self).__notproxied__:
return False
if _oga(self, "__notproxied__") is True:
return False
return True | [
"def",
"_should_proxy",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
"in",
"type",
"(",
"self",
")",
".",
"__notproxied__",
":",
"return",
"False",
"if",
"_oga",
"(",
"self",
",",
"\"__notproxied__\"",
")",
"is",
"True",
":",
"return",
"False",
"r... | Determines whether `attr` should be looked up on the proxied object, or
the proxy itself. | [
"Determines",
"whether",
"attr",
"should",
"be",
"looked",
"up",
"on",
"the",
"proxied",
"object",
"or",
"the",
"proxy",
"itself",
"."
] | 066132e527f8115f75bcadfd0eca12f8973a6309 | https://github.com/gazpachoking/jsonref/blob/066132e527f8115f75bcadfd0eca12f8973a6309/proxytypes.py#L161-L171 |
2,915 | gazpachoking/jsonref | proxytypes.py | Proxy.add_proxy_meth | def add_proxy_meth(cls, name, func, arg_pos=0):
"""
Add a method `name` to the class, which returns the value of `func`,
called with the proxied value inserted at `arg_pos`
"""
@wraps(func)
def proxied(self, *args, **kwargs):
args = list(args)
ar... | python | def add_proxy_meth(cls, name, func, arg_pos=0):
@wraps(func)
def proxied(self, *args, **kwargs):
args = list(args)
args.insert(arg_pos, self.__subject__)
result = func(*args, **kwargs)
return result
setattr(cls, name, proxied) | [
"def",
"add_proxy_meth",
"(",
"cls",
",",
"name",
",",
"func",
",",
"arg_pos",
"=",
"0",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"proxied",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"args",
"=",
"list",
"(",
"ar... | Add a method `name` to the class, which returns the value of `func`,
called with the proxied value inserted at `arg_pos` | [
"Add",
"a",
"method",
"name",
"to",
"the",
"class",
"which",
"returns",
"the",
"value",
"of",
"func",
"called",
"with",
"the",
"proxied",
"value",
"inserted",
"at",
"arg_pos"
] | 066132e527f8115f75bcadfd0eca12f8973a6309 | https://github.com/gazpachoking/jsonref/blob/066132e527f8115f75bcadfd0eca12f8973a6309/proxytypes.py#L192-L206 |
2,916 | gazpachoking/jsonref | jsonref.py | load_uri | def load_uri(uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=True):
"""
Load JSON data from ``uri`` with JSON references proxied to their referent
data.
:param uri: URI to fetch the JSON from
:param kwargs: This function takes any of the keyword arguments from
:meth:`JsonRef... | python | def load_uri(uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=True):
if loader is None:
loader = jsonloader
if base_uri is None:
base_uri = uri
return JsonRef.replace_refs(
loader(uri),
base_uri=base_uri,
loader=loader,
jsonschema=jsonschema,
... | [
"def",
"load_uri",
"(",
"uri",
",",
"base_uri",
"=",
"None",
",",
"loader",
"=",
"None",
",",
"jsonschema",
"=",
"False",
",",
"load_on_repr",
"=",
"True",
")",
":",
"if",
"loader",
"is",
"None",
":",
"loader",
"=",
"jsonloader",
"if",
"base_uri",
"is"... | Load JSON data from ``uri`` with JSON references proxied to their referent
data.
:param uri: URI to fetch the JSON from
:param kwargs: This function takes any of the keyword arguments from
:meth:`JsonRef.replace_refs` | [
"Load",
"JSON",
"data",
"from",
"uri",
"with",
"JSON",
"references",
"proxied",
"to",
"their",
"referent",
"data",
"."
] | 066132e527f8115f75bcadfd0eca12f8973a6309 | https://github.com/gazpachoking/jsonref/blob/066132e527f8115f75bcadfd0eca12f8973a6309/jsonref.py#L372-L394 |
2,917 | gazpachoking/jsonref | jsonref.py | JsonRef.resolve_pointer | def resolve_pointer(self, document, pointer):
"""
Resolve a json pointer ``pointer`` within the referenced ``document``.
:argument document: the referent document
:argument str pointer: a json pointer URI fragment to resolve within it
"""
# Do only split at single forwa... | python | def resolve_pointer(self, document, pointer):
# Do only split at single forward slashes which are not prefixed by a caret
parts = re.split(r"(?<!\^)/", unquote(pointer.lstrip("/"))) if pointer else []
for part in parts:
# Restore escaped slashes and carets
replacements =... | [
"def",
"resolve_pointer",
"(",
"self",
",",
"document",
",",
"pointer",
")",
":",
"# Do only split at single forward slashes which are not prefixed by a caret",
"parts",
"=",
"re",
".",
"split",
"(",
"r\"(?<!\\^)/\"",
",",
"unquote",
"(",
"pointer",
".",
"lstrip",
"("... | Resolve a json pointer ``pointer`` within the referenced ``document``.
:argument document: the referent document
:argument str pointer: a json pointer URI fragment to resolve within it | [
"Resolve",
"a",
"json",
"pointer",
"pointer",
"within",
"the",
"referenced",
"document",
"."
] | 066132e527f8115f75bcadfd0eca12f8973a6309 | https://github.com/gazpachoking/jsonref/blob/066132e527f8115f75bcadfd0eca12f8973a6309/jsonref.py#L191-L220 |
2,918 | Iotic-Labs/py-ubjson | ubjson/encoder.py | dump | def dump(obj, fp, container_count=False, sort_keys=False, no_float32=True, default=None):
"""Writes the given object as UBJSON to the provided file-like object
Args:
obj: The object to encode
fp: write([size])-able object
container_count (bool): Specify length for container types (inclu... | python | def dump(obj, fp, container_count=False, sort_keys=False, no_float32=True, default=None):
if not callable(fp.write):
raise TypeError('fp.write not callable')
fp_write = fp.write
__encode_value(fp_write, obj, {}, container_count, sort_keys, no_float32, default) | [
"def",
"dump",
"(",
"obj",
",",
"fp",
",",
"container_count",
"=",
"False",
",",
"sort_keys",
"=",
"False",
",",
"no_float32",
"=",
"True",
",",
"default",
"=",
"None",
")",
":",
"if",
"not",
"callable",
"(",
"fp",
".",
"write",
")",
":",
"raise",
... | Writes the given object as UBJSON to the provided file-like object
Args:
obj: The object to encode
fp: write([size])-able object
container_count (bool): Specify length for container types (including
for empty ones). This can aid decoding speed
... | [
"Writes",
"the",
"given",
"object",
"as",
"UBJSON",
"to",
"the",
"provided",
"file",
"-",
"like",
"object"
] | 80dcacbc7bba1759c69759fb3109ac1c6574da68 | https://github.com/Iotic-Labs/py-ubjson/blob/80dcacbc7bba1759c69759fb3109ac1c6574da68/ubjson/encoder.py#L233-L305 |
2,919 | Iotic-Labs/py-ubjson | ez_setup.py | _resolve_version | def _resolve_version(version):
"""
Resolve LATEST version
"""
if version is not LATEST:
return version
resp = urlopen('https://pypi.python.org/pypi/setuptools/json')
with contextlib.closing(resp):
try:
charset = resp.info().get_content_charset()
except Except... | python | def _resolve_version(version):
if version is not LATEST:
return version
resp = urlopen('https://pypi.python.org/pypi/setuptools/json')
with contextlib.closing(resp):
try:
charset = resp.info().get_content_charset()
except Exception:
# Python 2 compat; assume ... | [
"def",
"_resolve_version",
"(",
"version",
")",
":",
"if",
"version",
"is",
"not",
"LATEST",
":",
"return",
"version",
"resp",
"=",
"urlopen",
"(",
"'https://pypi.python.org/pypi/setuptools/json'",
")",
"with",
"contextlib",
".",
"closing",
"(",
"resp",
")",
":"... | Resolve LATEST version | [
"Resolve",
"LATEST",
"version"
] | 80dcacbc7bba1759c69759fb3109ac1c6574da68 | https://github.com/Iotic-Labs/py-ubjson/blob/80dcacbc7bba1759c69759fb3109ac1c6574da68/ez_setup.py#L340-L357 |
2,920 | Iotic-Labs/py-ubjson | ubjson/decoder.py | load | def load(fp, no_bytes=False, object_hook=None, object_pairs_hook=None, intern_object_keys=False):
"""Decodes and returns UBJSON from the given file-like object
Args:
fp: read([size])-able object
no_bytes (bool): If set, typed UBJSON arrays (uint8) will not be
converted ... | python | def load(fp, no_bytes=False, object_hook=None, object_pairs_hook=None, intern_object_keys=False):
if object_pairs_hook is None and object_hook is None:
object_hook = __object_hook_noop
if not callable(fp.read):
raise TypeError('fp.read not callable')
fp_read = fp.read
marker = fp_read(... | [
"def",
"load",
"(",
"fp",
",",
"no_bytes",
"=",
"False",
",",
"object_hook",
"=",
"None",
",",
"object_pairs_hook",
"=",
"None",
",",
"intern_object_keys",
"=",
"False",
")",
":",
"if",
"object_pairs_hook",
"is",
"None",
"and",
"object_hook",
"is",
"None",
... | Decodes and returns UBJSON from the given file-like object
Args:
fp: read([size])-able object
no_bytes (bool): If set, typed UBJSON arrays (uint8) will not be
converted to a bytes instance and instead treated like
any other array (i.e. result in a l... | [
"Decodes",
"and",
"returns",
"UBJSON",
"from",
"the",
"given",
"file",
"-",
"like",
"object"
] | 80dcacbc7bba1759c69759fb3109ac1c6574da68 | https://github.com/Iotic-Labs/py-ubjson/blob/80dcacbc7bba1759c69759fb3109ac1c6574da68/ubjson/decoder.py#L307-L383 |
2,921 | jborean93/requests-credssp | requests_credssp/asn_structures.py | TSRequest.check_error_code | def check_error_code(self):
"""
For CredSSP version of 3 or newer, the server can response with an
NtStatus error code with details of what error occurred. This method
will check if the error code exists and throws an NTStatusException
if it is no STATUS_SUCCESS.
"""
... | python | def check_error_code(self):
# start off with STATUS_SUCCESS as a baseline
status = NtStatusCodes.STATUS_SUCCESS
error_code = self['errorCode']
if error_code.isValue:
# ASN.1 Integer is stored as an signed integer, we need to
# convert it to a unsigned integer
... | [
"def",
"check_error_code",
"(",
"self",
")",
":",
"# start off with STATUS_SUCCESS as a baseline",
"status",
"=",
"NtStatusCodes",
".",
"STATUS_SUCCESS",
"error_code",
"=",
"self",
"[",
"'errorCode'",
"]",
"if",
"error_code",
".",
"isValue",
":",
"# ASN.1 Integer is sto... | For CredSSP version of 3 or newer, the server can response with an
NtStatus error code with details of what error occurred. This method
will check if the error code exists and throws an NTStatusException
if it is no STATUS_SUCCESS. | [
"For",
"CredSSP",
"version",
"of",
"3",
"or",
"newer",
"the",
"server",
"can",
"response",
"with",
"an",
"NtStatus",
"error",
"code",
"with",
"details",
"of",
"what",
"error",
"occurred",
".",
"This",
"method",
"will",
"check",
"if",
"the",
"error",
"code"... | 470db8d74dff919da67cf382e9ff784d4e8dd053 | https://github.com/jborean93/requests-credssp/blob/470db8d74dff919da67cf382e9ff784d4e8dd053/requests_credssp/asn_structures.py#L108-L125 |
2,922 | jborean93/requests-credssp | requests_credssp/spnego.py | GSSAPIContext.get_mechs_available | def get_mechs_available():
"""
Returns a list of auth mechanisms that are available to the local
GSSAPI instance. Because we are interacting with Windows, we only
care if SPNEGO, Kerberos and NTLM are available where NTLM is the
only wildcard that may not be available by default.... | python | def get_mechs_available():
ntlm_oid = GSSAPIContext._AUTH_MECHANISMS['ntlm']
ntlm_mech = gssapi.OID.from_int_seq(ntlm_oid)
# GSS_NTLMSSP_RESET_CRYPTO_OID_LENGTH
# github.com/simo5/gss-ntlmssp/blob/master/src/gssapi_ntlmssp.h#L68
reset_mech = gssapi.OID.from_int_seq("1.3.6.1.4.1.7... | [
"def",
"get_mechs_available",
"(",
")",
":",
"ntlm_oid",
"=",
"GSSAPIContext",
".",
"_AUTH_MECHANISMS",
"[",
"'ntlm'",
"]",
"ntlm_mech",
"=",
"gssapi",
".",
"OID",
".",
"from_int_seq",
"(",
"ntlm_oid",
")",
"# GSS_NTLMSSP_RESET_CRYPTO_OID_LENGTH",
"# github.com/simo5/... | Returns a list of auth mechanisms that are available to the local
GSSAPI instance. Because we are interacting with Windows, we only
care if SPNEGO, Kerberos and NTLM are available where NTLM is the
only wildcard that may not be available by default.
The only NTLM implementation that wor... | [
"Returns",
"a",
"list",
"of",
"auth",
"mechanisms",
"that",
"are",
"available",
"to",
"the",
"local",
"GSSAPI",
"instance",
".",
"Because",
"we",
"are",
"interacting",
"with",
"Windows",
"we",
"only",
"care",
"if",
"SPNEGO",
"Kerberos",
"and",
"NTLM",
"are",... | 470db8d74dff919da67cf382e9ff784d4e8dd053 | https://github.com/jborean93/requests-credssp/blob/470db8d74dff919da67cf382e9ff784d4e8dd053/requests_credssp/spnego.py#L397-L440 |
2,923 | jborean93/requests-credssp | requests_credssp/credssp.py | CredSSPContext.wrap | def wrap(self, data):
"""
Encrypts the data in preparation for sending to the server. The data is
encrypted using the TLS channel negotiated between the client and the
server.
:param data: a byte string of data to encrypt
:return: a byte string of the encrypted data
... | python | def wrap(self, data):
length = self.tls_connection.send(data)
encrypted_data = b''
counter = 0
while True:
try:
encrypted_chunk = \
self.tls_connection.bio_read(self.BIO_BUFFER_SIZE)
except SSL.WantReadError:
br... | [
"def",
"wrap",
"(",
"self",
",",
"data",
")",
":",
"length",
"=",
"self",
".",
"tls_connection",
".",
"send",
"(",
"data",
")",
"encrypted_data",
"=",
"b''",
"counter",
"=",
"0",
"while",
"True",
":",
"try",
":",
"encrypted_chunk",
"=",
"self",
".",
... | Encrypts the data in preparation for sending to the server. The data is
encrypted using the TLS channel negotiated between the client and the
server.
:param data: a byte string of data to encrypt
:return: a byte string of the encrypted data | [
"Encrypts",
"the",
"data",
"in",
"preparation",
"for",
"sending",
"to",
"the",
"server",
".",
"The",
"data",
"is",
"encrypted",
"using",
"the",
"TLS",
"channel",
"negotiated",
"between",
"the",
"client",
"and",
"the",
"server",
"."
] | 470db8d74dff919da67cf382e9ff784d4e8dd053 | https://github.com/jborean93/requests-credssp/blob/470db8d74dff919da67cf382e9ff784d4e8dd053/requests_credssp/credssp.py#L296-L324 |
2,924 | jborean93/requests-credssp | requests_credssp/credssp.py | CredSSPContext.unwrap | def unwrap(self, encrypted_data):
"""
Decrypts the data send by the server using the TLS channel negotiated
between the client and the server.
:param encrypted_data: the byte string of the encrypted data
:return: a byte string of the decrypted data
"""
length = s... | python | def unwrap(self, encrypted_data):
length = self.tls_connection.bio_write(encrypted_data)
data = b''
counter = 0
while True:
try:
data_chunk = self.tls_connection.recv(self.BIO_BUFFER_SIZE)
except SSL.WantReadError:
break
... | [
"def",
"unwrap",
"(",
"self",
",",
"encrypted_data",
")",
":",
"length",
"=",
"self",
".",
"tls_connection",
".",
"bio_write",
"(",
"encrypted_data",
")",
"data",
"=",
"b''",
"counter",
"=",
"0",
"while",
"True",
":",
"try",
":",
"data_chunk",
"=",
"self... | Decrypts the data send by the server using the TLS channel negotiated
between the client and the server.
:param encrypted_data: the byte string of the encrypted data
:return: a byte string of the decrypted data | [
"Decrypts",
"the",
"data",
"send",
"by",
"the",
"server",
"using",
"the",
"TLS",
"channel",
"negotiated",
"between",
"the",
"client",
"and",
"the",
"server",
"."
] | 470db8d74dff919da67cf382e9ff784d4e8dd053 | https://github.com/jborean93/requests-credssp/blob/470db8d74dff919da67cf382e9ff784d4e8dd053/requests_credssp/credssp.py#L326-L349 |
2,925 | jborean93/requests-credssp | requests_credssp/credssp.py | CredSSPContext._get_subject_public_key | def _get_subject_public_key(cert):
"""
Returns the SubjectPublicKey asn.1 field of the SubjectPublicKeyInfo
field of the server's certificate. This is used in the server
verification steps to thwart MitM attacks.
:param cert: X509 certificate from pyOpenSSL .get_peer_certificate... | python | def _get_subject_public_key(cert):
public_key = cert.get_pubkey()
cryptographic_key = public_key.to_cryptography_key()
subject_public_key = cryptographic_key.public_bytes(Encoding.DER,
PublicFormat.PKCS1)
return subject_public_k... | [
"def",
"_get_subject_public_key",
"(",
"cert",
")",
":",
"public_key",
"=",
"cert",
".",
"get_pubkey",
"(",
")",
"cryptographic_key",
"=",
"public_key",
".",
"to_cryptography_key",
"(",
")",
"subject_public_key",
"=",
"cryptographic_key",
".",
"public_bytes",
"(",
... | Returns the SubjectPublicKey asn.1 field of the SubjectPublicKeyInfo
field of the server's certificate. This is used in the server
verification steps to thwart MitM attacks.
:param cert: X509 certificate from pyOpenSSL .get_peer_certificate()
:return: byte string of the asn.1 DER encode... | [
"Returns",
"the",
"SubjectPublicKey",
"asn",
".",
"1",
"field",
"of",
"the",
"SubjectPublicKeyInfo",
"field",
"of",
"the",
"server",
"s",
"certificate",
".",
"This",
"is",
"used",
"in",
"the",
"server",
"verification",
"steps",
"to",
"thwart",
"MitM",
"attacks... | 470db8d74dff919da67cf382e9ff784d4e8dd053 | https://github.com/jborean93/requests-credssp/blob/470db8d74dff919da67cf382e9ff784d4e8dd053/requests_credssp/credssp.py#L352-L365 |
2,926 | msuozzo/Lector | lector/reader.py | _KindleCloudReaderBrowser._to_reader_home | def _to_reader_home(self):
"""Navigate to the Cloud Reader library page.
Raises:
BrowserError: If the KCR homepage could not be loaded.
ConnectionError: If there was a connection error.
"""
# NOTE: Prevents QueryInterface error caused by getting a URL
# while switched to an iframe
s... | python | def _to_reader_home(self):
# NOTE: Prevents QueryInterface error caused by getting a URL
# while switched to an iframe
self.switch_to_default_content()
self.get(_KindleCloudReaderBrowser._CLOUD_READER_URL)
if self.title == u'Problem loading page':
raise ConnectionError
# Wait for either ... | [
"def",
"_to_reader_home",
"(",
"self",
")",
":",
"# NOTE: Prevents QueryInterface error caused by getting a URL",
"# while switched to an iframe",
"self",
".",
"switch_to_default_content",
"(",
")",
"self",
".",
"get",
"(",
"_KindleCloudReaderBrowser",
".",
"_CLOUD_READER_URL",... | Navigate to the Cloud Reader library page.
Raises:
BrowserError: If the KCR homepage could not be loaded.
ConnectionError: If there was a connection error. | [
"Navigate",
"to",
"the",
"Cloud",
"Reader",
"library",
"page",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L199-L225 |
2,927 | msuozzo/Lector | lector/reader.py | _KindleCloudReaderBrowser._login | def _login(self, max_tries=2):
"""Logs in to Kindle Cloud Reader.
Args:
max_tries: The maximum number of login attempts that will be made.
Raises:
BrowserError: If method called when browser not at a signin URL.
LoginError: If login unsuccessful after `max_tries` attempts.
"""
i... | python | def _login(self, max_tries=2):
if not self.current_url.startswith(_KindleCloudReaderBrowser._SIGNIN_URL):
raise BrowserError(
'Current url "%s" is not a signin url ("%s")' %
(self.current_url, _KindleCloudReaderBrowser._SIGNIN_URL))
email_field_loaded = lambda br: br.find_elements_by_... | [
"def",
"_login",
"(",
"self",
",",
"max_tries",
"=",
"2",
")",
":",
"if",
"not",
"self",
".",
"current_url",
".",
"startswith",
"(",
"_KindleCloudReaderBrowser",
".",
"_SIGNIN_URL",
")",
":",
"raise",
"BrowserError",
"(",
"'Current url \"%s\" is not a signin url (... | Logs in to Kindle Cloud Reader.
Args:
max_tries: The maximum number of login attempts that will be made.
Raises:
BrowserError: If method called when browser not at a signin URL.
LoginError: If login unsuccessful after `max_tries` attempts. | [
"Logs",
"in",
"to",
"Kindle",
"Cloud",
"Reader",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L227-L274 |
2,928 | msuozzo/Lector | lector/reader.py | _KindleCloudReaderBrowser._to_reader_frame | def _to_reader_frame(self):
"""Navigate to the KindleReader iframe."""
reader_frame = 'KindleReaderIFrame'
frame_loaded = lambda br: br.find_elements_by_id(reader_frame)
self._wait().until(frame_loaded)
self.switch_to.frame(reader_frame) # pylint: disable=no-member
reader_loaded = lambda br:... | python | def _to_reader_frame(self):
reader_frame = 'KindleReaderIFrame'
frame_loaded = lambda br: br.find_elements_by_id(reader_frame)
self._wait().until(frame_loaded)
self.switch_to.frame(reader_frame) # pylint: disable=no-member
reader_loaded = lambda br: br.find_elements_by_id('kindleReader_header')
... | [
"def",
"_to_reader_frame",
"(",
"self",
")",
":",
"reader_frame",
"=",
"'KindleReaderIFrame'",
"frame_loaded",
"=",
"lambda",
"br",
":",
"br",
".",
"find_elements_by_id",
"(",
"reader_frame",
")",
"self",
".",
"_wait",
"(",
")",
".",
"until",
"(",
"frame_loade... | Navigate to the KindleReader iframe. | [
"Navigate",
"to",
"the",
"KindleReader",
"iframe",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L276-L286 |
2,929 | msuozzo/Lector | lector/reader.py | _KindleCloudReaderBrowser._wait_for_js | def _wait_for_js(self):
"""Wait for the Kindle Cloud Reader JS modules to initialize.
These modules provide the interface used to execute API queries.
"""
# Wait for the Module Manager to load
mod_mgr_script = ur"return window.hasOwnProperty('KindleModuleManager');"
mod_mgr_loaded = lambda br: ... | python | def _wait_for_js(self):
# Wait for the Module Manager to load
mod_mgr_script = ur"return window.hasOwnProperty('KindleModuleManager');"
mod_mgr_loaded = lambda br: br.execute_script(mod_mgr_script)
self._wait(5).until(mod_mgr_loaded)
# Wait for the DB Client to load
db_client_script = dedent(ur... | [
"def",
"_wait_for_js",
"(",
"self",
")",
":",
"# Wait for the Module Manager to load",
"mod_mgr_script",
"=",
"ur\"return window.hasOwnProperty('KindleModuleManager');\"",
"mod_mgr_loaded",
"=",
"lambda",
"br",
":",
"br",
".",
"execute_script",
"(",
"mod_mgr_script",
")",
"... | Wait for the Kindle Cloud Reader JS modules to initialize.
These modules provide the interface used to execute API queries. | [
"Wait",
"for",
"the",
"Kindle",
"Cloud",
"Reader",
"JS",
"modules",
"to",
"initialize",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L288-L314 |
2,930 | msuozzo/Lector | lector/reader.py | KindleCloudReaderAPI._get_api_call | def _get_api_call(self, function_name, *args):
"""Runs an api call with javascript-formatted arguments.
Args:
function_name: The name of the KindleAPI call to run.
*args: Javascript-formatted arguments to pass to the API call.
Returns:
The result of the API call.
Raises:
APIEr... | python | def _get_api_call(self, function_name, *args):
api_call = dedent("""
var done = arguments[0];
KindleAPI.%(api_call)s(%(args)s).always(function(a) {
done(a);
});
""") % {
'api_call': function_name,
'args': ', '.join(args)
}
script = '\n'.join((api.API_S... | [
"def",
"_get_api_call",
"(",
"self",
",",
"function_name",
",",
"*",
"args",
")",
":",
"api_call",
"=",
"dedent",
"(",
"\"\"\"\n var done = arguments[0];\n KindleAPI.%(api_call)s(%(args)s).always(function(a) {\n done(a);\n });\n \"\"\"",
")",
"%",... | Runs an api call with javascript-formatted arguments.
Args:
function_name: The name of the KindleAPI call to run.
*args: Javascript-formatted arguments to pass to the API call.
Returns:
The result of the API call.
Raises:
APIError: If the API call fails or times out. | [
"Runs",
"an",
"api",
"call",
"with",
"javascript",
"-",
"formatted",
"arguments",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L328-L355 |
2,931 | msuozzo/Lector | lector/reader.py | KindleCloudReaderAPI.get_book_metadata | def get_book_metadata(self, asin):
"""Returns a book's metadata.
Args:
asin: The ASIN of the book to be queried.
Returns:
A `KindleBook` instance corresponding to the book associated with
`asin`.
"""
kbm = self._get_api_call('get_book_metadata', '"%s"' % asin)
return KindleCl... | python | def get_book_metadata(self, asin):
kbm = self._get_api_call('get_book_metadata', '"%s"' % asin)
return KindleCloudReaderAPI._kbm_to_book(kbm) | [
"def",
"get_book_metadata",
"(",
"self",
",",
"asin",
")",
":",
"kbm",
"=",
"self",
".",
"_get_api_call",
"(",
"'get_book_metadata'",
",",
"'\"%s\"'",
"%",
"asin",
")",
"return",
"KindleCloudReaderAPI",
".",
"_kbm_to_book",
"(",
"kbm",
")"
] | Returns a book's metadata.
Args:
asin: The ASIN of the book to be queried.
Returns:
A `KindleBook` instance corresponding to the book associated with
`asin`. | [
"Returns",
"a",
"book",
"s",
"metadata",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L387-L398 |
2,932 | msuozzo/Lector | lector/reader.py | KindleCloudReaderAPI.get_book_progress | def get_book_progress(self, asin):
"""Returns the progress data available for a book.
NOTE: A summary of the two progress formats can be found in the
docstring for `ReadingProgress`.
Args:
asin: The asin of the book to be queried.
Returns:
A `ReadingProgress` instance corresponding to... | python | def get_book_progress(self, asin):
kbp = self._get_api_call('get_book_progress', '"%s"' % asin)
return KindleCloudReaderAPI._kbp_to_progress(kbp) | [
"def",
"get_book_progress",
"(",
"self",
",",
"asin",
")",
":",
"kbp",
"=",
"self",
".",
"_get_api_call",
"(",
"'get_book_progress'",
",",
"'\"%s\"'",
"%",
"asin",
")",
"return",
"KindleCloudReaderAPI",
".",
"_kbp_to_progress",
"(",
"kbp",
")"
] | Returns the progress data available for a book.
NOTE: A summary of the two progress formats can be found in the
docstring for `ReadingProgress`.
Args:
asin: The asin of the book to be queried.
Returns:
A `ReadingProgress` instance corresponding to the book associated with
`asin`. | [
"Returns",
"the",
"progress",
"data",
"available",
"for",
"a",
"book",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L410-L424 |
2,933 | msuozzo/Lector | lector/reader.py | KindleCloudReaderAPI.get_library_progress | def get_library_progress(self):
"""Returns the reading progress for all books in the kindle library.
Returns:
A mapping of ASINs to `ReadingProgress` instances corresponding to the
books in the current user's library.
"""
kbp_dict = self._get_api_call('get_library_progress')
return {asi... | python | def get_library_progress(self):
kbp_dict = self._get_api_call('get_library_progress')
return {asin: KindleCloudReaderAPI._kbp_to_progress(kbp)
for asin, kbp in kbp_dict.iteritems()} | [
"def",
"get_library_progress",
"(",
"self",
")",
":",
"kbp_dict",
"=",
"self",
".",
"_get_api_call",
"(",
"'get_library_progress'",
")",
"return",
"{",
"asin",
":",
"KindleCloudReaderAPI",
".",
"_kbp_to_progress",
"(",
"kbp",
")",
"for",
"asin",
",",
"kbp",
"i... | Returns the reading progress for all books in the kindle library.
Returns:
A mapping of ASINs to `ReadingProgress` instances corresponding to the
books in the current user's library. | [
"Returns",
"the",
"reading",
"progress",
"for",
"all",
"books",
"in",
"the",
"kindle",
"library",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L426-L435 |
2,934 | msuozzo/Lector | lector/reader.py | KindleCloudReaderAPI.get_instance | def get_instance(*args, **kwargs):
"""Context manager for an instance of `KindleCloudReaderAPI`."""
inst = KindleCloudReaderAPI(*args, **kwargs)
try:
yield inst
except Exception:
raise
finally:
inst.close() | python | def get_instance(*args, **kwargs):
inst = KindleCloudReaderAPI(*args, **kwargs)
try:
yield inst
except Exception:
raise
finally:
inst.close() | [
"def",
"get_instance",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"inst",
"=",
"KindleCloudReaderAPI",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"try",
":",
"yield",
"inst",
"except",
"Exception",
":",
"raise",
"finally",
":",
"inst",
... | Context manager for an instance of `KindleCloudReaderAPI`. | [
"Context",
"manager",
"for",
"an",
"instance",
"of",
"KindleCloudReaderAPI",
"."
] | 1570f7734a1c68f294648f44088a7ccb09c26241 | https://github.com/msuozzo/Lector/blob/1570f7734a1c68f294648f44088a7ccb09c26241/lector/reader.py#L443-L452 |
2,935 | alexanderlukanin13/coolname | coolname/loader.py | load_config | def load_config(path):
"""
Loads configuration from a path.
Path can be a json file, or a directory containing config.json
and zero or more *.txt files with word lists or phrase lists.
Returns config dict.
Raises InitializationError when something is wrong.
"""
path = os.path.abspath(... | python | def load_config(path):
path = os.path.abspath(path)
if os.path.isdir(path):
config, wordlists = _load_data(path)
elif os.path.isfile(path):
config = _load_config(path)
wordlists = {}
else:
raise InitializationError('File or directory not found: {0}'.format(path))
for ... | [
"def",
"load_config",
"(",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
":",
"config",
",",
"wordlists",
"=",
"_load_data",
"(",
"path",
")",
"elif",
... | Loads configuration from a path.
Path can be a json file, or a directory containing config.json
and zero or more *.txt files with word lists or phrase lists.
Returns config dict.
Raises InitializationError when something is wrong. | [
"Loads",
"configuration",
"from",
"a",
"path",
"."
] | 416cc39254ab9e921fd5be77dfe6cdafbad0300c | https://github.com/alexanderlukanin13/coolname/blob/416cc39254ab9e921fd5be77dfe6cdafbad0300c/coolname/loader.py#L19-L45 |
2,936 | alexanderlukanin13/coolname | coolname/loader.py | _load_wordlist | def _load_wordlist(name, stream):
"""
Loads list of words or phrases from file.
Returns "words" or "phrases" dictionary, the same as used in config.
Raises Exception if file is missing or invalid.
"""
items = []
max_length = None
multiword = False
multiword_start = None
number_o... | python | def _load_wordlist(name, stream):
items = []
max_length = None
multiword = False
multiword_start = None
number_of_words = None
for i, line in enumerate(stream, start=1):
line = line.strip()
if not line or line.startswith('#'):
continue
# Is it an option line, ... | [
"def",
"_load_wordlist",
"(",
"name",
",",
"stream",
")",
":",
"items",
"=",
"[",
"]",
"max_length",
"=",
"None",
"multiword",
"=",
"False",
"multiword_start",
"=",
"None",
"number_of_words",
"=",
"None",
"for",
"i",
",",
"line",
"in",
"enumerate",
"(",
... | Loads list of words or phrases from file.
Returns "words" or "phrases" dictionary, the same as used in config.
Raises Exception if file is missing or invalid. | [
"Loads",
"list",
"of",
"words",
"or",
"phrases",
"from",
"file",
"."
] | 416cc39254ab9e921fd5be77dfe6cdafbad0300c | https://github.com/alexanderlukanin13/coolname/blob/416cc39254ab9e921fd5be77dfe6cdafbad0300c/coolname/loader.py#L110-L182 |
2,937 | alexanderlukanin13/coolname | coolname/impl.py | _create_lists | def _create_lists(config, results, current, stack, inside_cartesian=None):
"""
An ugly recursive method to transform config dict
into a tree of AbstractNestedList.
"""
# Have we done it already?
try:
return results[current]
except KeyError:
pass
# Check recursion depth an... | python | def _create_lists(config, results, current, stack, inside_cartesian=None):
# Have we done it already?
try:
return results[current]
except KeyError:
pass
# Check recursion depth and detect loops
if current in stack:
raise ConfigurationError('Rule {!r} is recursive: {!r}'.forma... | [
"def",
"_create_lists",
"(",
"config",
",",
"results",
",",
"current",
",",
"stack",
",",
"inside_cartesian",
"=",
"None",
")",
":",
"# Have we done it already?",
"try",
":",
"return",
"results",
"[",
"current",
"]",
"except",
"KeyError",
":",
"pass",
"# Check... | An ugly recursive method to transform config dict
into a tree of AbstractNestedList. | [
"An",
"ugly",
"recursive",
"method",
"to",
"transform",
"config",
"dict",
"into",
"a",
"tree",
"of",
"AbstractNestedList",
"."
] | 416cc39254ab9e921fd5be77dfe6cdafbad0300c | https://github.com/alexanderlukanin13/coolname/blob/416cc39254ab9e921fd5be77dfe6cdafbad0300c/coolname/impl.py#L508-L559 |
2,938 | alexanderlukanin13/coolname | coolname/impl.py | RandomGenerator.generate | def generate(self, pattern=None):
"""
Generates and returns random name as a list of strings.
"""
lst = self._lists[pattern]
while True:
result = lst[self._randrange(lst.length)]
# 1. Check that there are no duplicates
# 2. Check that there are... | python | def generate(self, pattern=None):
lst = self._lists[pattern]
while True:
result = lst[self._randrange(lst.length)]
# 1. Check that there are no duplicates
# 2. Check that there are no duplicate prefixes
# 3. Check max slug length
n = len(result... | [
"def",
"generate",
"(",
"self",
",",
"pattern",
"=",
"None",
")",
":",
"lst",
"=",
"self",
".",
"_lists",
"[",
"pattern",
"]",
"while",
"True",
":",
"result",
"=",
"lst",
"[",
"self",
".",
"_randrange",
"(",
"lst",
".",
"length",
")",
"]",
"# 1. Ch... | Generates and returns random name as a list of strings. | [
"Generates",
"and",
"returns",
"random",
"name",
"as",
"a",
"list",
"of",
"strings",
"."
] | 416cc39254ab9e921fd5be77dfe6cdafbad0300c | https://github.com/alexanderlukanin13/coolname/blob/416cc39254ab9e921fd5be77dfe6cdafbad0300c/coolname/impl.py#L306-L321 |
2,939 | alexanderlukanin13/coolname | coolname/impl.py | RandomGenerator._dump | def _dump(self, stream, pattern=None, object_ids=False):
"""Dumps current tree into a text stream."""
return self._lists[pattern]._dump(stream, '', object_ids=object_ids) | python | def _dump(self, stream, pattern=None, object_ids=False):
return self._lists[pattern]._dump(stream, '', object_ids=object_ids) | [
"def",
"_dump",
"(",
"self",
",",
"stream",
",",
"pattern",
"=",
"None",
",",
"object_ids",
"=",
"False",
")",
":",
"return",
"self",
".",
"_lists",
"[",
"pattern",
"]",
".",
"_dump",
"(",
"stream",
",",
"''",
",",
"object_ids",
"=",
"object_ids",
")... | Dumps current tree into a text stream. | [
"Dumps",
"current",
"tree",
"into",
"a",
"text",
"stream",
"."
] | 416cc39254ab9e921fd5be77dfe6cdafbad0300c | https://github.com/alexanderlukanin13/coolname/blob/416cc39254ab9e921fd5be77dfe6cdafbad0300c/coolname/impl.py#L337-L339 |
2,940 | kvesteri/postgresql-audit | postgresql_audit/migrations.py | alter_column | def alter_column(conn, table, column_name, func, schema=None):
"""
Run given callable against given table and given column in activity table
jsonb data columns. This function is useful when you want to reflect type
changes in your schema to activity table.
In the following example we change the dat... | python | def alter_column(conn, table, column_name, func, schema=None):
activity_table = get_activity_table(schema=schema)
query = (
activity_table
.update()
.values(
old_data=(
activity_table.c.old_data +
sa.cast(sa.func.json_build_object(
... | [
"def",
"alter_column",
"(",
"conn",
",",
"table",
",",
"column_name",
",",
"func",
",",
"schema",
"=",
"None",
")",
":",
"activity_table",
"=",
"get_activity_table",
"(",
"schema",
"=",
"schema",
")",
"query",
"=",
"(",
"activity_table",
".",
"update",
"("... | Run given callable against given table and given column in activity table
jsonb data columns. This function is useful when you want to reflect type
changes in your schema to activity table.
In the following example we change the data type of User's age column from
string to integer.
::
f... | [
"Run",
"given",
"callable",
"against",
"given",
"table",
"and",
"given",
"column",
"in",
"activity",
"table",
"jsonb",
"data",
"columns",
".",
"This",
"function",
"is",
"useful",
"when",
"you",
"want",
"to",
"reflect",
"type",
"changes",
"in",
"your",
"schem... | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/migrations.py#L20-L93 |
2,941 | kvesteri/postgresql-audit | postgresql_audit/migrations.py | change_column_name | def change_column_name(
conn,
table,
old_column_name,
new_column_name,
schema=None
):
"""
Changes given `activity` jsonb data column key. This function is useful
when you want to reflect column name changes to activity table.
::
from alembic import op
from postgresq... | python | def change_column_name(
conn,
table,
old_column_name,
new_column_name,
schema=None
):
activity_table = get_activity_table(schema=schema)
query = (
activity_table
.update()
.values(
old_data=jsonb_change_key_name(
activity_table.c.old_data,
... | [
"def",
"change_column_name",
"(",
"conn",
",",
"table",
",",
"old_column_name",
",",
"new_column_name",
",",
"schema",
"=",
"None",
")",
":",
"activity_table",
"=",
"get_activity_table",
"(",
"schema",
"=",
"schema",
")",
"query",
"=",
"(",
"activity_table",
"... | Changes given `activity` jsonb data column key. This function is useful
when you want to reflect column name changes to activity table.
::
from alembic import op
from postgresql_audit import change_column_name
def upgrade():
op.alter_column(
'my_table',
... | [
"Changes",
"given",
"activity",
"jsonb",
"data",
"column",
"key",
".",
"This",
"function",
"is",
"useful",
"when",
"you",
"want",
"to",
"reflect",
"column",
"name",
"changes",
"to",
"activity",
"table",
"."
] | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/migrations.py#L96-L153 |
2,942 | kvesteri/postgresql-audit | postgresql_audit/migrations.py | add_column | def add_column(conn, table, column_name, default_value=None, schema=None):
"""
Adds given column to `activity` table jsonb data columns.
In the following example we reflect the changes made to our schema to
activity table.
::
import sqlalchemy as sa
from alembic import op
... | python | def add_column(conn, table, column_name, default_value=None, schema=None):
activity_table = get_activity_table(schema=schema)
data = {column_name: default_value}
query = (
activity_table
.update()
.values(
old_data=sa.case(
[
(
... | [
"def",
"add_column",
"(",
"conn",
",",
"table",
",",
"column_name",
",",
"default_value",
"=",
"None",
",",
"schema",
"=",
"None",
")",
":",
"activity_table",
"=",
"get_activity_table",
"(",
"schema",
"=",
"schema",
")",
"data",
"=",
"{",
"column_name",
":... | Adds given column to `activity` table jsonb data columns.
In the following example we reflect the changes made to our schema to
activity table.
::
import sqlalchemy as sa
from alembic import op
from postgresql_audit import add_column
def upgrade():
op.add_col... | [
"Adds",
"given",
"column",
"to",
"activity",
"table",
"jsonb",
"data",
"columns",
"."
] | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/migrations.py#L156-L220 |
2,943 | kvesteri/postgresql-audit | postgresql_audit/migrations.py | remove_column | def remove_column(conn, table, column_name, schema=None):
"""
Removes given `activity` jsonb data column key. This function is useful
when you are doing schema changes that require removing a column.
Let's say you've been using PostgreSQL-Audit for a while for a table called
article. Now you want t... | python | def remove_column(conn, table, column_name, schema=None):
activity_table = get_activity_table(schema=schema)
remove = sa.cast(column_name, sa.Text)
query = (
activity_table
.update()
.values(
old_data=activity_table.c.old_data - remove,
changed_data=activity_t... | [
"def",
"remove_column",
"(",
"conn",
",",
"table",
",",
"column_name",
",",
"schema",
"=",
"None",
")",
":",
"activity_table",
"=",
"get_activity_table",
"(",
"schema",
"=",
"schema",
")",
"remove",
"=",
"sa",
".",
"cast",
"(",
"column_name",
",",
"sa",
... | Removes given `activity` jsonb data column key. This function is useful
when you are doing schema changes that require removing a column.
Let's say you've been using PostgreSQL-Audit for a while for a table called
article. Now you want to remove one audited column called 'created_at' from
this table.
... | [
"Removes",
"given",
"activity",
"jsonb",
"data",
"column",
"key",
".",
"This",
"function",
"is",
"useful",
"when",
"you",
"are",
"doing",
"schema",
"changes",
"that",
"require",
"removing",
"a",
"column",
"."
] | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/migrations.py#L223-L264 |
2,944 | kvesteri/postgresql-audit | postgresql_audit/migrations.py | rename_table | def rename_table(conn, old_table_name, new_table_name, schema=None):
"""
Renames given table in activity table. You should remember to call this
function whenever you rename a versioned table.
::
from alembic import op
from postgresql_audit import rename_table
def upgrade():
... | python | def rename_table(conn, old_table_name, new_table_name, schema=None):
activity_table = get_activity_table(schema=schema)
query = (
activity_table
.update()
.values(table_name=new_table_name)
.where(activity_table.c.table_name == old_table_name)
)
return conn.execute(query) | [
"def",
"rename_table",
"(",
"conn",
",",
"old_table_name",
",",
"new_table_name",
",",
"schema",
"=",
"None",
")",
":",
"activity_table",
"=",
"get_activity_table",
"(",
"schema",
"=",
"schema",
")",
"query",
"=",
"(",
"activity_table",
".",
"update",
"(",
"... | Renames given table in activity table. You should remember to call this
function whenever you rename a versioned table.
::
from alembic import op
from postgresql_audit import rename_table
def upgrade():
op.rename_table('article', 'article_v2')
rename_table(op,... | [
"Renames",
"given",
"table",
"in",
"activity",
"table",
".",
"You",
"should",
"remember",
"to",
"call",
"this",
"function",
"whenever",
"you",
"rename",
"a",
"versioned",
"table",
"."
] | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/migrations.py#L267-L300 |
2,945 | kvesteri/postgresql-audit | postgresql_audit/base.py | VersioningManager.instrument_versioned_classes | def instrument_versioned_classes(self, mapper, cls):
"""
Collect versioned class and add it to pending_classes list.
:mapper mapper: SQLAlchemy mapper object
:cls cls: SQLAlchemy declarative class
"""
if hasattr(cls, '__versioned__') and cls not in self.pending_classes:
... | python | def instrument_versioned_classes(self, mapper, cls):
if hasattr(cls, '__versioned__') and cls not in self.pending_classes:
self.pending_classes.add(cls) | [
"def",
"instrument_versioned_classes",
"(",
"self",
",",
"mapper",
",",
"cls",
")",
":",
"if",
"hasattr",
"(",
"cls",
",",
"'__versioned__'",
")",
"and",
"cls",
"not",
"in",
"self",
".",
"pending_classes",
":",
"self",
".",
"pending_classes",
".",
"add",
"... | Collect versioned class and add it to pending_classes list.
:mapper mapper: SQLAlchemy mapper object
:cls cls: SQLAlchemy declarative class | [
"Collect",
"versioned",
"class",
"and",
"add",
"it",
"to",
"pending_classes",
"list",
"."
] | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/base.py#L346-L354 |
2,946 | kvesteri/postgresql-audit | postgresql_audit/base.py | VersioningManager.configure_versioned_classes | def configure_versioned_classes(self):
"""
Configures all versioned classes that were collected during
instrumentation process.
"""
for cls in self.pending_classes:
self.audit_table(cls.__table__, cls.__versioned__.get('exclude'))
assign_actor(self.base, self.... | python | def configure_versioned_classes(self):
for cls in self.pending_classes:
self.audit_table(cls.__table__, cls.__versioned__.get('exclude'))
assign_actor(self.base, self.transaction_cls, self.actor_cls) | [
"def",
"configure_versioned_classes",
"(",
"self",
")",
":",
"for",
"cls",
"in",
"self",
".",
"pending_classes",
":",
"self",
".",
"audit_table",
"(",
"cls",
".",
"__table__",
",",
"cls",
".",
"__versioned__",
".",
"get",
"(",
"'exclude'",
")",
")",
"assig... | Configures all versioned classes that were collected during
instrumentation process. | [
"Configures",
"all",
"versioned",
"classes",
"that",
"were",
"collected",
"during",
"instrumentation",
"process",
"."
] | 91b497ced2e04dd44bb757b02983d2a64a2b1514 | https://github.com/kvesteri/postgresql-audit/blob/91b497ced2e04dd44bb757b02983d2a64a2b1514/postgresql_audit/base.py#L356-L363 |
2,947 | mfcovington/pubmed-lookup | pubmed_lookup/command_line.py | pubmed_citation | def pubmed_citation(args=sys.argv[1:], out=sys.stdout):
"""Get a citation via the command line using a PubMed ID or PubMed URL"""
parser = argparse.ArgumentParser(
description='Get a citation using a PubMed ID or PubMed URL')
parser.add_argument('query', help='PubMed ID or PubMed URL')
parser.a... | python | def pubmed_citation(args=sys.argv[1:], out=sys.stdout):
parser = argparse.ArgumentParser(
description='Get a citation using a PubMed ID or PubMed URL')
parser.add_argument('query', help='PubMed ID or PubMed URL')
parser.add_argument(
'-m', '--mini', action='store_true', help='get mini citati... | [
"def",
"pubmed_citation",
"(",
"args",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
",",
"out",
"=",
"sys",
".",
"stdout",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Get a citation using a PubMed ID or PubMed URL'",
... | Get a citation via the command line using a PubMed ID or PubMed URL | [
"Get",
"a",
"citation",
"via",
"the",
"command",
"line",
"using",
"a",
"PubMed",
"ID",
"or",
"PubMed",
"URL"
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/command_line.py#L7-L26 |
2,948 | mfcovington/pubmed-lookup | pubmed_lookup/command_line.py | pubmed_url | def pubmed_url(args=sys.argv[1:], resolve_doi=True, out=sys.stdout):
"""
Get a publication URL via the command line using a PubMed ID or PubMed URL
"""
parser = argparse.ArgumentParser(
description='Get a publication URL using a PubMed ID or PubMed URL')
parser.add_argument('query', help='P... | python | def pubmed_url(args=sys.argv[1:], resolve_doi=True, out=sys.stdout):
parser = argparse.ArgumentParser(
description='Get a publication URL using a PubMed ID or PubMed URL')
parser.add_argument('query', help='PubMed ID or PubMed URL')
parser.add_argument(
'-d', '--doi', action='store_false', h... | [
"def",
"pubmed_url",
"(",
"args",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
",",
"resolve_doi",
"=",
"True",
",",
"out",
"=",
"sys",
".",
"stdout",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Get a publicat... | Get a publication URL via the command line using a PubMed ID or PubMed URL | [
"Get",
"a",
"publication",
"URL",
"via",
"the",
"command",
"line",
"using",
"a",
"PubMed",
"ID",
"or",
"PubMed",
"URL"
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/command_line.py#L29-L47 |
2,949 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | Publication.authors_et_al | def authors_et_al(self, max_authors=5):
"""
Return string with a truncated author list followed by 'et al.'
"""
author_list = self._author_list
if len(author_list) <= max_authors:
authors_et_al = self.authors
else:
authors_et_al = ", ".join(
... | python | def authors_et_al(self, max_authors=5):
author_list = self._author_list
if len(author_list) <= max_authors:
authors_et_al = self.authors
else:
authors_et_al = ", ".join(
self._author_list[:max_authors]) + ", et al."
return authors_et_al | [
"def",
"authors_et_al",
"(",
"self",
",",
"max_authors",
"=",
"5",
")",
":",
"author_list",
"=",
"self",
".",
"_author_list",
"if",
"len",
"(",
"author_list",
")",
"<=",
"max_authors",
":",
"authors_et_al",
"=",
"self",
".",
"authors",
"else",
":",
"author... | Return string with a truncated author list followed by 'et al.' | [
"Return",
"string",
"with",
"a",
"truncated",
"author",
"list",
"followed",
"by",
"et",
"al",
"."
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L48-L58 |
2,950 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | Publication.parse_abstract | def parse_abstract(xml_dict):
"""
Parse PubMed XML dictionary to retrieve abstract.
"""
key_path = ['PubmedArticleSet', 'PubmedArticle', 'MedlineCitation',
'Article', 'Abstract', 'AbstractText']
abstract_xml = reduce(dict.get, key_path, xml_dict)
abst... | python | def parse_abstract(xml_dict):
key_path = ['PubmedArticleSet', 'PubmedArticle', 'MedlineCitation',
'Article', 'Abstract', 'AbstractText']
abstract_xml = reduce(dict.get, key_path, xml_dict)
abstract_paragraphs = []
if isinstance(abstract_xml, str):
abstra... | [
"def",
"parse_abstract",
"(",
"xml_dict",
")",
":",
"key_path",
"=",
"[",
"'PubmedArticleSet'",
",",
"'PubmedArticle'",
",",
"'MedlineCitation'",
",",
"'Article'",
",",
"'Abstract'",
",",
"'AbstractText'",
"]",
"abstract_xml",
"=",
"reduce",
"(",
"dict",
".",
"g... | Parse PubMed XML dictionary to retrieve abstract. | [
"Parse",
"PubMed",
"XML",
"dictionary",
"to",
"retrieve",
"abstract",
"."
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L107-L148 |
2,951 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | Publication.get_pubmed_xml | def get_pubmed_xml(self):
"""
Use a PubMed ID to retrieve PubMed metadata in XML form.
"""
url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/' \
'efetch.fcgi?db=pubmed&rettype=abstract&id={}' \
.format(self.pmid)
try:
response = urlopen(... | python | def get_pubmed_xml(self):
url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/' \
'efetch.fcgi?db=pubmed&rettype=abstract&id={}' \
.format(self.pmid)
try:
response = urlopen(url)
except URLError:
xml_dict = ''
else:
xml = r... | [
"def",
"get_pubmed_xml",
"(",
"self",
")",
":",
"url",
"=",
"'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/'",
"'efetch.fcgi?db=pubmed&rettype=abstract&id={}'",
".",
"format",
"(",
"self",
".",
"pmid",
")",
"try",
":",
"response",
"=",
"urlopen",
"(",
"url",
")",
"e... | Use a PubMed ID to retrieve PubMed metadata in XML form. | [
"Use",
"a",
"PubMed",
"ID",
"to",
"retrieve",
"PubMed",
"metadata",
"in",
"XML",
"form",
"."
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L150-L166 |
2,952 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | Publication.set_abstract | def set_abstract(self, xml_dict):
"""
If record has an abstract, extract it from PubMed's XML data
"""
if self.record.get('HasAbstract') == 1 and xml_dict:
self.abstract = self.parse_abstract(xml_dict)
else:
self.abstract = '' | python | def set_abstract(self, xml_dict):
if self.record.get('HasAbstract') == 1 and xml_dict:
self.abstract = self.parse_abstract(xml_dict)
else:
self.abstract = '' | [
"def",
"set_abstract",
"(",
"self",
",",
"xml_dict",
")",
":",
"if",
"self",
".",
"record",
".",
"get",
"(",
"'HasAbstract'",
")",
"==",
"1",
"and",
"xml_dict",
":",
"self",
".",
"abstract",
"=",
"self",
".",
"parse_abstract",
"(",
"xml_dict",
")",
"el... | If record has an abstract, extract it from PubMed's XML data | [
"If",
"record",
"has",
"an",
"abstract",
"extract",
"it",
"from",
"PubMed",
"s",
"XML",
"data"
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L168-L175 |
2,953 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | Publication.set_article_url | def set_article_url(self, resolve_doi=True):
"""
If record has a DOI, set article URL based on where the DOI points.
"""
if 'DOI' in self.record:
doi_url = "/".join(['http://dx.doi.org', self.record['DOI']])
if resolve_doi:
try:
... | python | def set_article_url(self, resolve_doi=True):
if 'DOI' in self.record:
doi_url = "/".join(['http://dx.doi.org', self.record['DOI']])
if resolve_doi:
try:
response = urlopen(doi_url)
except URLError:
self.url = ''
... | [
"def",
"set_article_url",
"(",
"self",
",",
"resolve_doi",
"=",
"True",
")",
":",
"if",
"'DOI'",
"in",
"self",
".",
"record",
":",
"doi_url",
"=",
"\"/\"",
".",
"join",
"(",
"[",
"'http://dx.doi.org'",
",",
"self",
".",
"record",
"[",
"'DOI'",
"]",
"]"... | If record has a DOI, set article URL based on where the DOI points. | [
"If",
"record",
"has",
"a",
"DOI",
"set",
"article",
"URL",
"based",
"on",
"where",
"the",
"DOI",
"points",
"."
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L177-L195 |
2,954 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | Publication.set_pub_year_month_day | def set_pub_year_month_day(self, xml_dict):
"""
Set publication year, month, day from PubMed's XML data
"""
key_path = ['PubmedArticleSet', 'PubmedArticle', 'MedlineCitation',
'Article', 'Journal', 'JournalIssue', 'PubDate']
pubdate_xml = reduce(dict.get, key_... | python | def set_pub_year_month_day(self, xml_dict):
key_path = ['PubmedArticleSet', 'PubmedArticle', 'MedlineCitation',
'Article', 'Journal', 'JournalIssue', 'PubDate']
pubdate_xml = reduce(dict.get, key_path, xml_dict)
if isinstance(pubdate_xml, dict):
self.year = pubda... | [
"def",
"set_pub_year_month_day",
"(",
"self",
",",
"xml_dict",
")",
":",
"key_path",
"=",
"[",
"'PubmedArticleSet'",
",",
"'PubmedArticle'",
",",
"'MedlineCitation'",
",",
"'Article'",
",",
"'Journal'",
",",
"'JournalIssue'",
",",
"'PubDate'",
"]",
"pubdate_xml",
... | Set publication year, month, day from PubMed's XML data | [
"Set",
"publication",
"year",
"month",
"day",
"from",
"PubMed",
"s",
"XML",
"data"
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L197-L219 |
2,955 | mfcovington/pubmed-lookup | pubmed_lookup/pubmed_lookup.py | PubMedLookup.get_pubmed_record | def get_pubmed_record(pmid):
"""Get PubMed record from PubMed ID."""
handle = Entrez.esummary(db="pubmed", id=pmid)
record = Entrez.read(handle)
return record | python | def get_pubmed_record(pmid):
handle = Entrez.esummary(db="pubmed", id=pmid)
record = Entrez.read(handle)
return record | [
"def",
"get_pubmed_record",
"(",
"pmid",
")",
":",
"handle",
"=",
"Entrez",
".",
"esummary",
"(",
"db",
"=",
"\"pubmed\"",
",",
"id",
"=",
"pmid",
")",
"record",
"=",
"Entrez",
".",
"read",
"(",
"handle",
")",
"return",
"record"
] | Get PubMed record from PubMed ID. | [
"Get",
"PubMed",
"record",
"from",
"PubMed",
"ID",
"."
] | b0aa2945b354f0945db73da22dd15ea628212da8 | https://github.com/mfcovington/pubmed-lookup/blob/b0aa2945b354f0945db73da22dd15ea628212da8/pubmed_lookup/pubmed_lookup.py#L257-L261 |
2,956 | UCSBarchlab/PyRTL | pyrtl/simulation.py | Simulation._initialize | def _initialize(self, register_value_map=None, memory_value_map=None, default_value=None):
""" Sets the wire, register, and memory values to default or as specified.
:param register_value_map: is a map of {Register: value}.
:param memory_value_map: is a map of maps {Memory: {address: Value}}.
... | python | def _initialize(self, register_value_map=None, memory_value_map=None, default_value=None):
if default_value is None:
default_value = self.default_value
# set registers to their values
reg_set = self.block.wirevector_subset(Register)
if register_value_map is not None:
... | [
"def",
"_initialize",
"(",
"self",
",",
"register_value_map",
"=",
"None",
",",
"memory_value_map",
"=",
"None",
",",
"default_value",
"=",
"None",
")",
":",
"if",
"default_value",
"is",
"None",
":",
"default_value",
"=",
"self",
".",
"default_value",
"# set r... | Sets the wire, register, and memory values to default or as specified.
:param register_value_map: is a map of {Register: value}.
:param memory_value_map: is a map of maps {Memory: {address: Value}}.
:param default_value: is the value that all unspecified registers and memories will
def... | [
"Sets",
"the",
"wire",
"register",
"and",
"memory",
"values",
"to",
"default",
"or",
"as",
"specified",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L96-L150 |
2,957 | UCSBarchlab/PyRTL | pyrtl/simulation.py | Simulation.step | def step(self, provided_inputs):
""" Take the simulation forward one cycle
:param provided_inputs: a dictionary mapping wirevectors to their values for this step
All input wires must be in the provided_inputs in order for the simulation
to accept these values
Example: if we ha... | python | def step(self, provided_inputs):
# Check that all Input have a corresponding provided_input
input_set = self.block.wirevector_subset(Input)
supplied_inputs = set()
for i in provided_inputs:
if isinstance(i, WireVector):
name = i.name
else:
... | [
"def",
"step",
"(",
"self",
",",
"provided_inputs",
")",
":",
"# Check that all Input have a corresponding provided_input",
"input_set",
"=",
"self",
".",
"block",
".",
"wirevector_subset",
"(",
"Input",
")",
"supplied_inputs",
"=",
"set",
"(",
")",
"for",
"i",
"i... | Take the simulation forward one cycle
:param provided_inputs: a dictionary mapping wirevectors to their values for this step
All input wires must be in the provided_inputs in order for the simulation
to accept these values
Example: if we have inputs named 'a' and 'x', we can call:
... | [
"Take",
"the",
"simulation",
"forward",
"one",
"cycle"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L152-L218 |
2,958 | UCSBarchlab/PyRTL | pyrtl/simulation.py | Simulation._execute | def _execute(self, net):
"""Handle the combinational logic update rules for the given net.
This function, along with edge_update, defined the semantics
of the primitive ops. Function updates self.value accordingly.
"""
if net.op in 'r@':
return # registers and memor... | python | def _execute(self, net):
if net.op in 'r@':
return # registers and memory write ports have no logic function
elif net.op in self.simple_func:
argvals = (self.value[arg] for arg in net.args)
result = self.simple_func[net.op](*argvals)
elif net.op == 'c':
... | [
"def",
"_execute",
"(",
"self",
",",
"net",
")",
":",
"if",
"net",
".",
"op",
"in",
"'r@'",
":",
"return",
"# registers and memory write ports have no logic function",
"elif",
"net",
".",
"op",
"in",
"self",
".",
"simple_func",
":",
"argvals",
"=",
"(",
"sel... | Handle the combinational logic update rules for the given net.
This function, along with edge_update, defined the semantics
of the primitive ops. Function updates self.value accordingly. | [
"Handle",
"the",
"combinational",
"logic",
"update",
"rules",
"for",
"the",
"given",
"net",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L253-L286 |
2,959 | UCSBarchlab/PyRTL | pyrtl/simulation.py | FastSimulation.step | def step(self, provided_inputs):
""" Run the simulation for a cycle
:param provided_inputs: a dictionary mapping WireVectors (or their names)
to their values for this step
eg: {wire: 3, "wire_name": 17}
"""
# validate_inputs
for wire, value in provided_inputs... | python | def step(self, provided_inputs):
# validate_inputs
for wire, value in provided_inputs.items():
wire = self.block.get_wirevector_by_name(wire) if isinstance(wire, str) else wire
if value > wire.bitmask or value < 0:
raise PyrtlError("Wire {} has value {} which cann... | [
"def",
"step",
"(",
"self",
",",
"provided_inputs",
")",
":",
"# validate_inputs",
"for",
"wire",
",",
"value",
"in",
"provided_inputs",
".",
"items",
"(",
")",
":",
"wire",
"=",
"self",
".",
"block",
".",
"get_wirevector_by_name",
"(",
"wire",
")",
"if",
... | Run the simulation for a cycle
:param provided_inputs: a dictionary mapping WireVectors (or their names)
to their values for this step
eg: {wire: 3, "wire_name": 17} | [
"Run",
"the",
"simulation",
"for",
"a",
"cycle"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L404-L436 |
2,960 | UCSBarchlab/PyRTL | pyrtl/simulation.py | FastSimulation.inspect_mem | def inspect_mem(self, mem):
""" Get the values in a map during the current simulation cycle.
:param mem: the memory to inspect
:return: {address: value}
Note that this returns the current memory state. Modifying the dictonary
will also modify the state in the simulator
... | python | def inspect_mem(self, mem):
if isinstance(mem, RomBlock):
raise PyrtlError("ROM blocks are not stored in the simulation object")
return self.mems[self._mem_varname(mem)] | [
"def",
"inspect_mem",
"(",
"self",
",",
"mem",
")",
":",
"if",
"isinstance",
"(",
"mem",
",",
"RomBlock",
")",
":",
"raise",
"PyrtlError",
"(",
"\"ROM blocks are not stored in the simulation object\"",
")",
"return",
"self",
".",
"mems",
"[",
"self",
".",
"_me... | Get the values in a map during the current simulation cycle.
:param mem: the memory to inspect
:return: {address: value}
Note that this returns the current memory state. Modifying the dictonary
will also modify the state in the simulator | [
"Get",
"the",
"values",
"in",
"a",
"map",
"during",
"the",
"current",
"simulation",
"cycle",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L457-L468 |
2,961 | UCSBarchlab/PyRTL | pyrtl/simulation.py | FastSimulation._arg_varname | def _arg_varname(self, wire):
"""
Input, Const, and Registers have special input values
"""
if isinstance(wire, (Input, Register)):
return 'd[' + repr(wire.name) + ']' # passed in
elif isinstance(wire, Const):
return str(wire.val) # hardcoded
els... | python | def _arg_varname(self, wire):
if isinstance(wire, (Input, Register)):
return 'd[' + repr(wire.name) + ']' # passed in
elif isinstance(wire, Const):
return str(wire.val) # hardcoded
else:
return self._varname(wire) | [
"def",
"_arg_varname",
"(",
"self",
",",
"wire",
")",
":",
"if",
"isinstance",
"(",
"wire",
",",
"(",
"Input",
",",
"Register",
")",
")",
":",
"return",
"'d['",
"+",
"repr",
"(",
"wire",
".",
"name",
")",
"+",
"']'",
"# passed in",
"elif",
"isinstanc... | Input, Const, and Registers have special input values | [
"Input",
"Const",
"and",
"Registers",
"have",
"special",
"input",
"values"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L483-L492 |
2,962 | UCSBarchlab/PyRTL | pyrtl/simulation.py | _WaveRendererBase._render_val_with_prev | def _render_val_with_prev(self, w, n, current_val, symbol_len):
"""Return a string encoding the given value in a waveform.
:param w: The WireVector we are rendering to a waveform
:param n: An integer from 0 to segment_len-1
:param current_val: the value to be rendered
:param sym... | python | def _render_val_with_prev(self, w, n, current_val, symbol_len):
sl = symbol_len-1
if len(w) > 1:
out = self._revstart
if current_val != self.prior_val:
out += self._x + hex(current_val).rstrip('L').ljust(sl)[:sl]
elif n == 0:
out += hex... | [
"def",
"_render_val_with_prev",
"(",
"self",
",",
"w",
",",
"n",
",",
"current_val",
",",
"symbol_len",
")",
":",
"sl",
"=",
"symbol_len",
"-",
"1",
"if",
"len",
"(",
"w",
")",
">",
"1",
":",
"out",
"=",
"self",
".",
"_revstart",
"if",
"current_val",... | Return a string encoding the given value in a waveform.
:param w: The WireVector we are rendering to a waveform
:param n: An integer from 0 to segment_len-1
:param current_val: the value to be rendered
:param symbol_len: and integer for how big to draw the current value
Returns... | [
"Return",
"a",
"string",
"encoding",
"the",
"given",
"value",
"in",
"a",
"waveform",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L664-L694 |
2,963 | UCSBarchlab/PyRTL | pyrtl/simulation.py | SimulationTrace.add_step | def add_step(self, value_map):
""" Add the values in value_map to the end of the trace. """
if len(self.trace) == 0:
raise PyrtlError('error, simulation trace needs at least 1 signal to track '
'(by default, unnamed signals are not traced -- try either passing '
... | python | def add_step(self, value_map):
if len(self.trace) == 0:
raise PyrtlError('error, simulation trace needs at least 1 signal to track '
'(by default, unnamed signals are not traced -- try either passing '
'a name to a WireVector or setting a "wi... | [
"def",
"add_step",
"(",
"self",
",",
"value_map",
")",
":",
"if",
"len",
"(",
"self",
".",
"trace",
")",
"==",
"0",
":",
"raise",
"PyrtlError",
"(",
"'error, simulation trace needs at least 1 signal to track '",
"'(by default, unnamed signals are not traced -- try either ... | Add the values in value_map to the end of the trace. | [
"Add",
"the",
"values",
"in",
"value_map",
"to",
"the",
"end",
"of",
"the",
"trace",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L794-L803 |
2,964 | UCSBarchlab/PyRTL | pyrtl/simulation.py | SimulationTrace.add_fast_step | def add_fast_step(self, fastsim):
""" Add the fastsim context to the trace. """
for wire_name in self.trace:
self.trace[wire_name].append(fastsim.context[wire_name]) | python | def add_fast_step(self, fastsim):
for wire_name in self.trace:
self.trace[wire_name].append(fastsim.context[wire_name]) | [
"def",
"add_fast_step",
"(",
"self",
",",
"fastsim",
")",
":",
"for",
"wire_name",
"in",
"self",
".",
"trace",
":",
"self",
".",
"trace",
"[",
"wire_name",
"]",
".",
"append",
"(",
"fastsim",
".",
"context",
"[",
"wire_name",
"]",
")"
] | Add the fastsim context to the trace. | [
"Add",
"the",
"fastsim",
"context",
"to",
"the",
"trace",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L810-L813 |
2,965 | UCSBarchlab/PyRTL | pyrtl/simulation.py | SimulationTrace.print_vcd | def print_vcd(self, file=sys.stdout, include_clock=False):
""" Print the trace out as a VCD File for use in other tools.
:param file: file to open and output vcd dump to.
:param include_clock: boolean specifying if the implicit clk should be included.
Dumps the current trace to file as... | python | def print_vcd(self, file=sys.stdout, include_clock=False):
# dump header info
# file_timestamp = time.strftime("%a, %d %b %Y %H:%M:%S (UTC/GMT)", time.gmtime())
# print >>file, " ".join(["$date", file_timestamp, "$end"])
self.internal_names = _VerilogSanitizer('_vcd_tmp_')
for wi... | [
"def",
"print_vcd",
"(",
"self",
",",
"file",
"=",
"sys",
".",
"stdout",
",",
"include_clock",
"=",
"False",
")",
":",
"# dump header info",
"# file_timestamp = time.strftime(\"%a, %d %b %Y %H:%M:%S (UTC/GMT)\", time.gmtime())",
"# print >>file, \" \".join([\"$date\", file_timest... | Print the trace out as a VCD File for use in other tools.
:param file: file to open and output vcd dump to.
:param include_clock: boolean specifying if the implicit clk should be included.
Dumps the current trace to file as a "value change dump" file. The file parameter
defaults to _s... | [
"Print",
"the",
"trace",
"out",
"as",
"a",
"VCD",
"File",
"for",
"use",
"in",
"other",
"tools",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L843-L899 |
2,966 | UCSBarchlab/PyRTL | pyrtl/simulation.py | SimulationTrace.render_trace | def render_trace(
self, trace_list=None, file=sys.stdout, render_cls=default_renderer(),
symbol_len=5, segment_size=5, segment_delim=' ', extra_line=True):
""" Render the trace to a file using unicode and ASCII escape sequences.
:param trace_list: A list of signals to be output... | python | def render_trace(
self, trace_list=None, file=sys.stdout, render_cls=default_renderer(),
symbol_len=5, segment_size=5, segment_delim=' ', extra_line=True):
if _currently_in_ipython():
from IPython.display import display, HTML, Javascript # pylint: disable=import-error
... | [
"def",
"render_trace",
"(",
"self",
",",
"trace_list",
"=",
"None",
",",
"file",
"=",
"sys",
".",
"stdout",
",",
"render_cls",
"=",
"default_renderer",
"(",
")",
",",
"symbol_len",
"=",
"5",
",",
"segment_size",
"=",
"5",
",",
"segment_delim",
"=",
"' '"... | Render the trace to a file using unicode and ASCII escape sequences.
:param trace_list: A list of signals to be output in the specified order.
:param file: The place to write output, default to stdout.
:param render_cls: A class that translates traces into output bytes.
:param symbol_le... | [
"Render",
"the",
"trace",
"to",
"a",
"file",
"using",
"unicode",
"and",
"ASCII",
"escape",
"sequences",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/simulation.py#L901-L941 |
2,967 | UCSBarchlab/PyRTL | pyrtl/rtllib/muxes.py | prioritized_mux | def prioritized_mux(selects, vals):
"""
Returns the value in the first wire for which its select bit is 1
:param [WireVector] selects: a list of WireVectors signaling whether
a wire should be chosen
:param [WireVector] vals: values to return when the corresponding select
value is 1
... | python | def prioritized_mux(selects, vals):
if len(selects) != len(vals):
raise pyrtl.PyrtlError("Number of select and val signals must match")
if len(vals) == 0:
raise pyrtl.PyrtlError("Must have a signal to mux")
if len(vals) == 1:
return vals[0]
else:
half = len(vals) // 2
... | [
"def",
"prioritized_mux",
"(",
"selects",
",",
"vals",
")",
":",
"if",
"len",
"(",
"selects",
")",
"!=",
"len",
"(",
"vals",
")",
":",
"raise",
"pyrtl",
".",
"PyrtlError",
"(",
"\"Number of select and val signals must match\"",
")",
"if",
"len",
"(",
"vals",... | Returns the value in the first wire for which its select bit is 1
:param [WireVector] selects: a list of WireVectors signaling whether
a wire should be chosen
:param [WireVector] vals: values to return when the corresponding select
value is 1
:return: WireVector
If none of the items ar... | [
"Returns",
"the",
"value",
"in",
"the",
"first",
"wire",
"for",
"which",
"its",
"select",
"bit",
"is",
"1"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/muxes.py#L4-L26 |
2,968 | UCSBarchlab/PyRTL | pyrtl/rtllib/muxes.py | demux | def demux(select):
"""
Demultiplexes a wire of arbitrary bitwidth
:param WireVector select: indicates which wire to set on
:return (WireVector, ...): a tuple of wires corresponding to each demultiplexed wire
"""
if len(select) == 1:
return _demux_2(select)
wires = demux(select[:-1]... | python | def demux(select):
if len(select) == 1:
return _demux_2(select)
wires = demux(select[:-1])
sel = select[-1]
not_select = ~sel
zero_wires = tuple(not_select & w for w in wires)
one_wires = tuple(sel & w for w in wires)
return zero_wires + one_wires | [
"def",
"demux",
"(",
"select",
")",
":",
"if",
"len",
"(",
"select",
")",
"==",
"1",
":",
"return",
"_demux_2",
"(",
"select",
")",
"wires",
"=",
"demux",
"(",
"select",
"[",
":",
"-",
"1",
"]",
")",
"sel",
"=",
"select",
"[",
"-",
"1",
"]",
... | Demultiplexes a wire of arbitrary bitwidth
:param WireVector select: indicates which wire to set on
:return (WireVector, ...): a tuple of wires corresponding to each demultiplexed wire | [
"Demultiplexes",
"a",
"wire",
"of",
"arbitrary",
"bitwidth"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/muxes.py#L190-L205 |
2,969 | UCSBarchlab/PyRTL | pyrtl/rtllib/muxes.py | MultiSelector.finalize | def finalize(self):
"""
Connects the wires.
"""
self._check_finalized()
self._final = True
for dest_w, values in self.dest_instrs_info.items():
mux_vals = dict(zip(self.instructions, values))
dest_w <<= sparse_mux(self.signal_wire, mux_vals) | python | def finalize(self):
self._check_finalized()
self._final = True
for dest_w, values in self.dest_instrs_info.items():
mux_vals = dict(zip(self.instructions, values))
dest_w <<= sparse_mux(self.signal_wire, mux_vals) | [
"def",
"finalize",
"(",
"self",
")",
":",
"self",
".",
"_check_finalized",
"(",
")",
"self",
".",
"_final",
"=",
"True",
"for",
"dest_w",
",",
"values",
"in",
"self",
".",
"dest_instrs_info",
".",
"items",
"(",
")",
":",
"mux_vals",
"=",
"dict",
"(",
... | Connects the wires. | [
"Connects",
"the",
"wires",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/muxes.py#L178-L187 |
2,970 | UCSBarchlab/PyRTL | pyrtl/wire.py | WireVector.bitmask | def bitmask(self):
""" A property holding a bitmask of the same length as this WireVector.
Specifically it is an integer with a number of bits set to 1 equal to the
bitwidth of the WireVector.
It is often times useful to "mask" an integer such that it fits in the
the number of b... | python | def bitmask(self):
if "_bitmask" not in self.__dict__:
self._bitmask = (1 << len(self)) - 1
return self._bitmask | [
"def",
"bitmask",
"(",
"self",
")",
":",
"if",
"\"_bitmask\"",
"not",
"in",
"self",
".",
"__dict__",
":",
"self",
".",
"_bitmask",
"=",
"(",
"1",
"<<",
"len",
"(",
"self",
")",
")",
"-",
"1",
"return",
"self",
".",
"_bitmask"
] | A property holding a bitmask of the same length as this WireVector.
Specifically it is an integer with a number of bits set to 1 equal to the
bitwidth of the WireVector.
It is often times useful to "mask" an integer such that it fits in the
the number of bits of a WireVector. As a conv... | [
"A",
"property",
"holding",
"a",
"bitmask",
"of",
"the",
"same",
"length",
"as",
"this",
"WireVector",
".",
"Specifically",
"it",
"is",
"an",
"integer",
"with",
"a",
"number",
"of",
"bits",
"set",
"to",
"1",
"equal",
"to",
"the",
"bitwidth",
"of",
"the",... | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/wire.py#L427-L438 |
2,971 | usrlocalben/pydux | pydux/log_middleware.py | log_middleware | def log_middleware(store):
"""log all actions to console as they are dispatched"""
def wrapper(next_):
def log_dispatch(action):
print('Dispatch Action:', action)
return next_(action)
return log_dispatch
return wrapper | python | def log_middleware(store):
def wrapper(next_):
def log_dispatch(action):
print('Dispatch Action:', action)
return next_(action)
return log_dispatch
return wrapper | [
"def",
"log_middleware",
"(",
"store",
")",
":",
"def",
"wrapper",
"(",
"next_",
")",
":",
"def",
"log_dispatch",
"(",
"action",
")",
":",
"print",
"(",
"'Dispatch Action:'",
",",
"action",
")",
"return",
"next_",
"(",
"action",
")",
"return",
"log_dispatc... | log all actions to console as they are dispatched | [
"log",
"all",
"actions",
"to",
"console",
"as",
"they",
"are",
"dispatched"
] | 943ca1c75357b9289f55f17ff2d997a66a3313a4 | https://github.com/usrlocalben/pydux/blob/943ca1c75357b9289f55f17ff2d997a66a3313a4/pydux/log_middleware.py#L6-L13 |
2,972 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation.inspect | def inspect(self, w):
"""Get the latest value of the wire given, if possible."""
if isinstance(w, WireVector):
w = w.name
try:
vals = self.tracer.trace[w]
except KeyError:
pass
else:
if not vals:
raise PyrtlError('No... | python | def inspect(self, w):
if isinstance(w, WireVector):
w = w.name
try:
vals = self.tracer.trace[w]
except KeyError:
pass
else:
if not vals:
raise PyrtlError('No context available. Please run a simulation step')
retu... | [
"def",
"inspect",
"(",
"self",
",",
"w",
")",
":",
"if",
"isinstance",
"(",
"w",
",",
"WireVector",
")",
":",
"w",
"=",
"w",
".",
"name",
"try",
":",
"vals",
"=",
"self",
".",
"tracer",
".",
"trace",
"[",
"w",
"]",
"except",
"KeyError",
":",
"p... | Get the latest value of the wire given, if possible. | [
"Get",
"the",
"latest",
"value",
"of",
"the",
"wire",
"given",
"if",
"possible",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L110-L122 |
2,973 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation.run | def run(self, inputs):
"""Run many steps of the simulation.
The argument is a list of input mappings for each step,
and its length is the number of steps to be executed.
"""
steps = len(inputs)
# create i/o arrays of the appropriate length
ibuf_type = ctypes.c_ui... | python | def run(self, inputs):
steps = len(inputs)
# create i/o arrays of the appropriate length
ibuf_type = ctypes.c_uint64*(steps*self._ibufsz)
obuf_type = ctypes.c_uint64*(steps*self._obufsz)
ibuf = ibuf_type()
obuf = obuf_type()
# these array will be passed to _crun
... | [
"def",
"run",
"(",
"self",
",",
"inputs",
")",
":",
"steps",
"=",
"len",
"(",
"inputs",
")",
"# create i/o arrays of the appropriate length",
"ibuf_type",
"=",
"ctypes",
".",
"c_uint64",
"*",
"(",
"steps",
"*",
"self",
".",
"_ibufsz",
")",
"obuf_type",
"=",
... | Run many steps of the simulation.
The argument is a list of input mappings for each step,
and its length is the number of steps to be executed. | [
"Run",
"many",
"steps",
"of",
"the",
"simulation",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L131-L188 |
2,974 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._traceable | def _traceable(self, wv):
"""Check if wv is able to be traced
If it is traceable due to a probe, record that probe in _probe_mapping.
"""
if isinstance(wv, (Input, Output)):
return True
for net in self.block.logic:
if net.op == 'w' and net.args[0].name ==... | python | def _traceable(self, wv):
if isinstance(wv, (Input, Output)):
return True
for net in self.block.logic:
if net.op == 'w' and net.args[0].name == wv.name and isinstance(net.dests[0], Output):
self._probe_mapping[wv.name] = net.dests[0].name
return Tr... | [
"def",
"_traceable",
"(",
"self",
",",
"wv",
")",
":",
"if",
"isinstance",
"(",
"wv",
",",
"(",
"Input",
",",
"Output",
")",
")",
":",
"return",
"True",
"for",
"net",
"in",
"self",
".",
"block",
".",
"logic",
":",
"if",
"net",
".",
"op",
"==",
... | Check if wv is able to be traced
If it is traceable due to a probe, record that probe in _probe_mapping. | [
"Check",
"if",
"wv",
"is",
"able",
"to",
"be",
"traced"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L190-L201 |
2,975 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._remove_untraceable | def _remove_untraceable(self):
"""Remove from the tracer those wires that CompiledSimulation cannot track.
Create _probe_mapping for wires only traceable via probes.
"""
self._probe_mapping = {}
wvs = {wv for wv in self.tracer.wires_to_track if self._traceable(wv)}
self.... | python | def _remove_untraceable(self):
self._probe_mapping = {}
wvs = {wv for wv in self.tracer.wires_to_track if self._traceable(wv)}
self.tracer.wires_to_track = wvs
self.tracer._wires = {wv.name: wv for wv in wvs}
self.tracer.trace.__init__(wvs) | [
"def",
"_remove_untraceable",
"(",
"self",
")",
":",
"self",
".",
"_probe_mapping",
"=",
"{",
"}",
"wvs",
"=",
"{",
"wv",
"for",
"wv",
"in",
"self",
".",
"tracer",
".",
"wires_to_track",
"if",
"self",
".",
"_traceable",
"(",
"wv",
")",
"}",
"self",
"... | Remove from the tracer those wires that CompiledSimulation cannot track.
Create _probe_mapping for wires only traceable via probes. | [
"Remove",
"from",
"the",
"tracer",
"those",
"wires",
"that",
"CompiledSimulation",
"cannot",
"track",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L203-L212 |
2,976 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._create_dll | def _create_dll(self):
"""Create a dynamically-linked library implementing the simulation logic."""
self._dir = tempfile.mkdtemp()
with open(path.join(self._dir, 'pyrtlsim.c'), 'w') as f:
self._create_code(lambda s: f.write(s+'\n'))
if platform.system() == 'Darwin':
... | python | def _create_dll(self):
self._dir = tempfile.mkdtemp()
with open(path.join(self._dir, 'pyrtlsim.c'), 'w') as f:
self._create_code(lambda s: f.write(s+'\n'))
if platform.system() == 'Darwin':
shared = '-dynamiclib'
else:
shared = '-shared'
subpro... | [
"def",
"_create_dll",
"(",
"self",
")",
":",
"self",
".",
"_dir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"with",
"open",
"(",
"path",
".",
"join",
"(",
"self",
".",
"_dir",
",",
"'pyrtlsim.c'",
")",
",",
"'w'",
")",
"as",
"f",
":",
"self",
".... | Create a dynamically-linked library implementing the simulation logic. | [
"Create",
"a",
"dynamically",
"-",
"linked",
"library",
"implementing",
"the",
"simulation",
"logic",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L214-L230 |
2,977 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._makeini | def _makeini(self, w, v):
"""C initializer string for a wire with a given value."""
pieces = []
for n in range(self._limbs(w)):
pieces.append(hex(v & ((1 << 64)-1)))
v >>= 64
return ','.join(pieces).join('{}') | python | def _makeini(self, w, v):
pieces = []
for n in range(self._limbs(w)):
pieces.append(hex(v & ((1 << 64)-1)))
v >>= 64
return ','.join(pieces).join('{}') | [
"def",
"_makeini",
"(",
"self",
",",
"w",
",",
"v",
")",
":",
"pieces",
"=",
"[",
"]",
"for",
"n",
"in",
"range",
"(",
"self",
".",
"_limbs",
"(",
"w",
")",
")",
":",
"pieces",
".",
"append",
"(",
"hex",
"(",
"v",
"&",
"(",
"(",
"1",
"<<",
... | C initializer string for a wire with a given value. | [
"C",
"initializer",
"string",
"for",
"a",
"wire",
"with",
"a",
"given",
"value",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L236-L242 |
2,978 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._makemask | def _makemask(self, dest, res, pos):
"""Create a bitmask.
The value being masked is of width `res`.
Limb number `pos` of `dest` is being assigned to.
"""
if (res is None or dest.bitwidth < res) and 0 < (dest.bitwidth - 64*pos) < 64:
return '&0x{:X}'.format((1 << (des... | python | def _makemask(self, dest, res, pos):
if (res is None or dest.bitwidth < res) and 0 < (dest.bitwidth - 64*pos) < 64:
return '&0x{:X}'.format((1 << (dest.bitwidth % 64))-1)
return '' | [
"def",
"_makemask",
"(",
"self",
",",
"dest",
",",
"res",
",",
"pos",
")",
":",
"if",
"(",
"res",
"is",
"None",
"or",
"dest",
".",
"bitwidth",
"<",
"res",
")",
"and",
"0",
"<",
"(",
"dest",
".",
"bitwidth",
"-",
"64",
"*",
"pos",
")",
"<",
"6... | Create a bitmask.
The value being masked is of width `res`.
Limb number `pos` of `dest` is being assigned to. | [
"Create",
"a",
"bitmask",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L257-L265 |
2,979 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._getarglimb | def _getarglimb(self, arg, n):
"""Get the nth limb of the given wire.
Returns '0' when the wire does not have sufficient limbs.
"""
return '{vn}[{n}]'.format(vn=self.varname[arg], n=n) if arg.bitwidth > 64*n else '0' | python | def _getarglimb(self, arg, n):
return '{vn}[{n}]'.format(vn=self.varname[arg], n=n) if arg.bitwidth > 64*n else '0' | [
"def",
"_getarglimb",
"(",
"self",
",",
"arg",
",",
"n",
")",
":",
"return",
"'{vn}[{n}]'",
".",
"format",
"(",
"vn",
"=",
"self",
".",
"varname",
"[",
"arg",
"]",
",",
"n",
"=",
"n",
")",
"if",
"arg",
".",
"bitwidth",
">",
"64",
"*",
"n",
"els... | Get the nth limb of the given wire.
Returns '0' when the wire does not have sufficient limbs. | [
"Get",
"the",
"nth",
"limb",
"of",
"the",
"given",
"wire",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L267-L272 |
2,980 | UCSBarchlab/PyRTL | pyrtl/compilesim.py | CompiledSimulation._clean_name | def _clean_name(self, prefix, obj):
"""Create a C variable name with the given prefix based on the name of obj."""
return '{}{}_{}'.format(prefix, self._uid(), ''.join(c for c in obj.name if c.isalnum())) | python | def _clean_name(self, prefix, obj):
return '{}{}_{}'.format(prefix, self._uid(), ''.join(c for c in obj.name if c.isalnum())) | [
"def",
"_clean_name",
"(",
"self",
",",
"prefix",
",",
"obj",
")",
":",
"return",
"'{}{}_{}'",
".",
"format",
"(",
"prefix",
",",
"self",
".",
"_uid",
"(",
")",
",",
"''",
".",
"join",
"(",
"c",
"for",
"c",
"in",
"obj",
".",
"name",
"if",
"c",
... | Create a C variable name with the given prefix based on the name of obj. | [
"Create",
"a",
"C",
"variable",
"name",
"with",
"the",
"given",
"prefix",
"based",
"on",
"the",
"name",
"of",
"obj",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/compilesim.py#L274-L276 |
2,981 | UCSBarchlab/PyRTL | pyrtl/rtllib/multipliers.py | _trivial_mult | def _trivial_mult(A, B):
"""
turns a multiplication into an And gate if one of the
wires is a bitwidth of 1
:param A:
:param B:
:return:
"""
if len(B) == 1:
A, B = B, A # so that we can reuse the code below :)
if len(A) == 1:
a_vals = A.sign_extended(len(B))
... | python | def _trivial_mult(A, B):
if len(B) == 1:
A, B = B, A # so that we can reuse the code below :)
if len(A) == 1:
a_vals = A.sign_extended(len(B))
# keep the wirevector len consistent
return pyrtl.concat_list([a_vals & B, pyrtl.Const(0)]) | [
"def",
"_trivial_mult",
"(",
"A",
",",
"B",
")",
":",
"if",
"len",
"(",
"B",
")",
"==",
"1",
":",
"A",
",",
"B",
"=",
"B",
",",
"A",
"# so that we can reuse the code below :)",
"if",
"len",
"(",
"A",
")",
"==",
"1",
":",
"a_vals",
"=",
"A",
".",
... | turns a multiplication into an And gate if one of the
wires is a bitwidth of 1
:param A:
:param B:
:return: | [
"turns",
"a",
"multiplication",
"into",
"an",
"And",
"gate",
"if",
"one",
"of",
"the",
"wires",
"is",
"a",
"bitwidth",
"of",
"1"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/multipliers.py#L49-L64 |
2,982 | UCSBarchlab/PyRTL | pyrtl/rtllib/multipliers.py | tree_multiplier | def tree_multiplier(A, B, reducer=adders.wallace_reducer, adder_func=adders.kogge_stone):
""" Build an fast unclocked multiplier for inputs A and B using a Wallace or Dada Tree.
:param WireVector A, B: two input wires for the multiplication
:param function reducer: Reduce the tree using either a Dada recud... | python | def tree_multiplier(A, B, reducer=adders.wallace_reducer, adder_func=adders.kogge_stone):
"""
The two tree multipliers basically works by splitting the multiplication
into a series of many additions, and it works by applying 'reductions'.
"""
triv_res = _trivial_mult(A, B)
if triv_res is not Non... | [
"def",
"tree_multiplier",
"(",
"A",
",",
"B",
",",
"reducer",
"=",
"adders",
".",
"wallace_reducer",
",",
"adder_func",
"=",
"adders",
".",
"kogge_stone",
")",
":",
"\"\"\"\n The two tree multipliers basically works by splitting the multiplication\n into a series of man... | Build an fast unclocked multiplier for inputs A and B using a Wallace or Dada Tree.
:param WireVector A, B: two input wires for the multiplication
:param function reducer: Reduce the tree using either a Dada recuder or a Wallace reducer
determines whether it is a Wallace tree multiplier or a Dada tree mu... | [
"Build",
"an",
"fast",
"unclocked",
"multiplier",
"for",
"inputs",
"A",
"and",
"B",
"using",
"a",
"Wallace",
"or",
"Dada",
"Tree",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/multipliers.py#L125-L155 |
2,983 | UCSBarchlab/PyRTL | pyrtl/rtllib/multipliers.py | signed_tree_multiplier | def signed_tree_multiplier(A, B, reducer=adders.wallace_reducer, adder_func=adders.kogge_stone):
"""Same as tree_multiplier, but uses two's-complement signed integers"""
if len(A) == 1 or len(B) == 1:
raise pyrtl.PyrtlError("sign bit required, one or both wires too small")
aneg, bneg = A[-1], B[-1]... | python | def signed_tree_multiplier(A, B, reducer=adders.wallace_reducer, adder_func=adders.kogge_stone):
if len(A) == 1 or len(B) == 1:
raise pyrtl.PyrtlError("sign bit required, one or both wires too small")
aneg, bneg = A[-1], B[-1]
a = _twos_comp_conditional(A, aneg)
b = _twos_comp_conditional(B, bn... | [
"def",
"signed_tree_multiplier",
"(",
"A",
",",
"B",
",",
"reducer",
"=",
"adders",
".",
"wallace_reducer",
",",
"adder_func",
"=",
"adders",
".",
"kogge_stone",
")",
":",
"if",
"len",
"(",
"A",
")",
"==",
"1",
"or",
"len",
"(",
"B",
")",
"==",
"1",
... | Same as tree_multiplier, but uses two's-complement signed integers | [
"Same",
"as",
"tree_multiplier",
"but",
"uses",
"two",
"s",
"-",
"complement",
"signed",
"integers"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/multipliers.py#L158-L168 |
2,984 | UCSBarchlab/PyRTL | pyrtl/rtllib/multipliers.py | generalized_fma | def generalized_fma(mult_pairs, add_wires, signed=False, reducer=adders.wallace_reducer,
adder_func=adders.kogge_stone):
"""Generated an opimitized fused multiply adder.
A generalized FMA unit that multiplies each pair of numbers in mult_pairs,
then adds the resulting numbers and and th... | python | def generalized_fma(mult_pairs, add_wires, signed=False, reducer=adders.wallace_reducer,
adder_func=adders.kogge_stone):
# first need to figure out the max length
if mult_pairs: # Need to deal with the case when it is empty
mult_max = max(len(m[0]) + len(m[1]) - 1 for m in mult_pair... | [
"def",
"generalized_fma",
"(",
"mult_pairs",
",",
"add_wires",
",",
"signed",
"=",
"False",
",",
"reducer",
"=",
"adders",
".",
"wallace_reducer",
",",
"adder_func",
"=",
"adders",
".",
"kogge_stone",
")",
":",
"# first need to figure out the max length",
"if",
"m... | Generated an opimitized fused multiply adder.
A generalized FMA unit that multiplies each pair of numbers in mult_pairs,
then adds the resulting numbers and and the values of the add wires all
together to form an answer. This is faster than separate adders and
multipliers because you avoid unnecessary ... | [
"Generated",
"an",
"opimitized",
"fused",
"multiply",
"adder",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/rtllib/multipliers.py#L208-L258 |
2,985 | UCSBarchlab/PyRTL | pyrtl/transform.py | net_transform | def net_transform(transform_func, block=None, **kwargs):
"""
Maps nets to new sets of nets according to a custom function
:param transform_func:
Function signature: func(orig_net (logicnet)) -> keep_orig_net (bool)
:return:
"""
block = working_block(block)
with set_working_block(blo... | python | def net_transform(transform_func, block=None, **kwargs):
block = working_block(block)
with set_working_block(block, True):
for net in block.logic.copy():
keep_orig_net = transform_func(net, **kwargs)
if not keep_orig_net:
block.logic.remove(net) | [
"def",
"net_transform",
"(",
"transform_func",
",",
"block",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"block",
"=",
"working_block",
"(",
"block",
")",
"with",
"set_working_block",
"(",
"block",
",",
"True",
")",
":",
"for",
"net",
"in",
"block",
... | Maps nets to new sets of nets according to a custom function
:param transform_func:
Function signature: func(orig_net (logicnet)) -> keep_orig_net (bool)
:return: | [
"Maps",
"nets",
"to",
"new",
"sets",
"of",
"nets",
"according",
"to",
"a",
"custom",
"function"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L27-L40 |
2,986 | UCSBarchlab/PyRTL | pyrtl/transform.py | all_nets | def all_nets(transform_func):
"""Decorator that wraps a net transform function"""
@functools.wraps(transform_func)
def t_res(**kwargs):
net_transform(transform_func, **kwargs)
return t_res | python | def all_nets(transform_func):
@functools.wraps(transform_func)
def t_res(**kwargs):
net_transform(transform_func, **kwargs)
return t_res | [
"def",
"all_nets",
"(",
"transform_func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"transform_func",
")",
"def",
"t_res",
"(",
"*",
"*",
"kwargs",
")",
":",
"net_transform",
"(",
"transform_func",
",",
"*",
"*",
"kwargs",
")",
"return",
"t_res"
] | Decorator that wraps a net transform function | [
"Decorator",
"that",
"wraps",
"a",
"net",
"transform",
"function"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L43-L48 |
2,987 | UCSBarchlab/PyRTL | pyrtl/transform.py | wire_transform | def wire_transform(transform_func, select_types=WireVector,
exclude_types=(Input, Output, Register, Const), block=None):
"""
Maps Wires to new sets of nets and wires according to a custom function
:param transform_func: The function you want to run on all wires
Function signature... | python | def wire_transform(transform_func, select_types=WireVector,
exclude_types=(Input, Output, Register, Const), block=None):
block = working_block(block)
for orig_wire in block.wirevector_subset(select_types, exclude_types):
new_src, new_dst = transform_func(orig_wire)
replace_wir... | [
"def",
"wire_transform",
"(",
"transform_func",
",",
"select_types",
"=",
"WireVector",
",",
"exclude_types",
"=",
"(",
"Input",
",",
"Output",
",",
"Register",
",",
"Const",
")",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"working_block",
"(",
"bl... | Maps Wires to new sets of nets and wires according to a custom function
:param transform_func: The function you want to run on all wires
Function signature: func(orig_wire (WireVector)) -> src_wire, dst_wire
src_wire is the src for the stuff you made in the transform func
and dst_wire is th... | [
"Maps",
"Wires",
"to",
"new",
"sets",
"of",
"nets",
"and",
"wires",
"according",
"to",
"a",
"custom",
"function"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L51-L70 |
2,988 | UCSBarchlab/PyRTL | pyrtl/transform.py | all_wires | def all_wires(transform_func):
"""Decorator that wraps a wire transform function"""
@functools.wraps(transform_func)
def t_res(**kwargs):
wire_transform(transform_func, **kwargs)
return t_res | python | def all_wires(transform_func):
@functools.wraps(transform_func)
def t_res(**kwargs):
wire_transform(transform_func, **kwargs)
return t_res | [
"def",
"all_wires",
"(",
"transform_func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"transform_func",
")",
"def",
"t_res",
"(",
"*",
"*",
"kwargs",
")",
":",
"wire_transform",
"(",
"transform_func",
",",
"*",
"*",
"kwargs",
")",
"return",
"t_res"
] | Decorator that wraps a wire transform function | [
"Decorator",
"that",
"wraps",
"a",
"wire",
"transform",
"function"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L73-L78 |
2,989 | UCSBarchlab/PyRTL | pyrtl/transform.py | replace_wires | def replace_wires(wire_map, block=None):
"""
Quickly replace all wires in a block
:param {old_wire: new_wire} wire_map: mapping of old wires to
new wires
"""
block = working_block(block)
src_nets, dst_nets = block.net_connections(include_virtual_nodes=False)
for old_w, new_w in wire_m... | python | def replace_wires(wire_map, block=None):
block = working_block(block)
src_nets, dst_nets = block.net_connections(include_virtual_nodes=False)
for old_w, new_w in wire_map.items():
replace_wire_fast(old_w, new_w, new_w, src_nets, dst_nets, block) | [
"def",
"replace_wires",
"(",
"wire_map",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"working_block",
"(",
"block",
")",
"src_nets",
",",
"dst_nets",
"=",
"block",
".",
"net_connections",
"(",
"include_virtual_nodes",
"=",
"False",
")",
"for",
"old_w"... | Quickly replace all wires in a block
:param {old_wire: new_wire} wire_map: mapping of old wires to
new wires | [
"Quickly",
"replace",
"all",
"wires",
"in",
"a",
"block"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L109-L119 |
2,990 | UCSBarchlab/PyRTL | pyrtl/transform.py | clone_wire | def clone_wire(old_wire, name=None):
"""
Makes a copy of any existing wire
:param old_wire: The wire to clone
:param name: a name fo rhte new wire
Note that this function is mainly intended to be used when the
two wires are from different blocks. Making two wires with the
same name in the ... | python | def clone_wire(old_wire, name=None):
if isinstance(old_wire, Const):
return Const(old_wire.val, old_wire.bitwidth)
else:
if name is None:
return old_wire.__class__(old_wire.bitwidth, name=old_wire.name)
return old_wire.__class__(old_wire.bitwidth, name=name) | [
"def",
"clone_wire",
"(",
"old_wire",
",",
"name",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"old_wire",
",",
"Const",
")",
":",
"return",
"Const",
"(",
"old_wire",
".",
"val",
",",
"old_wire",
".",
"bitwidth",
")",
"else",
":",
"if",
"name",
"... | Makes a copy of any existing wire
:param old_wire: The wire to clone
:param name: a name fo rhte new wire
Note that this function is mainly intended to be used when the
two wires are from different blocks. Making two wires with the
same name in the same block is not allowed | [
"Makes",
"a",
"copy",
"of",
"any",
"existing",
"wire"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L166-L182 |
2,991 | UCSBarchlab/PyRTL | pyrtl/transform.py | copy_block | def copy_block(block=None, update_working_block=True):
"""
Makes a copy of an existing block
:param block: The block to clone. (defaults to the working block)
:return: The resulting block
"""
block_in = working_block(block)
block_out, temp_wv_map = _clone_block_and_wires(block_in)
mems ... | python | def copy_block(block=None, update_working_block=True):
block_in = working_block(block)
block_out, temp_wv_map = _clone_block_and_wires(block_in)
mems = {}
for net in block_in.logic:
_copy_net(block_out, net, temp_wv_map, mems)
block_out.mem_map = mems
if update_working_block:
se... | [
"def",
"copy_block",
"(",
"block",
"=",
"None",
",",
"update_working_block",
"=",
"True",
")",
":",
"block_in",
"=",
"working_block",
"(",
"block",
")",
"block_out",
",",
"temp_wv_map",
"=",
"_clone_block_and_wires",
"(",
"block_in",
")",
"mems",
"=",
"{",
"... | Makes a copy of an existing block
:param block: The block to clone. (defaults to the working block)
:return: The resulting block | [
"Makes",
"a",
"copy",
"of",
"an",
"existing",
"block"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L185-L201 |
2,992 | UCSBarchlab/PyRTL | pyrtl/transform.py | _clone_block_and_wires | def _clone_block_and_wires(block_in):
"""
This is a generic function to copy the WireVectors for another round of
synthesis This does not split a WireVector with multiple wires.
:param block_in: The block to change
:param synth_name: a name to prepend to all new copies of a wire
:return: the re... | python | def _clone_block_and_wires(block_in):
block_in.sanity_check() # make sure that everything is valid
block_out = block_in.__class__()
temp_wv_map = {}
with set_working_block(block_out, no_sanity_check=True):
for wirevector in block_in.wirevector_subset():
new_wv = clone_wire(wirevecto... | [
"def",
"_clone_block_and_wires",
"(",
"block_in",
")",
":",
"block_in",
".",
"sanity_check",
"(",
")",
"# make sure that everything is valid",
"block_out",
"=",
"block_in",
".",
"__class__",
"(",
")",
"temp_wv_map",
"=",
"{",
"}",
"with",
"set_working_block",
"(",
... | This is a generic function to copy the WireVectors for another round of
synthesis This does not split a WireVector with multiple wires.
:param block_in: The block to change
:param synth_name: a name to prepend to all new copies of a wire
:return: the resulting block and a WireVector map | [
"This",
"is",
"a",
"generic",
"function",
"to",
"copy",
"the",
"WireVectors",
"for",
"another",
"round",
"of",
"synthesis",
"This",
"does",
"not",
"split",
"a",
"WireVector",
"with",
"multiple",
"wires",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L204-L221 |
2,993 | UCSBarchlab/PyRTL | pyrtl/transform.py | _copy_net | def _copy_net(block_out, net, temp_wv_net, mem_map):
"""This function makes a copy of all nets passed to it for synth uses
"""
new_args = tuple(temp_wv_net[a_arg] for a_arg in net.args)
new_dests = tuple(temp_wv_net[a_dest] for a_dest in net.dests)
if net.op in "m@": # special stuff for copying mem... | python | def _copy_net(block_out, net, temp_wv_net, mem_map):
new_args = tuple(temp_wv_net[a_arg] for a_arg in net.args)
new_dests = tuple(temp_wv_net[a_dest] for a_dest in net.dests)
if net.op in "m@": # special stuff for copying memories
new_param = _get_new_block_mem_instance(net.op_param, mem_map, block... | [
"def",
"_copy_net",
"(",
"block_out",
",",
"net",
",",
"temp_wv_net",
",",
"mem_map",
")",
":",
"new_args",
"=",
"tuple",
"(",
"temp_wv_net",
"[",
"a_arg",
"]",
"for",
"a_arg",
"in",
"net",
".",
"args",
")",
"new_dests",
"=",
"tuple",
"(",
"temp_wv_net",... | This function makes a copy of all nets passed to it for synth uses | [
"This",
"function",
"makes",
"a",
"copy",
"of",
"all",
"nets",
"passed",
"to",
"it",
"for",
"synth",
"uses"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L224-L235 |
2,994 | UCSBarchlab/PyRTL | pyrtl/transform.py | _get_new_block_mem_instance | def _get_new_block_mem_instance(op_param, mem_map, block_out):
""" gets the instance of the memory in the new block that is
associated with a memory in a old block
"""
memid, old_mem = op_param
if old_mem not in mem_map:
new_mem = old_mem._make_copy(block_out)
new_mem.id = old_mem.id... | python | def _get_new_block_mem_instance(op_param, mem_map, block_out):
memid, old_mem = op_param
if old_mem not in mem_map:
new_mem = old_mem._make_copy(block_out)
new_mem.id = old_mem.id
mem_map[old_mem] = new_mem
return memid, mem_map[old_mem] | [
"def",
"_get_new_block_mem_instance",
"(",
"op_param",
",",
"mem_map",
",",
"block_out",
")",
":",
"memid",
",",
"old_mem",
"=",
"op_param",
"if",
"old_mem",
"not",
"in",
"mem_map",
":",
"new_mem",
"=",
"old_mem",
".",
"_make_copy",
"(",
"block_out",
")",
"n... | gets the instance of the memory in the new block that is
associated with a memory in a old block | [
"gets",
"the",
"instance",
"of",
"the",
"memory",
"in",
"the",
"new",
"block",
"that",
"is",
"associated",
"with",
"a",
"memory",
"in",
"a",
"old",
"block"
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/transform.py#L238-L247 |
2,995 | UCSBarchlab/PyRTL | pyrtl/helperfuncs.py | probe | def probe(w, name=None):
""" Print useful information about a WireVector when in debug mode.
:param w: WireVector from which to get info
:param name: optional name for probe (defaults to an autogenerated name)
:return: original WireVector w
Probe can be inserted into a existing design easily as it... | python | def probe(w, name=None):
if not isinstance(w, WireVector):
raise PyrtlError('Only WireVectors can be probed')
if name is None:
name = '(%s: %s)' % (probeIndexer.make_valid_string(), w.name)
print("Probe: " + name + ' ' + get_stack(w))
p = Output(name=name)
p <<= w # late assigns l... | [
"def",
"probe",
"(",
"w",
",",
"name",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"w",
",",
"WireVector",
")",
":",
"raise",
"PyrtlError",
"(",
"'Only WireVectors can be probed'",
")",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"'(%s: %s)'... | Print useful information about a WireVector when in debug mode.
:param w: WireVector from which to get info
:param name: optional name for probe (defaults to an autogenerated name)
:return: original WireVector w
Probe can be inserted into a existing design easily as it returns the
original wire un... | [
"Print",
"useful",
"information",
"about",
"a",
"WireVector",
"when",
"in",
"debug",
"mode",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/helperfuncs.py#L24-L52 |
2,996 | UCSBarchlab/PyRTL | pyrtl/helperfuncs.py | rtl_assert | def rtl_assert(w, exp, block=None):
""" Add hardware assertions to be checked on the RTL design.
:param w: should be a WireVector
:param Exception exp: Exception to throw when assertion fails
:param Block block: block to which the assertion should be added (default to working block)
:return: the Ou... | python | def rtl_assert(w, exp, block=None):
block = working_block(block)
if not isinstance(w, WireVector):
raise PyrtlError('Only WireVectors can be asserted with rtl_assert')
if len(w) != 1:
raise PyrtlError('rtl_assert checks only a WireVector of bitwidth 1')
if not isinstance(exp, Exception)... | [
"def",
"rtl_assert",
"(",
"w",
",",
"exp",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"working_block",
"(",
"block",
")",
"if",
"not",
"isinstance",
"(",
"w",
",",
"WireVector",
")",
":",
"raise",
"PyrtlError",
"(",
"'Only WireVectors can be assert... | Add hardware assertions to be checked on the RTL design.
:param w: should be a WireVector
:param Exception exp: Exception to throw when assertion fails
:param Block block: block to which the assertion should be added (default to working block)
:return: the Output wire for the assertion (can be ignored ... | [
"Add",
"hardware",
"assertions",
"to",
"be",
"checked",
"on",
"the",
"RTL",
"design",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/helperfuncs.py#L58-L90 |
2,997 | UCSBarchlab/PyRTL | pyrtl/helperfuncs.py | check_rtl_assertions | def check_rtl_assertions(sim):
""" Checks the values in sim to see if any registers assertions fail.
:param sim: Simulation in which to check the assertions
:return: None
"""
for (w, exp) in sim.block.rtl_assert_dict.items():
try:
value = sim.inspect(w)
if not value... | python | def check_rtl_assertions(sim):
for (w, exp) in sim.block.rtl_assert_dict.items():
try:
value = sim.inspect(w)
if not value:
raise exp
except KeyError:
pass | [
"def",
"check_rtl_assertions",
"(",
"sim",
")",
":",
"for",
"(",
"w",
",",
"exp",
")",
"in",
"sim",
".",
"block",
".",
"rtl_assert_dict",
".",
"items",
"(",
")",
":",
"try",
":",
"value",
"=",
"sim",
".",
"inspect",
"(",
"w",
")",
"if",
"not",
"v... | Checks the values in sim to see if any registers assertions fail.
:param sim: Simulation in which to check the assertions
:return: None | [
"Checks",
"the",
"values",
"in",
"sim",
"to",
"see",
"if",
"any",
"registers",
"assertions",
"fail",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/helperfuncs.py#L93-L106 |
2,998 | UCSBarchlab/PyRTL | pyrtl/helperfuncs.py | wirevector_list | def wirevector_list(names, bitwidth=None, wvtype=WireVector):
""" Allocate and return a list of WireVectors.
:param names: Names for the WireVectors. Can be a list or single comma/space-separated string
:param bitwidth: The desired bitwidth for the resulting WireVectors.
:param WireVector wvtype: Which... | python | def wirevector_list(names, bitwidth=None, wvtype=WireVector):
if isinstance(names, str):
names = names.replace(',', ' ').split()
if any('/' in name for name in names) and bitwidth is not None:
raise PyrtlError('only one of optional "/" or bitwidth parameter allowed')
if bitwidth is None:
... | [
"def",
"wirevector_list",
"(",
"names",
",",
"bitwidth",
"=",
"None",
",",
"wvtype",
"=",
"WireVector",
")",
":",
"if",
"isinstance",
"(",
"names",
",",
"str",
")",
":",
"names",
"=",
"names",
".",
"replace",
"(",
"','",
",",
"' '",
")",
".",
"split"... | Allocate and return a list of WireVectors.
:param names: Names for the WireVectors. Can be a list or single comma/space-separated string
:param bitwidth: The desired bitwidth for the resulting WireVectors.
:param WireVector wvtype: Which WireVector type to create.
:return: List of WireVectors.
Add... | [
"Allocate",
"and",
"return",
"a",
"list",
"of",
"WireVectors",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/helperfuncs.py#L154-L197 |
2,999 | UCSBarchlab/PyRTL | pyrtl/helperfuncs.py | val_to_signed_integer | def val_to_signed_integer(value, bitwidth):
""" Return value as intrepreted as a signed integer under twos complement.
:param value: a python integer holding the value to convert
:param bitwidth: the length of the integer in bits to assume for conversion
Given an unsigned integer (not a wirevector!) c... | python | def val_to_signed_integer(value, bitwidth):
if isinstance(value, WireVector) or isinstance(bitwidth, WireVector):
raise PyrtlError('inputs must not be wirevectors')
if bitwidth < 1:
raise PyrtlError('bitwidth must be a positive integer')
neg_mask = 1 << (bitwidth - 1)
neg_part = value &... | [
"def",
"val_to_signed_integer",
"(",
"value",
",",
"bitwidth",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"WireVector",
")",
"or",
"isinstance",
"(",
"bitwidth",
",",
"WireVector",
")",
":",
"raise",
"PyrtlError",
"(",
"'inputs must not be wirevectors'",
"... | Return value as intrepreted as a signed integer under twos complement.
:param value: a python integer holding the value to convert
:param bitwidth: the length of the integer in bits to assume for conversion
Given an unsigned integer (not a wirevector!) covert that to a signed
integer. This is useful ... | [
"Return",
"value",
"as",
"intrepreted",
"as",
"a",
"signed",
"integer",
"under",
"twos",
"complement",
"."
] | 0988e5c9c10ededd5e1f58d5306603f9edf4b3e2 | https://github.com/UCSBarchlab/PyRTL/blob/0988e5c9c10ededd5e1f58d5306603f9edf4b3e2/pyrtl/helperfuncs.py#L200-L223 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.