prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def <|fim_middle|>(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | __init__ |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def <|fim_middle|>(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | getPassphrase |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def <|fim_middle|>(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | createSignedCertificate |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def <|fim_middle|>(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | decryptData |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def <|fim_middle|>(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | encryptData |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def <|fim_middle|>(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | getPublicKey |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def <|fim_middle|>(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | signData |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def <|fim_middle|>(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | signEncryptedData |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def <|fim_middle|>(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | validCertificate |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def <|fim_middle|>(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | validSelfSignedCertificate |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def <|fim_middle|>(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def validSignedEncryptedData(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | validSignedData |
<|file_name|>CertAuthority.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
This module provides the necessary methods for a Certification Authority.
For creating the self signed Certificate for the CA, use the following command:
$ openssl req -x509 -newkey rsa:2048 -keyout ca_priv.pem -out ca_cert.pem
@author: Vasco Santos
"""
import time
from M2Crypto import X509, RSA, EVP, BIO, ASN1
class CertificationAuthority(object):
""" Class responsible for keeping the CA self-signed certificate,
as well as, its private key.
"""
def __init__(self, cert, priv_key, passphrase):
""" Create a Certification Authority Object.
Arguments:
cert: file system path of the CA's self-signed certificate.
priv_key: file system path of the CA's private key (encrypted).
passphrase: Symmetric key for priv_key decryption.
"""
def getPassphrase(*args):
""" Callback for private key decrypting.
"""
return str(passphrase.encode('utf-8'))
self.cert = X509.load_cert(cert.encode('utf-8'))
self.priv_key = RSA.load_key(priv_key.encode('utf-8'), getPassphrase)
# Private key for signing
self.signEVP = EVP.PKey()
self.signEVP.assign_rsa(self.priv_key)
def createSignedCertificate(self, subj_id, pub_key, expiration_time):
""" Create a certificate for a subject public key, signed by the CA.
Arguments:
subj_id: certificate subject identifier.
pub_key: public key of the subject.
expiration_time: certificate life time.
Returns:
Certificate in PEM Format.
"""
# Public Key to certificate
bio = BIO.MemoryBuffer(str(pub_key.decode('hex')))
pub_key = RSA.load_pub_key_bio(bio)
pkey = EVP.PKey()
pkey.assign_rsa(pub_key)
# Certificate Fields
cur_time = ASN1.ASN1_UTCTIME()
cur_time.set_time(int(time.time()))
expire_time = ASN1.ASN1_UTCTIME()
expire_time.set_time(int(time.time()) + expiration_time * 60) # In expiration time minutes
# Certification Creation
cert = X509.X509()
cert.set_pubkey(pkey)
s_name = X509.X509_Name()
s_name.C = "PT"
s_name.CN = str(subj_id)
cert.set_subject(s_name)
i_name = X509.X509_Name()
i_name.C = "PT"
i_name.CN = "Register Server"
cert.set_issuer_name(i_name)
cert.set_not_before(cur_time)
cert.set_not_after(expire_time)
cert.sign(self.signEVP, md="sha1")
#cert.save_pem("peer_CA.pem")
return cert.as_pem().encode('hex')
def decryptData(self, data):
""" Decrypt the intended data with the entity private key.
Arguments:
data: data to be decrypted.
"""
return self.priv_key.private_decrypt(data.decode('base64'), RSA.pkcs1_padding)
def encryptData(self, data, certificate):
""" Encrypt the intended data with the public key contained in the certificate.
Arguments:
data: data to be encrypted.
certificate: subject certificate.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
return cert.get_pubkey().get_rsa().public_encrypt(str(data), RSA.pkcs1_padding).encode('base64')
def getPublicKey(self):
""" Get the CA Public Key.
Returns:
CA Public Key in PEM Format.
"""
return self.cert.get_pubkey().get_rsa().as_pem().encode('hex')
def signData(self, data):
""" Sign a received String.
Arguments:
data: string to sign.
Returns:
signature of the received data.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def signEncryptedData(self, cipherData):
""" Sign encrypted data.
Arguments:
cipherData: data encrypted (base64 format).
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
self.signEVP.sign_init()
self.signEVP.sign_update(msgDigest.digest())
return self.signEVP.sign_final().encode('base64')
def validCertificate(self, certificate):
""" Verify if a certificate of a subject was issued by this CA.
Arguments:
certificate: subject certificate.
Returns:
true if the certificate was issued by this CA. false otherwise.
"""
cert = X509.load_cert_string(certificate.decode('hex'))
# Data Analysis
# Subject confirmation
return cert.verify(self.cert.get_pubkey())
def validSelfSignedCertificate(self):
""" Verify if the self-signed CA certificate was not corrupted.
Returns:
true if the self signed certificate is valid, false otherwise.
"""
return self.cert.check_ca() and self.cert.verify(self.cert.get_pubkey())
def validSignedData(self, data, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
data: received data.
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(str(data))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
def <|fim_middle|>(self, cipherData, signature, certificate):
""" Verify if the received data was signed by the owner of the certificate.
Arguments:
cipherData: data encrypted (base64 format).
signature: digital signature of the data.
certificate: certificate of the data issuer.
Returns:
true if the data maintains its integrity, false otherwise.
"""
msgDigest = EVP.MessageDigest('sha1')
msgDigest.update(cipherData.decode('base64'))
pub_key = X509.load_cert_string(certificate.decode('hex')).get_pubkey().get_rsa()
verifyEVP = EVP.PKey()
verifyEVP.assign_rsa(pub_key)
verifyEVP.verify_init()
verifyEVP.verify_update(msgDigest.digest())
return verifyEVP.verify_final(str(signature.decode('base64')))
<|fim▁end|> | validSignedEncryptedData |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
<|fim▁hole|> Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled<|fim▁end|> | You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
<|fim_middle|>
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | def emit(self, record):
pass |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
<|fim_middle|>
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | pass |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
<|fim_middle|>
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | """
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
<|fim_middle|>
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------") |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
<|fim_middle|>
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | _logger.error(msg) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
<|fim_middle|>
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | _logger.warning(msg) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
<|fim_middle|>
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | _logger.debug(msg) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
<|fim_middle|>
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | if _traceEnabled:
_logger.debug(msg) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
<|fim_middle|>
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | return _logger.isEnabledFor(logging.ERROR) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
<|fim_middle|>
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | return _logger.isEnabledFor(logging.DEBUG) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
<|fim_middle|>
<|fim▁end|> | return _traceEnabled |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
<|fim_middle|>
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | _logger.addHandler(handler)
_logger.setLevel(logging.DEBUG) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
<|fim_middle|>
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | _logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------") |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
<|fim_middle|>
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | _logger.debug(msg) |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def <|fim_middle|>(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | emit |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def <|fim_middle|>(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | enableTrace |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def <|fim_middle|>(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | dump |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def <|fim_middle|>(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | error |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def <|fim_middle|>(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | warning |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def <|fim_middle|>(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | debug |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def <|fim_middle|>(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | trace |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def <|fim_middle|>():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | isEnabledForError |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def <|fim_middle|>():
return _logger.isEnabledFor(logging.DEBUG)
def isEnabledForTrace():
return _traceEnabled
<|fim▁end|> | isEnabledForDebug |
<|file_name|>_logging.py<|end_file_name|><|fim▁begin|>"""
websocket - WebSocket client library for Python
Copyright (C) 2010 Hiroki Ohtani(liris)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1335 USA
"""
import logging
_logger = logging.getLogger('websocket')
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
_logger.addHandler(NullHandler())
_traceEnabled = False
__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace",
"isEnabledForError", "isEnabledForDebug", "isEnabledForTrace"]
def enableTrace(traceable, handler = logging.StreamHandler()):
"""
turn on/off the traceability.
traceable: boolean value. if set True, traceability is enabled.
"""
global _traceEnabled
_traceEnabled = traceable
if traceable:
_logger.addHandler(handler)
_logger.setLevel(logging.DEBUG)
def dump(title, message):
if _traceEnabled:
_logger.debug("--- " + title + " ---")
_logger.debug(message)
_logger.debug("-----------------------")
def error(msg):
_logger.error(msg)
def warning(msg):
_logger.warning(msg)
def debug(msg):
_logger.debug(msg)
def trace(msg):
if _traceEnabled:
_logger.debug(msg)
def isEnabledForError():
return _logger.isEnabledFor(logging.ERROR)
def isEnabledForDebug():
return _logger.isEnabledFor(logging.DEBUG)
def <|fim_middle|>():
return _traceEnabled
<|fim▁end|> | isEnabledForTrace |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:<|fim▁hole|> stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result<|fim▁end|> | stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED: |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
<|fim_middle|>
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
<|fim_middle|>
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
<|fim_middle|>
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
<|fim_middle|>
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
<|fim_middle|>
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
<|fim_middle|>
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
<|fim_middle|>
<|fim▁end|> | api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
<|fim_middle|>
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | """Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
<|fim_middle|>
<|fim▁end|> | """Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
<|fim_middle|>
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_counts_by_month() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
<|fim_middle|>
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
<|fim_middle|>
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_counts_by_month_published() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
<|fim_middle|>
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_count() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
<|fim_middle|>
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_count_unpublished() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
<|fim_middle|>
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_count_published() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
<|fim_middle|>
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_affiliation_counts() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
<|fim_middle|>
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
<|fim_middle|>
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_affiliation_counts_published() |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
<|fim_middle|>
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | return True |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
<|fim_middle|>
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | exclude_uncategorized = False |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
<|fim_middle|>
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | exclude_uncategorized = True |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
<|fim_middle|>
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized) |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
<|fim_middle|>
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized) |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
<|fim_middle|>
return stats_result
<|fim▁end|> | stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized) |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def <|fim_middle|>(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | get_stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def <|fim_middle|>(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | get_stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def <|fim_middle|>(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | get_stats_result |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def <|fim_middle|>(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | is_show_uncategorized |
<|file_name|>stats_views_dataverses.py<|end_file_name|><|fim▁begin|>from .stats_view_base import StatsViewSwagger, StatsViewSwaggerKeyRequired
from .stats_util_dataverses import StatsMakerDataverses
class DataverseCountByMonthView(StatsViewSwaggerKeyRequired):
"""API View - Dataverse counts by Month."""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/monthly'
summary = ('Number of published Dataverses by'
' the month they were created*. (*'
' Not month published)')
description = ('Returns a list of counts and'
' cumulative counts of all Dataverses added in a month')
description_200 = 'A list of Dataverse counts by month'
param_names = StatsViewSwagger.PARAM_DV_API_KEY +\
StatsViewSwagger.BASIC_DATE_PARAMS +\
StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_month()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_month_unpublished()
else:
stats_result = stats_datasets.get_dataverse_counts_by_month_published()
return stats_result
class DataverseTotalCounts(StatsViewSwaggerKeyRequired):
"""API View - Total count of all Dataverses"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count'
summary = ('Simple count of published Dataverses')
description = ('Returns number of published Dataverses')
description_200 = 'Number of published Dataverses'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS + StatsViewSwagger.PRETTY_JSON_PARAM
tags = [StatsViewSwagger.TAG_DATAVERSES]
result_name = StatsViewSwagger.RESULT_NAME_TOTAL_COUNT
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_count()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_count_unpublished()
else:
stats_result = stats_datasets.get_dataverse_count_published()
return stats_result
class DataverseAffiliationCounts(StatsViewSwaggerKeyRequired):
"""API View - Number of Dataverses by Affiliation"""
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-affiliation'
summary = ('Number of Dataverses by Affiliation')
description = ('Number of Dataverses by Affiliation.')
description_200 = 'Number of published Dataverses by Affiliation.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY\
+ StatsViewSwagger.PUBLISH_PARAMS\
+ StatsViewSwagger.PRETTY_JSON_PARAM\
+ StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_AFFILIATION_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def get_stats_result(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_affiliation_counts()
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_affiliation_counts_unpublished()
else:
stats_result = stats_datasets.get_dataverse_affiliation_counts_published()
return stats_result
class DataverseTypeCounts(StatsViewSwaggerKeyRequired):
# Define the swagger attributes
# Note: api_path must match the path in urls.py
#
api_path = '/dataverses/count/by-type'
summary = ('Number of Dataverses by Type')
description = ('Number of Dataverses by Type.')
description_200 = 'Number of published Dataverses by Type.'
param_names = StatsViewSwagger.PARAM_DV_API_KEY + StatsViewSwagger.PUBLISH_PARAMS +\
StatsViewSwagger.PRETTY_JSON_PARAM +\
StatsViewSwagger.DV_TYPE_UNCATEGORIZED_PARAM +\
StatsViewSwagger.PARAM_AS_CSV
result_name = StatsViewSwagger.RESULT_NAME_DATAVERSE_TYPE_COUNTS
tags = [StatsViewSwagger.TAG_DATAVERSES]
def is_show_uncategorized(self, request):
"""Return the result of the "?show_uncategorized" query string param"""
show_uncategorized = request.GET.get('show_uncategorized', False)
if show_uncategorized is True or show_uncategorized == 'true':
return True
return False
def <|fim_middle|>(self, request):
"""Return the StatsResult object for this statistic"""
stats_datasets = StatsMakerDataverses(**request.GET.dict())
if self.is_show_uncategorized(request):
exclude_uncategorized = False
else:
exclude_uncategorized = True
pub_state = self.get_pub_state(request)
if pub_state == self.PUB_STATE_ALL:
stats_result = stats_datasets.get_dataverse_counts_by_type(exclude_uncategorized)
elif pub_state == self.PUB_STATE_UNPUBLISHED:
stats_result = stats_datasets.get_dataverse_counts_by_type_unpublished(exclude_uncategorized)
else:
stats_result = stats_datasets.get_dataverse_counts_by_type_published(exclude_uncategorized)
return stats_result
<|fim▁end|> | get_stats_result |
<|file_name|>101_test.py<|end_file_name|><|fim▁begin|>from fruits import validate_fruit<|fim▁hole|>
print fruits
def list_fruits(fruits, byName=True):
if byName:
# WARNING: this won't make a copy of the list and return it. It will change the list FOREVER
fruits.sort()
for index, fruit in enumerate(fruits):
if validate_fruit(fruit):
print "Fruit nr %d is %s" % (index, fruit)
else:
print "This %s is no fruit!" % (fruit)
list_fruits(fruits)
print fruits<|fim▁end|> |
fruits = ["banana", "lemon", "apple", "orange", "batman"] |
<|file_name|>101_test.py<|end_file_name|><|fim▁begin|>from fruits import validate_fruit
fruits = ["banana", "lemon", "apple", "orange", "batman"]
print fruits
def list_fruits(fruits, byName=True):
<|fim_middle|>
list_fruits(fruits)
print fruits
<|fim▁end|> | if byName:
# WARNING: this won't make a copy of the list and return it. It will change the list FOREVER
fruits.sort()
for index, fruit in enumerate(fruits):
if validate_fruit(fruit):
print "Fruit nr %d is %s" % (index, fruit)
else:
print "This %s is no fruit!" % (fruit) |
<|file_name|>101_test.py<|end_file_name|><|fim▁begin|>from fruits import validate_fruit
fruits = ["banana", "lemon", "apple", "orange", "batman"]
print fruits
def list_fruits(fruits, byName=True):
if byName:
# WARNING: this won't make a copy of the list and return it. It will change the list FOREVER
<|fim_middle|>
for index, fruit in enumerate(fruits):
if validate_fruit(fruit):
print "Fruit nr %d is %s" % (index, fruit)
else:
print "This %s is no fruit!" % (fruit)
list_fruits(fruits)
print fruits
<|fim▁end|> | fruits.sort() |
<|file_name|>101_test.py<|end_file_name|><|fim▁begin|>from fruits import validate_fruit
fruits = ["banana", "lemon", "apple", "orange", "batman"]
print fruits
def list_fruits(fruits, byName=True):
if byName:
# WARNING: this won't make a copy of the list and return it. It will change the list FOREVER
fruits.sort()
for index, fruit in enumerate(fruits):
if validate_fruit(fruit):
<|fim_middle|>
else:
print "This %s is no fruit!" % (fruit)
list_fruits(fruits)
print fruits
<|fim▁end|> | print "Fruit nr %d is %s" % (index, fruit) |
<|file_name|>101_test.py<|end_file_name|><|fim▁begin|>from fruits import validate_fruit
fruits = ["banana", "lemon", "apple", "orange", "batman"]
print fruits
def list_fruits(fruits, byName=True):
if byName:
# WARNING: this won't make a copy of the list and return it. It will change the list FOREVER
fruits.sort()
for index, fruit in enumerate(fruits):
if validate_fruit(fruit):
print "Fruit nr %d is %s" % (index, fruit)
else:
<|fim_middle|>
list_fruits(fruits)
print fruits
<|fim▁end|> | print "This %s is no fruit!" % (fruit) |
<|file_name|>101_test.py<|end_file_name|><|fim▁begin|>from fruits import validate_fruit
fruits = ["banana", "lemon", "apple", "orange", "batman"]
print fruits
def <|fim_middle|>(fruits, byName=True):
if byName:
# WARNING: this won't make a copy of the list and return it. It will change the list FOREVER
fruits.sort()
for index, fruit in enumerate(fruits):
if validate_fruit(fruit):
print "Fruit nr %d is %s" % (index, fruit)
else:
print "This %s is no fruit!" % (fruit)
list_fruits(fruits)
print fruits
<|fim▁end|> | list_fruits |
<|file_name|>urls.py<|end_file_name|><|fim▁begin|># ETConf -- web-based user-friendly computer hardware configurator
# Copyright (C) 2010-2011 ETegro Technologies, PLC <http://etegro.com/>
# Sergey Matveev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<|fim▁hole|># along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls.defaults import *
urlpatterns = patterns( "configurator.giver.views",
( r"^perform/(?P<computermodel_alias>.+)/$", "perform" ),
( r"^configurator/(?P<computermodel_alias>.+)/$", "configurator" ),
( r"^computermodel/request/(?P<computermodel_alias>.+)$", "computermodel_request" ),
)<|fim▁end|> | # GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
delim = sys.argv[3]
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: graph[src] = {}
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
graph[src][dst] += 1
if dst in graph and src in graph[dst]:
graph[dst][src] += 2
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:<|fim▁hole|> count += 1
if val in [1,3]:
w_dir += 1
if val in [1,2,3]:
wo_dir += 1
print "%s\t%s" % (w_dir/count, wo_dir/count)<|fim▁end|> | val = graph[src][dst] |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
<|fim_middle|>
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: graph[src] = {}
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
graph[src][dst] += 1
if dst in graph and src in graph[dst]:
graph[dst][src] += 2
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:
val = graph[src][dst]
count += 1
if val in [1,3]:
w_dir += 1
if val in [1,2,3]:
wo_dir += 1
print "%s\t%s" % (w_dir/count, wo_dir/count)
<|fim▁end|> | delim = sys.argv[3] |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
delim = sys.argv[3]
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: <|fim_middle|>
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
graph[src][dst] += 1
if dst in graph and src in graph[dst]:
graph[dst][src] += 2
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:
val = graph[src][dst]
count += 1
if val in [1,3]:
w_dir += 1
if val in [1,2,3]:
wo_dir += 1
print "%s\t%s" % (w_dir/count, wo_dir/count)
<|fim▁end|> | graph[src] = {} |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
delim = sys.argv[3]
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: graph[src] = {}
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
<|fim_middle|>
if dst in graph and src in graph[dst]:
graph[dst][src] += 2
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:
val = graph[src][dst]
count += 1
if val in [1,3]:
w_dir += 1
if val in [1,2,3]:
wo_dir += 1
print "%s\t%s" % (w_dir/count, wo_dir/count)
<|fim▁end|> | graph[src][dst] += 1 |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
delim = sys.argv[3]
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: graph[src] = {}
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
graph[src][dst] += 1
if dst in graph and src in graph[dst]:
<|fim_middle|>
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:
val = graph[src][dst]
count += 1
if val in [1,3]:
w_dir += 1
if val in [1,2,3]:
wo_dir += 1
print "%s\t%s" % (w_dir/count, wo_dir/count)
<|fim▁end|> | graph[dst][src] += 2 |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
delim = sys.argv[3]
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: graph[src] = {}
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
graph[src][dst] += 1
if dst in graph and src in graph[dst]:
graph[dst][src] += 2
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:
val = graph[src][dst]
count += 1
if val in [1,3]:
<|fim_middle|>
if val in [1,2,3]:
wo_dir += 1
print "%s\t%s" % (w_dir/count, wo_dir/count)
<|fim▁end|> | w_dir += 1 |
<|file_name|>tag_follow_disagreement.py<|end_file_name|><|fim▁begin|>import sys
tagging_filepath = sys.argv[1]
following_filepath = sys.argv[2]
delim = '\t'
if len(sys.argv) > 3:
delim = sys.argv[3]
graph = {}
for line in open(tagging_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if not src in graph: graph[src] = {}
graph[src][dst] = 0
for line in open(following_filepath):
entry = line.rstrip().split('\t')
src = entry[0]
dst = entry[1]
if src in graph and dst in graph[src]:
graph[src][dst] += 1
if dst in graph and src in graph[dst]:
graph[dst][src] += 2
w_dir = 0
wo_dir = 0
count = 0.0
for src in graph:
for dst in graph[src]:
val = graph[src][dst]
count += 1
if val in [1,3]:
w_dir += 1
if val in [1,2,3]:
<|fim_middle|>
print "%s\t%s" % (w_dir/count, wo_dir/count)
<|fim▁end|> | wo_dir += 1 |
<|file_name|>__main__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import argparse
from . import core
from . import gui
def main():
parser = argparse.ArgumentParser(
description="Track opponent's mulligan in the game of Hearthstone.")
parser.add_argument('--gui', action='store_true')
args = parser.parse_args()
if args.gui:
gui.main()
else:
core.main()
if __name__ == '__main__':<|fim▁hole|><|fim▁end|> | main() |
<|file_name|>__main__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import argparse
from . import core
from . import gui
def main():
<|fim_middle|>
if __name__ == '__main__':
main()
<|fim▁end|> | parser = argparse.ArgumentParser(
description="Track opponent's mulligan in the game of Hearthstone.")
parser.add_argument('--gui', action='store_true')
args = parser.parse_args()
if args.gui:
gui.main()
else:
core.main() |
<|file_name|>__main__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import argparse
from . import core
from . import gui
def main():
parser = argparse.ArgumentParser(
description="Track opponent's mulligan in the game of Hearthstone.")
parser.add_argument('--gui', action='store_true')
args = parser.parse_args()
if args.gui:
<|fim_middle|>
else:
core.main()
if __name__ == '__main__':
main()
<|fim▁end|> | gui.main() |
<|file_name|>__main__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import argparse
from . import core
from . import gui
def main():
parser = argparse.ArgumentParser(
description="Track opponent's mulligan in the game of Hearthstone.")
parser.add_argument('--gui', action='store_true')
args = parser.parse_args()
if args.gui:
gui.main()
else:
<|fim_middle|>
if __name__ == '__main__':
main()
<|fim▁end|> | core.main() |
<|file_name|>__main__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import argparse
from . import core
from . import gui
def main():
parser = argparse.ArgumentParser(
description="Track opponent's mulligan in the game of Hearthstone.")
parser.add_argument('--gui', action='store_true')
args = parser.parse_args()
if args.gui:
gui.main()
else:
core.main()
if __name__ == '__main__':
<|fim_middle|>
<|fim▁end|> | main() |
<|file_name|>__main__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import argparse
from . import core
from . import gui
def <|fim_middle|>():
parser = argparse.ArgumentParser(
description="Track opponent's mulligan in the game of Hearthstone.")
parser.add_argument('--gui', action='store_true')
args = parser.parse_args()
if args.gui:
gui.main()
else:
core.main()
if __name__ == '__main__':
main()
<|fim▁end|> | main |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at<|fim▁hole|># http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
def __init__(self, type_):
self.type = type_
def create(self, **kwargs):
return self.type(**kwargs)<|fim▁end|> | # |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
<|fim_middle|>
class Factory(object):
def __init__(self, type_):
self.type = type_
def create(self, **kwargs):
return self.type(**kwargs)
<|fim▁end|> | """
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
<|fim_middle|>
<|fim▁end|> | def __init__(self, type_):
self.type = type_
def create(self, **kwargs):
return self.type(**kwargs) |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
def __init__(self, type_):
<|fim_middle|>
def create(self, **kwargs):
return self.type(**kwargs)
<|fim▁end|> | self.type = type_ |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
def __init__(self, type_):
self.type = type_
def create(self, **kwargs):
<|fim_middle|>
<|fim▁end|> | return self.type(**kwargs) |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def <|fim_middle|>(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
def __init__(self, type_):
self.type = type_
def create(self, **kwargs):
return self.type(**kwargs)
<|fim▁end|> | create |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
def <|fim_middle|>(self, type_):
self.type = type_
def create(self, **kwargs):
return self.type(**kwargs)
<|fim▁end|> | __init__ |
<|file_name|>factory.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 DST Controls
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
osisoftpy.factory
~~~~~~~~~~~~
"""
from __future__ import (absolute_import, division, unicode_literals)
from future.builtins import *
from future.utils import iteritems
def create(factory, thing, session, webapi=None):
"""
Return an object created with factory
:param webapi:
:param factory:
:param params:
:param session:
:return:
"""
payload = dict(map(lambda k_v: (k_v[0].lower(), k_v[1]), iteritems(thing)))
# added to avoid creating Value objects if the value was considered bad values
# but we don't need this since we don't want the library to cull bad values that
# the pi web api gave us.
#
# if 'good' in payload:
# if not payload['good']:
# return None
payload.update({'session': session, 'webapi': webapi})
thing = factory.create(**payload)
return thing
class Factory(object):
def __init__(self, type_):
self.type = type_
def <|fim_middle|>(self, **kwargs):
return self.type(**kwargs)
<|fim▁end|> | create |
<|file_name|>counter.py<|end_file_name|><|fim▁begin|>import cv2
import numpy as np
import datetime as dt
# constant
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
OPENCV_METHODS = {
"Correlation": 0,
"Chi-Squared": 1,
"Intersection": 2,
"Hellinger": 3}
hist_limit = 0.6
ttl = 1 * 60
q_limit = 3
<|fim▁hole|>total_delta = 0
stm = {}
q = []
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
video_capture = cv2.VideoCapture(0)
while True:
for t in list(stm): # short term memory
if (dt.datetime.now() - t).seconds > ttl:
stm.pop(t, None)
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
count = len(faces)
if len(q) >= q_limit: del q[0]
q.append(count)
isSame = True
for c in q: # Protect from fluctuation
if c != count: isSame = False
if isSame is False: continue
max_hist = 0
total_delta = 0
for (x, y, w, h) in faces:
# Draw a rectangle around the faces
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
if count == prev_count: continue
# set up the ROI
face = frame[y: y + h, x: x + w]
hsv_roi = cv2.cvtColor(face, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(face, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
face_hist = cv2.calcHist([face], [0], mask, [180], [0, 180])
cv2.normalize(face_hist, face_hist, 0, 255, cv2.NORM_MINMAX)
isFound = False
for t in stm:
hist_compare = cv2.compareHist(stm[t], face_hist, OPENCV_METHODS["Correlation"])
if hist_compare > max_hist: max_hist = hist_compare
if hist_compare >= hist_limit: isFound = True
if (len(stm) == 0) or (isFound is False and max_hist > 0):
total_delta += 1
stm[dt.datetime.now()] = face_hist
if prev_count != count:
total_count += total_delta
print("", count, " > ", total_count)
prev_count = count
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()<|fim▁end|> | # init variables
total_count = 0
prev_count = 0 |
<|file_name|>counter.py<|end_file_name|><|fim▁begin|>import cv2
import numpy as np
import datetime as dt
# constant
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
OPENCV_METHODS = {
"Correlation": 0,
"Chi-Squared": 1,
"Intersection": 2,
"Hellinger": 3}
hist_limit = 0.6
ttl = 1 * 60
q_limit = 3
# init variables
total_count = 0
prev_count = 0
total_delta = 0
stm = {}
q = []
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
video_capture = cv2.VideoCapture(0)
while True:
for t in list(stm): # short term memory
if (dt.datetime.now() - t).seconds > ttl:
<|fim_middle|>
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
count = len(faces)
if len(q) >= q_limit: del q[0]
q.append(count)
isSame = True
for c in q: # Protect from fluctuation
if c != count: isSame = False
if isSame is False: continue
max_hist = 0
total_delta = 0
for (x, y, w, h) in faces:
# Draw a rectangle around the faces
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
if count == prev_count: continue
# set up the ROI
face = frame[y: y + h, x: x + w]
hsv_roi = cv2.cvtColor(face, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(face, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
face_hist = cv2.calcHist([face], [0], mask, [180], [0, 180])
cv2.normalize(face_hist, face_hist, 0, 255, cv2.NORM_MINMAX)
isFound = False
for t in stm:
hist_compare = cv2.compareHist(stm[t], face_hist, OPENCV_METHODS["Correlation"])
if hist_compare > max_hist: max_hist = hist_compare
if hist_compare >= hist_limit: isFound = True
if (len(stm) == 0) or (isFound is False and max_hist > 0):
total_delta += 1
stm[dt.datetime.now()] = face_hist
if prev_count != count:
total_count += total_delta
print("", count, " > ", total_count)
prev_count = count
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
<|fim▁end|> | stm.pop(t, None) |
<|file_name|>counter.py<|end_file_name|><|fim▁begin|>import cv2
import numpy as np
import datetime as dt
# constant
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
OPENCV_METHODS = {
"Correlation": 0,
"Chi-Squared": 1,
"Intersection": 2,
"Hellinger": 3}
hist_limit = 0.6
ttl = 1 * 60
q_limit = 3
# init variables
total_count = 0
prev_count = 0
total_delta = 0
stm = {}
q = []
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
video_capture = cv2.VideoCapture(0)
while True:
for t in list(stm): # short term memory
if (dt.datetime.now() - t).seconds > ttl:
stm.pop(t, None)
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
count = len(faces)
if len(q) >= q_limit: <|fim_middle|>
q.append(count)
isSame = True
for c in q: # Protect from fluctuation
if c != count: isSame = False
if isSame is False: continue
max_hist = 0
total_delta = 0
for (x, y, w, h) in faces:
# Draw a rectangle around the faces
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
if count == prev_count: continue
# set up the ROI
face = frame[y: y + h, x: x + w]
hsv_roi = cv2.cvtColor(face, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(face, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
face_hist = cv2.calcHist([face], [0], mask, [180], [0, 180])
cv2.normalize(face_hist, face_hist, 0, 255, cv2.NORM_MINMAX)
isFound = False
for t in stm:
hist_compare = cv2.compareHist(stm[t], face_hist, OPENCV_METHODS["Correlation"])
if hist_compare > max_hist: max_hist = hist_compare
if hist_compare >= hist_limit: isFound = True
if (len(stm) == 0) or (isFound is False and max_hist > 0):
total_delta += 1
stm[dt.datetime.now()] = face_hist
if prev_count != count:
total_count += total_delta
print("", count, " > ", total_count)
prev_count = count
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
<|fim▁end|> | del q[0] |
<|file_name|>counter.py<|end_file_name|><|fim▁begin|>import cv2
import numpy as np
import datetime as dt
# constant
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
OPENCV_METHODS = {
"Correlation": 0,
"Chi-Squared": 1,
"Intersection": 2,
"Hellinger": 3}
hist_limit = 0.6
ttl = 1 * 60
q_limit = 3
# init variables
total_count = 0
prev_count = 0
total_delta = 0
stm = {}
q = []
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
video_capture = cv2.VideoCapture(0)
while True:
for t in list(stm): # short term memory
if (dt.datetime.now() - t).seconds > ttl:
stm.pop(t, None)
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
count = len(faces)
if len(q) >= q_limit: del q[0]
q.append(count)
isSame = True
for c in q: # Protect from fluctuation
if c != count: <|fim_middle|>
if isSame is False: continue
max_hist = 0
total_delta = 0
for (x, y, w, h) in faces:
# Draw a rectangle around the faces
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
if count == prev_count: continue
# set up the ROI
face = frame[y: y + h, x: x + w]
hsv_roi = cv2.cvtColor(face, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(face, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
face_hist = cv2.calcHist([face], [0], mask, [180], [0, 180])
cv2.normalize(face_hist, face_hist, 0, 255, cv2.NORM_MINMAX)
isFound = False
for t in stm:
hist_compare = cv2.compareHist(stm[t], face_hist, OPENCV_METHODS["Correlation"])
if hist_compare > max_hist: max_hist = hist_compare
if hist_compare >= hist_limit: isFound = True
if (len(stm) == 0) or (isFound is False and max_hist > 0):
total_delta += 1
stm[dt.datetime.now()] = face_hist
if prev_count != count:
total_count += total_delta
print("", count, " > ", total_count)
prev_count = count
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
<|fim▁end|> | isSame = False |
<|file_name|>counter.py<|end_file_name|><|fim▁begin|>import cv2
import numpy as np
import datetime as dt
# constant
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
OPENCV_METHODS = {
"Correlation": 0,
"Chi-Squared": 1,
"Intersection": 2,
"Hellinger": 3}
hist_limit = 0.6
ttl = 1 * 60
q_limit = 3
# init variables
total_count = 0
prev_count = 0
total_delta = 0
stm = {}
q = []
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
video_capture = cv2.VideoCapture(0)
while True:
for t in list(stm): # short term memory
if (dt.datetime.now() - t).seconds > ttl:
stm.pop(t, None)
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
count = len(faces)
if len(q) >= q_limit: del q[0]
q.append(count)
isSame = True
for c in q: # Protect from fluctuation
if c != count: isSame = False
if isSame is False: <|fim_middle|>
max_hist = 0
total_delta = 0
for (x, y, w, h) in faces:
# Draw a rectangle around the faces
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
if count == prev_count: continue
# set up the ROI
face = frame[y: y + h, x: x + w]
hsv_roi = cv2.cvtColor(face, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(face, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
face_hist = cv2.calcHist([face], [0], mask, [180], [0, 180])
cv2.normalize(face_hist, face_hist, 0, 255, cv2.NORM_MINMAX)
isFound = False
for t in stm:
hist_compare = cv2.compareHist(stm[t], face_hist, OPENCV_METHODS["Correlation"])
if hist_compare > max_hist: max_hist = hist_compare
if hist_compare >= hist_limit: isFound = True
if (len(stm) == 0) or (isFound is False and max_hist > 0):
total_delta += 1
stm[dt.datetime.now()] = face_hist
if prev_count != count:
total_count += total_delta
print("", count, " > ", total_count)
prev_count = count
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
<|fim▁end|> | continue |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.