text stringlengths 81 112k |
|---|
Register an event that occurred during processing of a task of the given
type.
Args: event_name: str A name for a type of events. Events of the
same type are displayed as a single entry and a total count of
occurences.
def event(self, event_name):
"""Registe... |
r"""For some classes (in particular $\Delta F=1$), only a subset of Wilson
coefficients exist in WET-3 and WET-4. Therefore, depending on the number
of flavours `f`, the dimensionality of the ADM has to be reduced.
def get_permissible_wcs(classname, f):
r"""For some classes (in particular $\Delta F=1$), on... |
Compute the eigenvalues and eigenvectors for a QCD anomalous dimension
matrix that is defined in `adm.adm_s_X` where X is the name of the sector.
Supports memoization. Output analogous to `np.linalg.eig`.
def admeig(classname, f, m_u, m_d, m_s, m_c, m_b, m_e, m_mu, m_tau):
"""Compute the eigenvalues and e... |
Get the QCD evolution matrix.
def getUs(classname, eta_s, f, alpha_s, alpha_e, m_u, m_d, m_s, m_c, m_b, m_e, m_mu, m_tau):
"""Get the QCD evolution matrix."""
w, v = admeig(classname, f, m_u, m_d, m_s, m_c, m_b, m_e, m_mu, m_tau)
b0s = 11 - 2 * f / 3
a = w / (2 * b0s)
return v @ np.diag(eta_s**a) @... |
Get the QCD evolution matrix.
def getUe(classname, eta_s, f, alpha_s, alpha_e, m_u, m_d, m_s, m_c, m_b, m_e, m_mu, m_tau):
"""Get the QCD evolution matrix."""
args = f, m_u, m_d, m_s, m_c, m_b, m_e, m_mu, m_tau
A = getattr(adm, 'adm_e_' + classname)(*args)
perm_keys = get_permissible_wcs(classname, f)
... |
r"""Solve the WET RGE for a specific sector.
Parameters:
- sector: sector of interest
- C_in: dictionary of Wilson coefficients
- eta_s: ratio of $\alpha_s$ at input and output scale
- f: number of active quark flavours
- p_in: running parameters at the input scale
- p_out: running paramet... |
Merge conflicts occur if a folder in one tree is a file in the other.
As the files are PIDs, this can only happen if a PID matches one of the
geographical areas that the dataset covers and should be very rare. In such
conflicts, the destination wins.
def _merge_region_trees(self, dst_tree, src... |
Return the region_tree item specified by path. An item can be a a folder
(represented by a dictionary) or a PID (represented by None).
This function is also used for determining which section of a path is within
the region tree and which section should be passed to the next resolver. To
... |
Override save method to catch handled errors and repackage them as 400 errors.
def save(self, **kwargs):
"""Override save method to catch handled errors and repackage them as 400 errors."""
try:
return super().save(**kwargs)
except SlugError as error:
raise ParseError(er... |
Read the Node document from a node and return an int containing the latest D1 API
version supported by the node.
The Node document can always be reached through the v1 API and will list services
for v1 and any later APIs versions supported by the node.
def get_api_major_by_base_url(base_url, *client_arg_l... |
Delete any unused subjects from the database.
This is not strictly required as any unused subjects will automatically be reused if
needed in the future.
def delete_unused_subjects():
"""Delete any unused subjects from the database.
This is not strictly required as any unused subjects will automatical... |
Serialize a DN to a DataONE subject string.
Args:
cert_obj: cryptography.Certificate
Returns:
str:
Primary subject extracted from the certificate DN.
The certificate DN (DistinguishedName) is a sequence of RDNs
(RelativeDistinguishedName). Each RDN is a set of AVAs (AttributeValue... |
Create the DN Subject for certificate that will be used in a DataONE environment.
The DN is formatted into a DataONE subject, which is used in authentication,
authorization and event tracking.
Args:
common_name_str: str
DataONE uses simple DNs without physical location information, so ... |
Generate a Certificate Signing Request (CSR).
Args:
private_key_bytes: bytes
Private key with which the CSR will be signed.
subject_name: str
Certificate Subject Name
fqdn_list:
List of Fully Qualified Domain Names (FQDN) and/or IP addresses for which
... |
Deserialize PEM (Base64) encoded X.509 v3 certificate.
Args:
cert_pem: str or bytes
PEM (Base64) encoded X.509 v3 certificate
Returns:
cert_obj: cryptography.Certificate
def deserialize_pem(cert_pem):
"""Deserialize PEM (Base64) encoded X.509 v3 certificate.
Args:
cert_pem:... |
Serialize certificate to PEM.
The certificate can be also be a Certificate Signing Request (CSR).
Args:
cert_obj: cryptography.Certificate
Returns:
bytes: PEM encoded certificate
def serialize_cert_to_pem(cert_obj):
"""Serialize certificate to PEM.
The certificate can be also be a C... |
Extract DataONE SubjectInfo XML doc from certificate.
Certificates issued by DataONE may include an embedded XML doc containing
additional information about the subject specified in the certificate DN. If
present, the doc is stored as an extension with an OID specified by DataONE and
formatted as speci... |
Download public certificate from a TLS/SSL web server as DER encoded ``bytes``.
If the certificate is being downloaded in order to troubleshoot validation issues,
the download itself may fail due to the validation issue that is being investigated.
To work around such chicken-and-egg problems, temporarily w... |
Download public certificate from a TLS/SSL web server as PEM encoded string.
Also see download_as_der().
Args:
base_url : str
A full URL to a DataONE service endpoint or a server hostname
timeout_sec : int or float
Timeout for the SSL socket operations
Returns:
s... |
Download public certificate from a TLS/SSL web server as Certificate object.
Also see download_as_der().
Args:
base_url : str
A full URL to a DataONE service endpoint or a server hostname
timeout_sec : int or float
Timeout for the SSL socket operations
Returns:
c... |
Decode cert DER string to Certificate object.
Args:
cert_der : Certificate as a DER encoded string
Returns:
cryptography.Certificate()
def decode_der(cert_der):
"""Decode cert DER string to Certificate object.
Args:
cert_der : Certificate as a DER encoded string
Returns:
... |
Context manager to temporarily disable certificate validation in the standard SSL
library.
Note: This should not be used in production code but is sometimes useful for
troubleshooting certificate validation issues.
By design, the standard SSL library does not provide a way to disable verification
... |
Extract issuer CA certificate URL from certificate.
Certificates may include a URL where the root certificate for the CA which was used
for signing the certificate can be downloaded. This function returns the URL if
present.
The primary use for this is to fix validation failure due to non-trusted issu... |
Serialize private key to PEM.
Args:
private_key:
passphrase_bytes:
Returns:
bytes: PEM encoded private key
def serialize_private_key_to_pem(private_key, passphrase_bytes=None):
"""Serialize private key to PEM.
Args:
private_key:
passphrase_bytes:
Returns:
byt... |
Generate a private key
def generate_private_key(key_size=2048):
"""Generate a private key"""
return cryptography.hazmat.primitives.asymmetric.rsa.generate_private_key(
public_exponent=65537,
key_size=key_size,
backend=cryptography.hazmat.backends.default_backend(),
) |
Extract public key from certificate as PEM encoded PKCS#1.
Args:
cert_obj: cryptography.Certificate
Returns:
bytes: PEM encoded PKCS#1 public key.
def get_public_key_pem(cert_obj):
"""Extract public key from certificate as PEM encoded PKCS#1.
Args:
cert_obj: cryptography.Certificat... |
Load CSR from PEM encoded file
def load_csr(pem_path):
"""Load CSR from PEM encoded file"""
with open(pem_path, "rb") as f:
return cryptography.x509.load_pem_x509_csr(
data=f.read(), backend=cryptography.hazmat.backends.default_backend()
) |
Load private key from PEM encoded file
def load_private_key(pem_path, passphrase_bytes=None):
"""Load private key from PEM encoded file"""
with open(pem_path, "rb") as f:
return cryptography.hazmat.primitives.serialization.load_pem_private_key(
data=f.read(),
password=passphrase... |
Serialize certificate to DER.
Args:
cert_obj: cryptography.Certificate
Returns:
bytes: DER encoded certificate
def serialize_cert_to_der(cert_obj):
"""Serialize certificate to DER.
Args:
cert_obj: cryptography.Certificate
Returns:
bytes: DER encoded certificate
"""
... |
Dump basic certificate values to the log.
Args:
logger: Logger
Logger to which to write the certificate values.
msg_str: str
A message to write to the log before the certificate values.
cert_obj: cryptography.Certificate
Certificate containing values to log.
Returns... |
Get a standard certificate extension by attribute name.
Args:
cert_obj: cryptography.Certificate
Certificate containing a standard extension.
extension_name : str
Extension name. E.g., 'SUBJECT_DIRECTORY_ATTRIBUTES'.
Returns:
Cryptography.Extension
def get_extension_by_name... |
Extract values from nested objects by attribute names.
Objects contain attributes which are named references to objects. This will descend
down a tree of nested objects, starting at the given object, following the given
path.
Args:
obj: object
Any type of object
path_list: list
... |
Extract values from nested objects by attribute names and concatenate their
string representations.
Args:
obj: object
Any type of object
path_list: list
Attribute names
reverse: bool
Reverse the list of values before concatenation.
Returns:
str: Concatenat... |
From JMS to BernI basis (= traditional SUSY basis in this case)
for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'cu
def _JMS_to_Bern_I(C, qq):
"""From JMS to BernI basis (= traditional SUSY basis in this case)
for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'cu'"""
... |
From Bern to JMS basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'cu
def _Bern_to_JMS_I(C, qq):
"""From Bern to JMS basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'cu'"""
if qq in ['sb', 'db', 'ds']:
dd = 'dd'
ij = '{}{}'.format(dflav[qq[0]] + ... |
From BernI to FlavioI basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'uc
def _BernI_to_Flavio_I(C, qq):
"""From BernI to FlavioI basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'uc'"""
qqf = qq[::-1] # flavio uses "bs" instead of "sb" etc.
if qq in ['sb',... |
From FlavioI to BernI basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'uc
def _FlavioI_to_Bern_I(C, qq):
"""From FlavioI to BernI basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'uc'"""
qqb = qq[::-1] # flavio uses "bs" instead of "sb" etc.
if qq in ['bs',... |
From BernI to FormFlavorI basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'uc
def _BernI_to_FormFlavor_I(C, qq):
"""From BernI to FormFlavorI basis for $\Delta F=2$ operators.
`qq` should be 'sb', 'db', 'ds' or 'uc'"""
qqf = qq[::-1] # FormFlavour uses "bs" instead of "sb" etc.
... |
From JMS to BernII basis for charged current process semileptonic
operators. `udlnu` should be of the form 'udl_enu_tau', 'cbl_munu_e' etc.
def _JMS_to_Bern_II(C, udlnu):
"""From JMS to BernII basis for charged current process semileptonic
operators. `udlnu` should be of the form 'udl_enu_tau', 'cbl_munu_e... |
From BernII to JMS basis for charged current process semileptonic
operators. `udlnu` should be of the form 'udl_enu_tau', 'cbl_munu_e' etc.
def _Bern_to_JMS_II(C, udlnu):
"""From BernII to JMS basis for charged current process semileptonic
operators. `udlnu` should be of the form 'udl_enu_tau', 'cbl_munu_e... |
From BernII to FlavioII basis
for charged current process semileptonic operators.
`udlnu` should be of the form 'udl_enu_tau', 'cbl_munu_e' etc.
def _BernII_to_Flavio_II(C, udlnu, parameters):
"""From BernII to FlavioII basis
for charged current process semileptonic operators.
`udlnu` should be of ... |
From 4-quark Fierz to JMS basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc.
def _Fierz_to_JMS_III_IV_V(Fqqqq, qqqq):
"""From 4-quark Fierz to JMS basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc."""
F = Fqqqq.copy()
#ca... |
From JMS to 4-quark Fierz basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc.
def _JMS_to_Fierz_III_IV_V(C, qqqq):
"""From JMS to 4-quark Fierz basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc."""
#case dduu
classIII = ['... |
From Fierz to 4-quark Bern basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc.
def _Fierz_to_Bern_III_IV_V(Fqqqq, qqqq):
"""From Fierz to 4-quark Bern basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc."""
# 2nd != 4th, color-o... |
From Bern to 4-quark Fierz basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc.
def _Bern_to_Fierz_III_IV_V(C, qqqq):
"""From Bern to 4-quark Fierz basis for Classes III, IV and V.
`qqqq` should be of the form 'sbuc', 'sdcc', 'ucuu' etc."""
# 2nd != 4th, color-octet... |
From Fierz to the EOS basis for b -> s transitions.
The arguments are dictionaries of the corresponding Fierz bases
def _Fierz_to_EOS_V(Fsbuu,Fsbdd,Fsbcc,Fsbss,Fsbbb,parameters):
p = parameters
V = ckmutil.ckm.ckm_tree(p["Vus"], p["Vub"], p["Vcb"], p["delta"])
Vtb = V[2,2]
Vts = V[2,1]
"""From ... |
From JMS to semileptonic Fierz basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def JMS_to_Fierz_lep(C, ddll):
"""From JMS to semileptonic Fierz basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc."""
if ddll[:2] == 'uc':
s = uflav[ddl... |
From JMS to semileptonic Fierz basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def JMS_to_Fierz_nunu(C, ddll):
"""From JMS to semileptonic Fierz basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc."""
s = dflav[ddll[0]]
b = dflav[ddll[1]]... |
From Fierz to semileptonic JMS basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Fierz_to_JMS_lep(C, ddll):
"""From Fierz to semileptonic JMS basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc."""
if ddll[:2] == 'uc':
s = str(uflav... |
From Fierz to semileptonic JMS basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Fierz_to_JMS_nunu(C, ddll):
"""From Fierz to semileptonic JMS basis for Class V.
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc."""
s = str(dflav[ddll[0]] + 1)
b = str(d... |
From semileptonic Fierz basis to Bern semileptonic basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Fierz_to_Bern_lep(C, ddll):
"""From semileptonic Fierz basis to Bern semileptonic basis for Class V.
C should be... |
From semileptonic Fierz basis to Bern semileptonic basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Fierz_to_Bern_nunu(C, ddll):
"""From semileptonic Fierz basis to Bern semileptonic basis for Class V.
C should b... |
From semileptonic Bern basis to Fierz semileptonic basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Bern_to_Fierz_lep(C,ddll):
"""From semileptonic Bern basis to Fierz semileptonic basis for Class V.
C should be ... |
From semileptonic Bern basis to Fierz semileptonic basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Bern_to_Fierz_nunu(C,ddll):
"""From semileptonic Bern basis to Fierz semileptonic basis for Class V.
C should be... |
From semileptonic Fierz basis to Flavio semileptonic basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Fierz_to_Flavio_lep(C, ddll, parameters, norm_gf=True):
"""From semileptonic Fierz basis to Flavio semileptonic ba... |
From Flavio semileptonic basis to semileptonic Fierz basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Flavio_to_Fierz_nunu(C, ddll, parameters, norm_gf=True):
"""From Flavio semileptonic basis to semileptonic Fierz... |
From semileptonic Fierz basis to EOS semileptonic basis for Class V.
C should be the corresponding leptonic Fierz basis and
`ddll` should be of the form 'sbl_enu_tau', 'dbl_munu_e' etc.
def Fierz_to_EOS_lep(C, ddll, parameters):
"""From semileptonic Fierz basis to EOS semileptonic basis for Class V.
C ... |
From JMS to semileptonic Fierz basis for Classes V.
C should be the JMS basis and `ddll` should be of the
form 'sbl_eni_tau', 'dbl_munu_e' etc.
def JMS_to_FormFlavor_lep(C, dd):
"""From JMS to semileptonic Fierz basis for Classes V.
C should be the JMS basis and `ddll` should be of the
form 'sbl_en... |
From JMS to chromomagnetic Fierz basis for Class V.
qq should be of the form 'sb', 'ds' etc.
def JMS_to_Fierz_chrom(C, qq):
"""From JMS to chromomagnetic Fierz basis for Class V.
qq should be of the form 'sb', 'ds' etc."""
if qq[0] in dflav:
s = dflav[qq[0]]
b = dflav[qq[1]]
ret... |
From chromomagnetic Fierz to JMS basis for Class V.
qq should be of the form 'sb', 'ds' etc.
def Fierz_to_JMS_chrom(C, qq):
"""From chromomagnetic Fierz to JMS basis for Class V.
qq should be of the form 'sb', 'ds' etc."""
if qq[0] in dflav:
s = dflav[qq[0]] + 1
b = dflav[qq[1]] + 1
... |
From Fierz to chromomagnetic Bern basis for Class V.
dd should be of the form 'sb', 'ds' etc.
def Fierz_to_Bern_chrom(C, dd, parameters):
"""From Fierz to chromomagnetic Bern basis for Class V.
dd should be of the form 'sb', 'ds' etc."""
e = sqrt(4 * pi * parameters['alpha_e'])
gs = sqrt(4 * pi * p... |
From Flavio to chromomagnetic Fierz basis for Class V.
qq should be of the form 'sb', 'db' etc.
def Flavio_to_Fierz_chrom(C, qq, parameters):
"""From Flavio to chromomagnetic Fierz basis for Class V.
qq should be of the form 'sb', 'db' etc."""
p = parameters
V = ckmutil.ckm.ckm_tree(p["Vus"], p["Vu... |
From Fierz to chromomagnetic EOS basis for Class V.
dd should be of the form 'sb', 'ds' etc.
def Fierz_to_EOS_chrom(C, dd, parameters):
"""From Fierz to chromomagnetic EOS basis for Class V.
dd should be of the form 'sb', 'ds' etc."""
p = parameters
V = ckmutil.ckm.ckm_tree(p["Vus"], p["Vub"], p["V... |
From JMS to chromomagnetic FormFlavor basis for Class V.
qq should be of the form 'sb', 'ds', 'uu', mt (mu tau), em (e mu) etc.
def JMS_to_FormFlavor_chrom(C, qq, parameters):
"""From JMS to chromomagnetic FormFlavor basis for Class V.
qq should be of the form 'sb', 'ds', 'uu', mt (mu tau), em (e mu) etc."... |
From JMS to flavio basis for class VII, i.e. flavour blind operators.
def _JMS_to_Flavio_VII(C, parameters):
"""From JMS to flavio basis for class VII, i.e. flavour blind operators."""
d = {}
dtrans = json.loads(pkgutil.get_data('wilson', 'data/flavio_jms_vii.json').decode('utf8'))
for cj, cf in dtrans... |
Get parameters (masses, coupling constants, ...) at the scale
`scale` in QCD with `f` dynamical quark flavours. Optionally takes a
dictionary of inputs (otherwise, defaults are used).
def get_parameters(scale, f=5, input_parameters=None):
"""Get parameters (masses, coupling constants, ...) at the scale
... |
Remove an object from a revision chain.
The object can be at any location in the chain, including the head or tail.
Preconditions:
- The object with the pid is verified to exist and to be a member of an
revision chain. E.g., with:
d1_gmn.app.views.asserts.is_existing_object(pid)
d1_gmn.app.vi... |
Get the PID to which the ``sid`` currently maps.
Preconditions:
- ``sid`` is verified to exist. E.g., with d1_gmn.app.views.asserts.is_sid().
def resolve_sid(sid):
"""Get the PID to which the ``sid`` currently maps.
Preconditions:
- ``sid`` is verified to exist. E.g., with d1_gmn.app.views.assert... |
Return True if ``pid`` is referenced in the obsoletes field of any object.
This will return True even if the PID is in the obsoletes field of an object that
does not exist on the local MN, such as replica that is in an incomplete chain.
def is_obsoletes_pid(pid):
"""Return True if ``pid`` is referenced in... |
Return True if ``pid`` is referenced in the obsoletedBy field of any object.
This will return True even if the PID is in the obsoletes field of an object that
does not exist on the local MN, such as replica that is in an incomplete chain.
def is_obsoleted_by_pid(pid):
"""Return True if ``pid`` is referenc... |
Merge two chains.
For use when it becomes known that two chains that were created separately
actually are separate sections of the same chain
E.g.:
- A obsoleted by X is created. A has no SID. X does not exist yet. A chain is
created for A.
- B obsoleting Y is created. B has SID. Y does not... |
Set or update SID for chain.
If the chain already has a SID, ``sid`` must either be None or match the existing
SID.
def _set_chain_sid(chain_model, sid):
"""Set or update SID for chain.
If the chain already has a SID, ``sid`` must either be None or match the existing
SID.
"""
if not sid:... |
Find chain by pid.
Return None if not found.
def _get_chain_by_pid(pid):
"""Find chain by pid.
Return None if not found.
"""
try:
return d1_gmn.app.models.ChainMember.objects.get(pid__did=pid).chain
except d1_gmn.app.models.ChainMember.DoesNotExist:
pass |
Return None if not found.
def _get_chain_by_sid(sid):
"""Return None if not found."""
try:
return d1_gmn.app.models.Chain.objects.get(sid__did=sid)
except d1_gmn.app.models.Chain.DoesNotExist:
pass |
Set chain head PID to the last existing object in the chain to which ``pid``
belongs. If SID has been set for chain, it resolves to chain head PID.
Intended to be called in MNStorage.delete() and other chain manipulation.
Preconditions:
- ``pid`` must exist and be verified to be a PID.
d1_gmn.ap... |
Create the initial chain structure for a new standalone object. Intended to be
called in MNStorage.create().
Preconditions:
- ``sid`` must be verified to be available to be assigned to a new standalone
object. E.g., with is_valid_sid_for_new_standalone().
def _create_chain(pid, sid):
"""Create t... |
Populate entity type from attached descriptor schema.
def populate_entity_type(apps, schema_editor):
"""Populate entity type from attached descriptor schema."""
Entity = apps.get_model('flow', 'Entity')
for entity in Entity.objects.all():
if entity.descriptor_schema is not None:
entity... |
Deserialize DataONE XML types to PyXB.
Args:
doc_xml: UTF-8 encoded ``bytes``
pyxb_binding: PyXB binding object. If not specified, the correct one should be
selected automatically.
Returns:
PyXB object
See Also:
``deserialize_d1_exception()`` for deserializing DataONE Excep... |
Serialize PyXB object to XML.
Args:
obj_pyxb: PyXB object
PyXB object to serialize.
encoding: str
Encoding to use for XML doc bytes
pretty: bool
True: Use pretty print formatting for human readability.
strip_prolog:
True: remove any XML prolog (e.g., ``<?x... |
Serialize PyXB object to XML ``bytes`` with UTF-8 encoding for transport over the
network, filesystem storage and other machine usage.
Args:
obj_pyxb: PyXB object
PyXB object to serialize.
pretty: bool
True: Use pretty print formatting for human readability.
strip_prolog:
... |
Serialize PyXB object to pretty printed XML ``str`` for display.
Args:
obj_pyxb: PyXB object
PyXB object to serialize.
pretty: bool
False: Disable pretty print formatting. XML will not have line breaks.
strip_prolog:
True: remove any XML prolog (e.g., ``<?xml version="1.... |
Pretty print XML doc.
Args:
doc_xml : str
Well formed XML doc
Returns:
str: Pretty printed XML doc
def reformat_to_pretty_xml(doc_xml):
"""Pretty print XML doc.
Args:
doc_xml : str
Well formed XML doc
Returns:
str: Pretty printed XML doc
"""
asse... |
Return True if two XML docs are semantically equivalent, else False.
- TODO: Include test for tails. Skipped for now because tails are not used in any
D1 types.
def are_equivalent(a_xml, b_xml, encoding=None):
"""Return True if two XML docs are semantically equivalent, else False.
- TODO: Include t... |
Return True if ``superset_tree`` is equal to or a superset of ``base_tree``
- Checks that all elements and attributes in ``superset_tree`` are present and
contain the same values as in ``base_tree``. For elements, also checks that the
order is the same.
- Can be used for checking if one XML documen... |
Normalize and compare XML documents for equality. The document may or may not be
a DataONE type.
Args:
a_xml: str
b_xml: str
XML documents to compare for equality.
Returns:
bool: ``True`` if the XML documents are semantically equivalent.
def are_equal_xml(a_xml, b_xml):
"""N... |
Normalize and compare ElementTrees for equality.
Args:
a_el: ElementTree
b_el: ElementTree
ElementTrees to compare for equality.
Returns:
bool: ``True`` if the ElementTrees are semantically equivalent.
def are_equal_elements(a_el, b_el):
"""Normalize and compare ElementTrees for... |
In-place sort simple or complex elements in a PyXB object by values they contain
in child elements.
Args:
obj_pyxb: PyXB object
child_name_list: list of str
List of element names that are direct children of the PyXB object.
def sort_elements_by_child_values(obj_pyxb, child_name_list):
... |
Create a diff between two PyXB objects.
Args:
a_pyxb: PyXB object
b_pyxb: PyXB object
Returns:
str : `Differ`-style delta
def format_diff_pyxb(a_pyxb, b_pyxb):
"""Create a diff between two PyXB objects.
Args:
a_pyxb: PyXB object
b_pyxb: PyXB object
Returns:
s... |
Create a diff between two XML documents.
Args:
a_xml: str
b_xml: str
Returns:
str : `Differ`-style delta
def format_diff_xml(a_xml, b_xml):
"""Create a diff between two XML documents.
Args:
a_xml: str
b_xml: str
Returns:
str : `Differ`-style delta
"""
... |
Get an optional attribute value from a PyXB element.
The attributes for elements that are optional according to the schema and
not set in the PyXB object are present and set to None.
PyXB validation will fail if required elements are missing.
Args:
obj_pyxb: PyXB object
attr_str: str
... |
Get an optional Simple Content value from a PyXB element.
The attributes for elements that are optional according to the schema and
not set in the PyXB object are present and set to None.
PyXB validation will fail if required elements are missing.
Args:
obj_pyxb: PyXB object
attr_str: st... |
Handle exceptions raised in API and make them nicer.
To enable this, you have to add it to the settings:
.. code:: python
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'resolwe.flow.utils.exceptions.resolwe_exception_handler',
}
def resolwe_exception_handler(exc, contex... |
Example for validating the signature of a JWT using only the cryptography
library.
Note that this does NOT validate the claims in the claim set.
def validate_and_decode(jwt_bu64, cert_obj):
"""Example for validating the signature of a JWT using only the cryptography
library.
Note that this does N... |
Given a list of cert and JWT file names, print a list showing each combination
along with indicators for combinations where the JWT signature was successfully
validated with the cert.
def find_valid_combinations(cert_file_name_list, jwt_file_name_list):
"""Given a list of cert and JWT file names, print a l... |
Return a dict containing scheme, netloc, url, params, query, fragment keys.
query is a dict where the values are always lists. If the query key appears only
once in the URL, the list will have a single value.
def parseUrl(url):
"""Return a dict containing scheme, netloc, url, params, query, fragment keys.... |
Encode a URL path element according to RFC3986.
def encodePathElement(element):
"""Encode a URL path element according to RFC3986."""
return urllib.parse.quote(
(
element.encode('utf-8')
if isinstance(element, str)
else str(element)
if isinstance(element,... |
Encode a URL query element according to RFC3986.
def encodeQueryElement(element):
"""Encode a URL query element according to RFC3986."""
return urllib.parse.quote(
(
element.encode('utf-8')
if isinstance(element, str)
else str(element)
if isinstance(eleme... |
Modified version of the standard urllib.urlencode that is conforms to RFC3986.
The urllib version encodes spaces as '+' which can lead to inconsistency. This
version will always encode spaces as '%20'.
Encode a sequence of two-element tuples or dictionary into a URL query string.
If any values in the ... |
Attempt to create a valid CN BaseURL when one or more sections of the URL are
missing.
def makeCNBaseURL(url):
"""Attempt to create a valid CN BaseURL when one or more sections of the URL are
missing."""
o = urllib.parse.urlparse(url, scheme=d1_common.const.DEFAULT_CN_PROTOCOL)
if o.netloc and o.pa... |
Attempt to create a valid MN BaseURL when one or more sections of the URL are
missing.
def makeMNBaseURL(url):
"""Attempt to create a valid MN BaseURL when one or more sections of the URL are
missing."""
o = urllib.parse.urlparse(url, scheme=d1_common.const.DEFAULT_MN_PROTOCOL)
if o.netloc and o.pa... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.