body
stringlengths 26
98.2k
| body_hash
int64 -9,222,864,604,528,158,000
9,221,803,474B
| docstring
stringlengths 1
16.8k
| path
stringlengths 5
230
| name
stringlengths 1
96
| repository_name
stringlengths 7
89
| lang
stringclasses 1
value | body_without_docstring
stringlengths 20
98.2k
|
---|---|---|---|---|---|---|---|
def _datetime_object_to_rfc_date_str(datetime_obj):
' Returns a date string to the RFC 3339 standard '
return datetime_obj.strftime(_RFC3339_DATE_FORMAT)
| -6,955,022,055,545,367,000 |
Returns a date string to the RFC 3339 standard
|
precisionmapper/__init__.py
|
_datetime_object_to_rfc_date_str
|
tducret/precisionmapper-python
|
python
|
def _datetime_object_to_rfc_date_str(datetime_obj):
' '
return datetime_obj.strftime(_RFC3339_DATE_FORMAT)
|
def _rfc_date_str_to_datetime_object(rfc_date_str):
' Returns a date string to the RFC 3339 standard '
return datetime.strptime(rfc_date_str, _RFC3339_DATE_FORMAT)
| -4,682,690,617,751,041,000 |
Returns a date string to the RFC 3339 standard
|
precisionmapper/__init__.py
|
_rfc_date_str_to_datetime_object
|
tducret/precisionmapper-python
|
python
|
def _rfc_date_str_to_datetime_object(rfc_date_str):
' '
return datetime.strptime(rfc_date_str, _RFC3339_DATE_FORMAT)
|
def _datetime_object_to_short_date_str(datetime_obj):
' Returns a short date string '
return datetime_obj.strftime(_SHORT_DATE_FORMAT)
| 4,117,565,389,665,448,000 |
Returns a short date string
|
precisionmapper/__init__.py
|
_datetime_object_to_short_date_str
|
tducret/precisionmapper-python
|
python
|
def _datetime_object_to_short_date_str(datetime_obj):
' '
return datetime_obj.strftime(_SHORT_DATE_FORMAT)
|
def get_authenticity_token(self, url=_SIGNIN_URL):
' Returns an authenticity_token, mandatory for signing in '
res = self.client._get(url=url, expected_status_code=200)
soup = BeautifulSoup(res.text, _DEFAULT_BEAUTIFULSOUP_PARSER)
selection = soup.select(_AUTHENTICITY_TOKEN_SELECTOR)
try:
authenticity_token = selection[0].get('content')
except:
raise ValueError('authenticity_token not found in {} with {}\n{}'.format(_SIGNIN_URL, _AUTHENTICITY_TOKEN_SELECTOR, res.text))
return authenticity_token
| 2,306,949,847,597,205,500 |
Returns an authenticity_token, mandatory for signing in
|
precisionmapper/__init__.py
|
get_authenticity_token
|
tducret/precisionmapper-python
|
python
|
def get_authenticity_token(self, url=_SIGNIN_URL):
' '
res = self.client._get(url=url, expected_status_code=200)
soup = BeautifulSoup(res.text, _DEFAULT_BEAUTIFULSOUP_PARSER)
selection = soup.select(_AUTHENTICITY_TOKEN_SELECTOR)
try:
authenticity_token = selection[0].get('content')
except:
raise ValueError('authenticity_token not found in {} with {}\n{}'.format(_SIGNIN_URL, _AUTHENTICITY_TOKEN_SELECTOR, res.text))
return authenticity_token
|
def get_surveys(self, url=_SURVEYS_URL):
' Function to get the surveys for the account '
res = self.client._get(url=url, expected_status_code=200)
soup = BeautifulSoup(res.text, _DEFAULT_BEAUTIFULSOUP_PARSER)
surveys_soup = soup.select(_SURVEYS_SELECTOR)
survey_list = []
for survey_soup in surveys_soup:
survey_name = _css_select(survey_soup, _SURVEY_NAME_SELECTOR)
try:
url = survey_soup.select(_SURVEY_URL_SELECTOR)[0]['href']
except:
raise ValueError('Cannot get URL for the survey with css selector {}'.format(_SURVEY_URL_SELECTOR))
try:
id = int(url.split('survey_id=')[1].split('&')[0])
except:
raise ValueError('Cannot extract id from URL {}'.format(url))
survey_location = _css_select(survey_soup, _SURVEY_LOCATION_SELECTOR)
try:
survey_epoch = int(survey_soup.select(_SURVEY_DATE_SELECTOR)[0]['epoch'])
survey_date_obj = datetime.fromtimestamp(survey_epoch)
survey_date = _datetime_object_to_rfc_date_str(survey_date_obj)
except:
raise ValueError('Cannot get date for the survey with css selector {}'.format(_SURVEY_DATE_SELECTOR))
survey_img_nb_and_size = survey_soup.select(_SURVEY_IMG_NB_AND_SIZE_SELECTOR)
try:
survey_img_nb = survey_img_nb_and_size[0].text
survey_img_nb = int(survey_img_nb.split(' ')[0])
except:
raise ValueError('Cannot get or convert image number, survey_img_nb_and_size = {}'.format(survey_img_nb_and_size))
try:
survey_size = survey_img_nb_and_size[1].text
except:
raise ValueError('Cannot get survey size, survey_img_nb_and_size = {}'.format(survey_img_nb_and_size))
sensor = _css_select(survey_soup, _SURVEY_SENSOR_SELECTOR)
survey = Survey(id=id, name=survey_name, url=url, date=survey_date, location=survey_location, image_nb=survey_img_nb, size=survey_size, sensor=sensor)
survey_list.append(survey)
return survey_list
| -8,596,098,261,441,833,000 |
Function to get the surveys for the account
|
precisionmapper/__init__.py
|
get_surveys
|
tducret/precisionmapper-python
|
python
|
def get_surveys(self, url=_SURVEYS_URL):
' '
res = self.client._get(url=url, expected_status_code=200)
soup = BeautifulSoup(res.text, _DEFAULT_BEAUTIFULSOUP_PARSER)
surveys_soup = soup.select(_SURVEYS_SELECTOR)
survey_list = []
for survey_soup in surveys_soup:
survey_name = _css_select(survey_soup, _SURVEY_NAME_SELECTOR)
try:
url = survey_soup.select(_SURVEY_URL_SELECTOR)[0]['href']
except:
raise ValueError('Cannot get URL for the survey with css selector {}'.format(_SURVEY_URL_SELECTOR))
try:
id = int(url.split('survey_id=')[1].split('&')[0])
except:
raise ValueError('Cannot extract id from URL {}'.format(url))
survey_location = _css_select(survey_soup, _SURVEY_LOCATION_SELECTOR)
try:
survey_epoch = int(survey_soup.select(_SURVEY_DATE_SELECTOR)[0]['epoch'])
survey_date_obj = datetime.fromtimestamp(survey_epoch)
survey_date = _datetime_object_to_rfc_date_str(survey_date_obj)
except:
raise ValueError('Cannot get date for the survey with css selector {}'.format(_SURVEY_DATE_SELECTOR))
survey_img_nb_and_size = survey_soup.select(_SURVEY_IMG_NB_AND_SIZE_SELECTOR)
try:
survey_img_nb = survey_img_nb_and_size[0].text
survey_img_nb = int(survey_img_nb.split(' ')[0])
except:
raise ValueError('Cannot get or convert image number, survey_img_nb_and_size = {}'.format(survey_img_nb_and_size))
try:
survey_size = survey_img_nb_and_size[1].text
except:
raise ValueError('Cannot get survey size, survey_img_nb_and_size = {}'.format(survey_img_nb_and_size))
sensor = _css_select(survey_soup, _SURVEY_SENSOR_SELECTOR)
survey = Survey(id=id, name=survey_name, url=url, date=survey_date, location=survey_location, image_nb=survey_img_nb, size=survey_size, sensor=sensor)
survey_list.append(survey)
return survey_list
|
def test_download_wheel_bad_output(mocker, for_py_version, session_app_data):
'if the download contains no match for what wheel was downloaded, pick one that matches from target'
distribution = 'setuptools'
p_open = mocker.MagicMock()
mocker.patch('virtualenv.seed.wheels.acquire.Popen', return_value=p_open)
p_open.communicate.return_value = ('', '')
p_open.returncode = 0
embed = get_embed_wheel(distribution, for_py_version)
as_path = mocker.MagicMock()
available = discover_wheels(BUNDLE_FOLDER, 'setuptools', None, for_py_version)
as_path.iterdir.return_value = [i.path for i in available]
result = download_wheel(distribution, '=={}'.format(embed.version), for_py_version, [], session_app_data, as_path)
assert (result.path == embed.path)
| -8,604,230,394,771,363,000 |
if the download contains no match for what wheel was downloaded, pick one that matches from target
|
tests/unit/seed/wheels/test_acquire.py
|
test_download_wheel_bad_output
|
MShaffar19/virtualenv
|
python
|
def test_download_wheel_bad_output(mocker, for_py_version, session_app_data):
distribution = 'setuptools'
p_open = mocker.MagicMock()
mocker.patch('virtualenv.seed.wheels.acquire.Popen', return_value=p_open)
p_open.communicate.return_value = (, )
p_open.returncode = 0
embed = get_embed_wheel(distribution, for_py_version)
as_path = mocker.MagicMock()
available = discover_wheels(BUNDLE_FOLDER, 'setuptools', None, for_py_version)
as_path.iterdir.return_value = [i.path for i in available]
result = download_wheel(distribution, '=={}'.format(embed.version), for_py_version, [], session_app_data, as_path)
assert (result.path == embed.path)
|
@transactional_session
def add_identity(identity, type, email, password=None, session=None):
'\n Creates a user identity.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, ssh, saml)\n :param email: The Email address associated with the identity.\n :param password: If type==userpass, this sets the password.\n :param session: The database session in use.\n '
if ((type == IdentityType.USERPASS) and (password is None)):
raise exception.IdentityError('You must provide a password!')
new_id = models.Identity()
new_id.update({'identity': identity, 'identity_type': type, 'email': email})
if ((type == IdentityType.USERPASS) and (password is not None)):
salt = os.urandom(255)
if six.PY3:
decoded_salt = b64encode(salt).decode()
salted_password = ('%s%s' % (decoded_salt, password)).encode()
else:
salted_password = ('%s%s' % (salt, str(password)))
password = hashlib.sha256(salted_password).hexdigest()
new_id.update({'salt': salt, 'password': password, 'email': email})
try:
new_id.save(session=session)
except IntegrityError as e:
if match('.*IntegrityError.*1062.*Duplicate entry.*for key.*', e.args[0]):
raise exception.Duplicate(("Identity pair '%s','%s' already exists!" % (identity, type)))
raise exception.DatabaseException(str(e))
| -3,860,912,868,457,641,500 |
Creates a user identity.
:param identity: The identity key name. For example x509 DN, or a username.
:param type: The type of the authentication (x509, gss, userpass, ssh, saml)
:param email: The Email address associated with the identity.
:param password: If type==userpass, this sets the password.
:param session: The database session in use.
|
lib/rucio/core/identity.py
|
add_identity
|
Pranay144/rucio
|
python
|
@transactional_session
def add_identity(identity, type, email, password=None, session=None):
'\n Creates a user identity.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, ssh, saml)\n :param email: The Email address associated with the identity.\n :param password: If type==userpass, this sets the password.\n :param session: The database session in use.\n '
if ((type == IdentityType.USERPASS) and (password is None)):
raise exception.IdentityError('You must provide a password!')
new_id = models.Identity()
new_id.update({'identity': identity, 'identity_type': type, 'email': email})
if ((type == IdentityType.USERPASS) and (password is not None)):
salt = os.urandom(255)
if six.PY3:
decoded_salt = b64encode(salt).decode()
salted_password = ('%s%s' % (decoded_salt, password)).encode()
else:
salted_password = ('%s%s' % (salt, str(password)))
password = hashlib.sha256(salted_password).hexdigest()
new_id.update({'salt': salt, 'password': password, 'email': email})
try:
new_id.save(session=session)
except IntegrityError as e:
if match('.*IntegrityError.*1062.*Duplicate entry.*for key.*', e.args[0]):
raise exception.Duplicate(("Identity pair '%s','%s' already exists!" % (identity, type)))
raise exception.DatabaseException(str(e))
|
@transactional_session
def del_identity(identity, type, session=None):
'\n Deletes a user identity.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param session: The database session in use.\n '
id = session.query(models.Identity).filter_by(identity=identity, identity_type=type).first()
if (id is None):
raise exception.IdentityError(("Identity ('%s','%s') does not exist!" % (identity, type)))
id.delete(session=session)
| -5,832,953,435,856,953,000 |
Deletes a user identity.
:param identity: The identity key name. For example x509 DN, or a username.
:param type: The type of the authentication (x509, gss, userpass, saml).
:param session: The database session in use.
|
lib/rucio/core/identity.py
|
del_identity
|
Pranay144/rucio
|
python
|
@transactional_session
def del_identity(identity, type, session=None):
'\n Deletes a user identity.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param session: The database session in use.\n '
id = session.query(models.Identity).filter_by(identity=identity, identity_type=type).first()
if (id is None):
raise exception.IdentityError(("Identity ('%s','%s') does not exist!" % (identity, type)))
id.delete(session=session)
|
@transactional_session
def add_account_identity(identity, type, account, email, default=False, password=None, session=None):
'\n Adds a membership association between identity and account.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, ssh, saml).\n :param account: The account name.\n :param email: The Email address associated with the identity.\n :param default: If True, the account should be used by default with the provided identity.\n :param password: Password if type is userpass.\n :param session: The database session in use.\n '
if (not account_exists(account, session=session)):
raise exception.AccountNotFound(("Account '%s' does not exist." % account))
id = session.query(models.Identity).filter_by(identity=identity, identity_type=type).first()
if (id is None):
add_identity(identity=identity, type=type, email=email, password=password, session=session)
id = session.query(models.Identity).filter_by(identity=identity, identity_type=type).first()
iaa = models.IdentityAccountAssociation(identity=id.identity, identity_type=id.identity_type, account=account)
try:
iaa.save(session=session)
except IntegrityError:
raise exception.Duplicate(("Identity pair '%s','%s' already exists!" % (identity, type)))
| 5,409,784,752,029,731,000 |
Adds a membership association between identity and account.
:param identity: The identity key name. For example x509 DN, or a username.
:param type: The type of the authentication (x509, gss, userpass, ssh, saml).
:param account: The account name.
:param email: The Email address associated with the identity.
:param default: If True, the account should be used by default with the provided identity.
:param password: Password if type is userpass.
:param session: The database session in use.
|
lib/rucio/core/identity.py
|
add_account_identity
|
Pranay144/rucio
|
python
|
@transactional_session
def add_account_identity(identity, type, account, email, default=False, password=None, session=None):
'\n Adds a membership association between identity and account.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, ssh, saml).\n :param account: The account name.\n :param email: The Email address associated with the identity.\n :param default: If True, the account should be used by default with the provided identity.\n :param password: Password if type is userpass.\n :param session: The database session in use.\n '
if (not account_exists(account, session=session)):
raise exception.AccountNotFound(("Account '%s' does not exist." % account))
id = session.query(models.Identity).filter_by(identity=identity, identity_type=type).first()
if (id is None):
add_identity(identity=identity, type=type, email=email, password=password, session=session)
id = session.query(models.Identity).filter_by(identity=identity, identity_type=type).first()
iaa = models.IdentityAccountAssociation(identity=id.identity, identity_type=id.identity_type, account=account)
try:
iaa.save(session=session)
except IntegrityError:
raise exception.Duplicate(("Identity pair '%s','%s' already exists!" % (identity, type)))
|
@read_session
def get_default_account(identity, type, session=None):
'\n Retrieves the default account mapped to an identity.\n\n :param identity: The identity key name. For example, x509DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param session: The database session to use.\n :returns: The default account name, None otherwise.\n '
tmp = session.query(models.IdentityAccountAssociation).filter_by(identity=identity, identity_type=type, is_default=True).first()
if (tmp is None):
raise exception.IdentityError(('There is no default account for identity (%s, %s)' % (identity, type)))
return tmp.account
| -9,161,338,177,434,302,000 |
Retrieves the default account mapped to an identity.
:param identity: The identity key name. For example, x509DN, or a username.
:param type: The type of the authentication (x509, gss, userpass, saml).
:param session: The database session to use.
:returns: The default account name, None otherwise.
|
lib/rucio/core/identity.py
|
get_default_account
|
Pranay144/rucio
|
python
|
@read_session
def get_default_account(identity, type, session=None):
'\n Retrieves the default account mapped to an identity.\n\n :param identity: The identity key name. For example, x509DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param session: The database session to use.\n :returns: The default account name, None otherwise.\n '
tmp = session.query(models.IdentityAccountAssociation).filter_by(identity=identity, identity_type=type, is_default=True).first()
if (tmp is None):
raise exception.IdentityError(('There is no default account for identity (%s, %s)' % (identity, type)))
return tmp.account
|
@transactional_session
def del_account_identity(identity, type, account, session=None):
'\n Removes a membership association between identity and account.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param account: The account name.\n :param session: The database session in use.\n '
aid = session.query(models.IdentityAccountAssociation).filter_by(identity=identity, identity_type=type, account=account).first()
if (aid is None):
raise exception.IdentityError(("Identity ('%s','%s') does not exist!" % (identity, type)))
aid.delete(session=session)
| -4,375,022,618,797,144,000 |
Removes a membership association between identity and account.
:param identity: The identity key name. For example x509 DN, or a username.
:param type: The type of the authentication (x509, gss, userpass, saml).
:param account: The account name.
:param session: The database session in use.
|
lib/rucio/core/identity.py
|
del_account_identity
|
Pranay144/rucio
|
python
|
@transactional_session
def del_account_identity(identity, type, account, session=None):
'\n Removes a membership association between identity and account.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param account: The account name.\n :param session: The database session in use.\n '
aid = session.query(models.IdentityAccountAssociation).filter_by(identity=identity, identity_type=type, account=account).first()
if (aid is None):
raise exception.IdentityError(("Identity ('%s','%s') does not exist!" % (identity, type)))
aid.delete(session=session)
|
@read_session
def list_identities(session=None, **kwargs):
'\n Returns a list of all identities.\n\n :param session: The database session in use.\n\n returns: A list of all identities.\n '
id_list = []
for id in session.query(models.Identity).order_by(models.Identity.identity):
id_list.append((id.identity, id.identity_type))
return id_list
| -8,399,802,736,883,936,000 |
Returns a list of all identities.
:param session: The database session in use.
returns: A list of all identities.
|
lib/rucio/core/identity.py
|
list_identities
|
Pranay144/rucio
|
python
|
@read_session
def list_identities(session=None, **kwargs):
'\n Returns a list of all identities.\n\n :param session: The database session in use.\n\n returns: A list of all identities.\n '
id_list = []
for id in session.query(models.Identity).order_by(models.Identity.identity):
id_list.append((id.identity, id.identity_type))
return id_list
|
@read_session
def list_accounts_for_identity(identity, type, session=None):
'\n Returns a list of all accounts for an identity.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param session: The database session in use.\n\n returns: A list of all accounts for the identity.\n '
account_list = []
for (account,) in session.query(models.IdentityAccountAssociation.account).filter_by(identity=identity, identity_type=type):
account_list.append(account)
return account_list
| 7,104,951,005,997,469,000 |
Returns a list of all accounts for an identity.
:param identity: The identity key name. For example x509 DN, or a username.
:param type: The type of the authentication (x509, gss, userpass, saml).
:param session: The database session in use.
returns: A list of all accounts for the identity.
|
lib/rucio/core/identity.py
|
list_accounts_for_identity
|
Pranay144/rucio
|
python
|
@read_session
def list_accounts_for_identity(identity, type, session=None):
'\n Returns a list of all accounts for an identity.\n\n :param identity: The identity key name. For example x509 DN, or a username.\n :param type: The type of the authentication (x509, gss, userpass, saml).\n :param session: The database session in use.\n\n returns: A list of all accounts for the identity.\n '
account_list = []
for (account,) in session.query(models.IdentityAccountAssociation.account).filter_by(identity=identity, identity_type=type):
account_list.append(account)
return account_list
|
def test_plain_ansi(self):
'\n Test that printable characters do not get mangled.\n '
irc_ansi = irc.parse_ansi_to_irc(string.printable)
ansi_irc = irc.parse_irc_to_ansi(string.printable)
self.assertEqual(irc_ansi, string.printable)
self.assertEqual(ansi_irc, string.printable)
| 2,886,767,279,122,754,000 |
Test that printable characters do not get mangled.
|
evennia/server/portal/tests.py
|
test_plain_ansi
|
Antrare/evennia
|
python
|
def test_plain_ansi(self):
'\n \n '
irc_ansi = irc.parse_ansi_to_irc(string.printable)
ansi_irc = irc.parse_irc_to_ansi(string.printable)
self.assertEqual(irc_ansi, string.printable)
self.assertEqual(ansi_irc, string.printable)
|
def test_identity(self):
'\n Test that the composition of the function and\n its inverse gives the correct string.\n '
s = '|wthis|Xis|gis|Ma|C|complex|*string'
self.assertEqual(irc.parse_irc_to_ansi(irc.parse_ansi_to_irc(s)), s)
| -7,974,552,474,826,718,000 |
Test that the composition of the function and
its inverse gives the correct string.
|
evennia/server/portal/tests.py
|
test_identity
|
Antrare/evennia
|
python
|
def test_identity(self):
'\n Test that the composition of the function and\n its inverse gives the correct string.\n '
s = '|wthis|Xis|gis|Ma|C|complex|*string'
self.assertEqual(irc.parse_irc_to_ansi(irc.parse_ansi_to_irc(s)), s)
|
def test_find_start_codons():
'New test to test the function to find start codons'
assert (DNA('ATGGTACATGCGA').find_start_codons() == [0, 7])
| 5,244,507,483,773,776,000 |
New test to test the function to find start codons
|
tests/test_dna.py
|
test_find_start_codons
|
nickdelgrosso/genomics_workshop_demo
|
python
|
def test_find_start_codons():
assert (DNA('ATGGTACATGCGA').find_start_codons() == [0, 7])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.