prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
<|fim_middle|>
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | if input_value:
return 'TRUE'
else:
return 'FALSE' |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
<|fim_middle|>
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return 'TRUE' |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
<|fim_middle|>
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return 'FALSE' |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
<|fim_middle|>
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE' |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
<|fim_middle|>
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return 'TRUE' |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
<|fim_middle|>
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return 'FALSE' |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
<|fim_middle|>
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | sequence = False
input_value = [input_value] |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
<|fim_middle|>
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | sequence = True # indicates if a sequence must be returned |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
<|fim_middle|>
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
<|fim_middle|>
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | valid_values.append(element) |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
<|fim_middle|>
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return False |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
<|fim_middle|>
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ')) |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
<|fim_middle|>
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | valid_values.append(element.strftime('%Y%m%d%H%M%S%z')) |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
<|fim_middle|>
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ')) |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
<|fim_middle|>
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return False |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
<|fim_middle|>
else:
return True
<|fim▁end|> | if sequence:
return valid_values
else:
return valid_values[0] |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
<|fim_middle|>
else:
return valid_values[0]
else:
return True
<|fim▁end|> | return valid_values |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
<|fim_middle|>
else:
return True
<|fim▁end|> | return valid_values[0] |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
<|fim_middle|>
<|fim▁end|> | return True |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def <|fim_middle|>(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | check_type |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def <|fim_middle|>(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | always_valid |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def <|fim_middle|>(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | validate_generic_single_value |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def <|fim_middle|>(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | validate_integer |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def <|fim_middle|>(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | validate_bytes |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def <|fim_middle|>(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def validate_time(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | validate_boolean |
<|file_name|>validators.py<|end_file_name|><|fim▁begin|>"""
"""
# Created on 2016.08.09
#
# Author: Giovanni Cannata
#
# Copyright 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 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 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from ... import SEQUENCE_TYPES, STRING_TYPES
from .formatters import format_time
from ...utils.conv import to_raw
# Validators return True if value is valid, False if value is not valid,
# or a value different from True and False that is a valid value to substitute to the input value
def check_type(input_value, value_type):
if isinstance(input_value, value_type):
return True
if isinstance(input_value, SEQUENCE_TYPES):
for value in input_value:
if not isinstance(value, value_type):
return False
return True
return False
def always_valid(input_value):
return True
def validate_generic_single_value(input_value):
if not isinstance(input_value, SEQUENCE_TYPES):
return True
try: # object couldn't have a __len__ method
if len(input_value) == 1:
return True
except Exception:
pass
return False
def validate_integer(input_value):
if check_type(input_value, (float, bool)):
return False
if str is bytes: # Python 2, check for long too
if check_type(input_value, (int, long)):
return True
else: # Python 3, int only
if check_type(input_value, int):
return True
sequence = True # indicates if a sequence must be returned
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = [] # builds a list of valid int values
for element in input_value:
try: # try to convert any type to int, an invalid conversion raise TypeError of ValueError, if both are valid and equal then then int() value is used
float_value = float(element)
int_value = int(element)
if float_value == int_value:
valid_values.append(int(element))
else:
return False
except (ValueError, TypeError):
return False
if sequence:
return valid_values
else:
return valid_values[0]
def validate_bytes(input_value):
return check_type(input_value, bytes)
def validate_boolean(input_value):
# it could be a real bool or the string TRUE or FALSE, # only a single valued is allowed
if validate_generic_single_value(input_value): # valid only if a single value or a sequence with a single element
if isinstance(input_value, SEQUENCE_TYPES):
input_value = input_value[0]
if isinstance(input_value, bool):
if input_value:
return 'TRUE'
else:
return 'FALSE'
if isinstance(input_value, STRING_TYPES):
if input_value.lower() == 'true':
return 'TRUE'
elif input_value.lower() == 'false':
return 'FALSE'
return False
def <|fim_middle|>(input_value):
# if datetime object doesn't have a timezone it's considered local time and is adjusted to UTC
if not isinstance(input_value, SEQUENCE_TYPES):
sequence = False
input_value = [input_value]
else:
sequence = True # indicates if a sequence must be returned
valid_values = []
changed = False
for element in input_value:
if isinstance(element, STRING_TYPES): # tries to check if it is already be a Generalized Time
if isinstance(format_time(to_raw(element)), datetime): # valid Generalized Time string
valid_values.append(element)
else:
return False
elif isinstance(element, datetime):
changed = True
if element.tzinfo: # a datetime with a timezone
valid_values.append(element.strftime('%Y%m%d%H%M%S%z'))
else: # datetime without timezone, assumed local and adjusted to UTC
offset = datetime.now() - datetime.utcnow()
valid_values.append((element - offset).strftime('%Y%m%d%H%M%SZ'))
else:
return False
if changed:
if sequence:
return valid_values
else:
return valid_values[0]
else:
return True
<|fim▁end|> | validate_time |
<|file_name|>0002_phonenumber_related_sim.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-11-01 20:02
from __future__ import unicode_literals
<|fim▁hole|>
class Migration(migrations.Migration):
initial = True
dependencies = [
('phone_numbers', '0001_initial'),
('sims', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='phonenumber',
name='related_sim',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='phone_numbers', to='sims.Sim'),
),
]<|fim▁end|> | from django.db import migrations, models
import django.db.models.deletion
|
<|file_name|>0002_phonenumber_related_sim.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-11-01 20:02
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
<|fim_middle|>
<|fim▁end|> | initial = True
dependencies = [
('phone_numbers', '0001_initial'),
('sims', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='phonenumber',
name='related_sim',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='phone_numbers', to='sims.Sim'),
),
] |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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<|fim▁hole|># limitations under the License.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()<|fim▁end|> | # 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 |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start() |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
<|fim_middle|>
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | print(WeavePing.WeavePing.__doc__)
sys.exit(0) |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
<|fim_middle|>
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["quiet"] = True |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
<|fim_middle|>
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["tcp"] = True |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
<|fim_middle|>
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["udp"] = True |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
<|fim_middle|>
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["wrmp"] = True |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
<|fim_middle|>
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["client"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
<|fim_middle|>
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["server"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
<|fim_middle|>
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["count"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
<|fim_middle|>
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["interval"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
<|fim_middle|>
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["tap"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
<|fim_middle|>
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["case"] = True |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
<|fim_middle|>
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["case_cert_path"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
<|fim_middle|>
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["case_key_path"] = a |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
<|fim_middle|>
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | assert False, "unhandled option" |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
<|fim_middle|>
if len(args) == 2:
options["client"] = args[0]
options["server"] = args[1]
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["origin"] = args[0] |
<|file_name|>weave-ping.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Nest Labs, Inc.
# All rights reserved.
#
# 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.
#
#
# @file
# A Happy command line utility that tests Weave Ping among Weave nodes.
#
# The command is executed by instantiating and running WeavePing class.
#
from __future__ import absolute_import
from __future__ import print_function
import getopt
import sys
import set_test_path
from happy.Utils import *
import WeavePing
if __name__ == "__main__":
options = WeavePing.option()
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:s:c:tuwqp:i:a:e:n:CE:T:",
["help", "origin=", "server=", "count=", "tcp", "udp", "wrmp", "interval=", "quiet",
"tap=", "case", "case_cert_path=", "case_key_path="])
except getopt.GetoptError as err:
print(WeavePing.WeavePing.__doc__)
print(hred(str(err)))
sys.exit(hred("%s: Failed server parse arguments." % (__file__)))
for o, a in opts:
if o in ("-h", "--help"):
print(WeavePing.WeavePing.__doc__)
sys.exit(0)
elif o in ("-q", "--quiet"):
options["quiet"] = True
elif o in ("-t", "--tcp"):
options["tcp"] = True
elif o in ("-u", "--udp"):
options["udp"] = True
elif o in ("-w", "--wrmp"):
options["wrmp"] = True
elif o in ("-o", "--origin"):
options["client"] = a
elif o in ("-s", "--server"):
options["server"] = a
elif o in ("-c", "--count"):
options["count"] = a
elif o in ("-i", "--interval"):
options["interval"] = a
elif o in ("-p", "--tap"):
options["tap"] = a
elif o in ("-C", "--case"):
options["case"] = True
elif o in ("-E", "--case_cert_path"):
options["case_cert_path"] = a
elif o in ("-T", "--case_key_path"):
options["case_key_path"] = a
else:
assert False, "unhandled option"
if len(args) == 1:
options["origin"] = args[0]
if len(args) == 2:
<|fim_middle|>
cmd = WeavePing.WeavePing(options)
cmd.start()
<|fim▁end|> | options["client"] = args[0]
options["server"] = args[1] |
<|file_name|>carenet.py<|end_file_name|><|fim▁begin|>from django.conf.urls.defaults import *
from indivo.views import *
from indivo.lib.utils import MethodDispatcher
urlpatterns = patterns('',
(r'^$', MethodDispatcher({
'DELETE' : carenet_delete})),
(r'^/rename$', MethodDispatcher({
'POST' : carenet_rename})),
(r'^/record$', MethodDispatcher({'GET':carenet_record})),
# Manage documents
(r'^/documents/', include('indivo.urls.carenet_documents')),
# Manage accounts
(r'^/accounts/$',
MethodDispatcher({
'GET' : carenet_account_list,
'POST' : carenet_account_create
})),
(r'^/accounts/(?P<account_id>[^/]+)$',
MethodDispatcher({ 'DELETE' : carenet_account_delete })),
# Manage apps
(r'^/apps/$',
MethodDispatcher({ 'GET' : carenet_apps_list})),
(r'^/apps/(?P<pha_email>[^/]+)$',
MethodDispatcher({ 'PUT' : carenet_apps_create,
'DELETE': carenet_apps_delete})),
# Permissions Calls
(r'^/accounts/(?P<account_id>[^/]+)/permissions$',
MethodDispatcher({ 'GET' : carenet_account_permissions })),
(r'^/apps/(?P<pha_email>[^/]+)/permissions$', <|fim▁hole|> MethodDispatcher({'GET':carenet_procedure_list})),
(r'^/reports/minimal/simple-clinical-notes/$',
MethodDispatcher({'GET':carenet_simple_clinical_notes_list})),
(r'^/reports/minimal/equipment/$',
MethodDispatcher({'GET':carenet_equipment_list})),
(r'^/reports/minimal/measurements/(?P<lab_code>[^/]+)/$',
MethodDispatcher({'GET':carenet_measurement_list})),
(r'^/reports/(?P<data_model>[^/]+)/$',
MethodDispatcher({'GET':carenet_generic_list})),
# Demographics
(r'^/demographics$', MethodDispatcher({'GET': read_demographics_carenet})),
)<|fim▁end|> | MethodDispatcher({ 'GET' : carenet_app_permissions })),
# Reporting Calls
(r'^/reports/minimal/procedures/$', |
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|>from .image import Image
from .product_category import ProductCategory
from .supplier import Supplier, PaymentMethod
from .product import Product
from .product import ProductImage
from .enum_values import EnumValues
from .related_values import RelatedValues
from .customer import Customer
from .expense import Expense
from .incoming import Incoming
from .shipping import Shipping, ShippingLine
from .receiving import Receiving, ReceivingLine
from .inventory_transaction import InventoryTransaction, InventoryTransactionLine<|fim▁hole|>from .sales_order import SalesOrder, SalesOrderLine
from .user import User
from .role import Role, roles_users
from .organization import Organization
from .inventory_in_out_link import InventoryInOutLink
from .aspects import update_menemonic
from .product_inventory import ProductInventory<|fim▁end|> | from .purchase_order import PurchaseOrder, PurchaseOrderLine |
<|file_name|>test_with_shap.py<|end_file_name|><|fim▁begin|>import numpy as np
import xgboost as xgb
import pytest<|fim▁hole|>
try:
import shap
except ImportError:
shap = None
pass
pytestmark = pytest.mark.skipif(shap is None, reason="Requires shap package")
# Check integration is not broken from xgboost side
# Changes in binary format may cause problems
def test_with_shap():
from sklearn.datasets import fetch_california_housing
X, y = fetch_california_housing(return_X_y=True)
dtrain = xgb.DMatrix(X, label=y)
model = xgb.train({"learning_rate": 0.01}, dtrain, 10)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)
margin = model.predict(dtrain, output_margin=True)
assert np.allclose(np.sum(shap_values, axis=len(shap_values.shape) - 1),
margin - explainer.expected_value, 1e-3, 1e-3)<|fim▁end|> | |
<|file_name|>test_with_shap.py<|end_file_name|><|fim▁begin|>import numpy as np
import xgboost as xgb
import pytest
try:
import shap
except ImportError:
shap = None
pass
pytestmark = pytest.mark.skipif(shap is None, reason="Requires shap package")
# Check integration is not broken from xgboost side
# Changes in binary format may cause problems
def test_with_shap():
<|fim_middle|>
<|fim▁end|> | from sklearn.datasets import fetch_california_housing
X, y = fetch_california_housing(return_X_y=True)
dtrain = xgb.DMatrix(X, label=y)
model = xgb.train({"learning_rate": 0.01}, dtrain, 10)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)
margin = model.predict(dtrain, output_margin=True)
assert np.allclose(np.sum(shap_values, axis=len(shap_values.shape) - 1),
margin - explainer.expected_value, 1e-3, 1e-3) |
<|file_name|>test_with_shap.py<|end_file_name|><|fim▁begin|>import numpy as np
import xgboost as xgb
import pytest
try:
import shap
except ImportError:
shap = None
pass
pytestmark = pytest.mark.skipif(shap is None, reason="Requires shap package")
# Check integration is not broken from xgboost side
# Changes in binary format may cause problems
def <|fim_middle|>():
from sklearn.datasets import fetch_california_housing
X, y = fetch_california_housing(return_X_y=True)
dtrain = xgb.DMatrix(X, label=y)
model = xgb.train({"learning_rate": 0.01}, dtrain, 10)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)
margin = model.predict(dtrain, output_margin=True)
assert np.allclose(np.sum(shap_values, axis=len(shap_values.shape) - 1),
margin - explainer.expected_value, 1e-3, 1e-3)
<|fim▁end|> | test_with_shap |
<|file_name|>notification.py<|end_file_name|><|fim▁begin|>import requests
import logging
import redis
from requests.packages.urllib3.exceptions import ConnectionError
from core.serialisers import json
from dss import localsettings
# TODO([email protected]): refactor these out to
# classes to avoid duplicating constants below
HEADERS = {
'content-type': 'application/json'
}
logger = logging.getLogger('spa')
def post_notification(session_id, image, message):
try:
payload = {
'sessionid': session_id,
'image': image,
'message': message
}
data = json.dumps(payload)
r = requests.post(
localsettings.REALTIME_HOST + 'notification',
data=data,<|fim▁hole|> )
if r.status_code == 200:
return ""
else:
return r.text
except ConnectionError:
#should probably implement some sort of retry in here
pass<|fim▁end|> | headers=HEADERS |
<|file_name|>notification.py<|end_file_name|><|fim▁begin|>import requests
import logging
import redis
from requests.packages.urllib3.exceptions import ConnectionError
from core.serialisers import json
from dss import localsettings
# TODO([email protected]): refactor these out to
# classes to avoid duplicating constants below
HEADERS = {
'content-type': 'application/json'
}
logger = logging.getLogger('spa')
def post_notification(session_id, image, message):
<|fim_middle|>
<|fim▁end|> | try:
payload = {
'sessionid': session_id,
'image': image,
'message': message
}
data = json.dumps(payload)
r = requests.post(
localsettings.REALTIME_HOST + 'notification',
data=data,
headers=HEADERS
)
if r.status_code == 200:
return ""
else:
return r.text
except ConnectionError:
#should probably implement some sort of retry in here
pass |
<|file_name|>notification.py<|end_file_name|><|fim▁begin|>import requests
import logging
import redis
from requests.packages.urllib3.exceptions import ConnectionError
from core.serialisers import json
from dss import localsettings
# TODO([email protected]): refactor these out to
# classes to avoid duplicating constants below
HEADERS = {
'content-type': 'application/json'
}
logger = logging.getLogger('spa')
def post_notification(session_id, image, message):
try:
payload = {
'sessionid': session_id,
'image': image,
'message': message
}
data = json.dumps(payload)
r = requests.post(
localsettings.REALTIME_HOST + 'notification',
data=data,
headers=HEADERS
)
if r.status_code == 200:
<|fim_middle|>
else:
return r.text
except ConnectionError:
#should probably implement some sort of retry in here
pass<|fim▁end|> | return "" |
<|file_name|>notification.py<|end_file_name|><|fim▁begin|>import requests
import logging
import redis
from requests.packages.urllib3.exceptions import ConnectionError
from core.serialisers import json
from dss import localsettings
# TODO([email protected]): refactor these out to
# classes to avoid duplicating constants below
HEADERS = {
'content-type': 'application/json'
}
logger = logging.getLogger('spa')
def post_notification(session_id, image, message):
try:
payload = {
'sessionid': session_id,
'image': image,
'message': message
}
data = json.dumps(payload)
r = requests.post(
localsettings.REALTIME_HOST + 'notification',
data=data,
headers=HEADERS
)
if r.status_code == 200:
return ""
else:
<|fim_middle|>
except ConnectionError:
#should probably implement some sort of retry in here
pass<|fim▁end|> | return r.text |
<|file_name|>notification.py<|end_file_name|><|fim▁begin|>import requests
import logging
import redis
from requests.packages.urllib3.exceptions import ConnectionError
from core.serialisers import json
from dss import localsettings
# TODO([email protected]): refactor these out to
# classes to avoid duplicating constants below
HEADERS = {
'content-type': 'application/json'
}
logger = logging.getLogger('spa')
def <|fim_middle|>(session_id, image, message):
try:
payload = {
'sessionid': session_id,
'image': image,
'message': message
}
data = json.dumps(payload)
r = requests.post(
localsettings.REALTIME_HOST + 'notification',
data=data,
headers=HEADERS
)
if r.status_code == 200:
return ""
else:
return r.text
except ConnectionError:
#should probably implement some sort of retry in here
pass<|fim▁end|> | post_notification |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|><|fim▁hole|>extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki<|fim▁end|> | """ |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
<|fim_middle|>
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | """
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
<|fim_middle|>
<|fim▁end|> | """
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
<|fim_middle|>
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | """
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers) |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
<|fim_middle|>
<|fim▁end|> | beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
<|fim_middle|>
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | base += '_external' |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
<|fim_middle|>
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | base += '_beta' |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
<|fim_middle|>
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers' |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
<|fim_middle|>
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | tiddlers.link = '/tiddlers' |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
<|fim_middle|>
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | beta = True |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
<|fim_middle|>
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | external = True |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
<|fim_middle|>
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | external = False |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
<|fim_middle|>
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file) |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
<|fim_middle|>
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file) |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
<|fim_middle|>
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | wiki = WikiSerialization._get_wiki(self) |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
<|fim_middle|>
return wiki
<|fim▁end|> | wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag) |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def <|fim_middle|>(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | build_config_var |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def <|fim_middle|>(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def _get_wiki(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | list_tiddlers |
<|file_name|>betaserialization.py<|end_file_name|><|fim▁begin|>"""
extend TiddlyWiki serialization to optionally use beta or
externalized releases and add the UniversalBackstage.
activated via "twrelease=beta" URL parameter or ServerSettings,
see build_config_var
"""
import logging
from tiddlyweb.util import read_utf8_file
from tiddlywebwiki.serialization import Serialization as WikiSerialization
from tiddlywebplugins.tiddlyspace.web import (determine_host,
determine_space, determine_space_recipe)
LOGGER = logging.getLogger(__name__)
def build_config_var(beta=False, external=False):
"""
Create the configuration key which will be used to locate
the base tiddlywiki file.
"""
base = 'base_tiddlywiki'
if external:
base += '_external'
if beta:
base += '_beta'
return base
class Serialization(WikiSerialization):
"""
Subclass of the standard TiddlyWiki serialization to allow
choosing beta or externalized versions of the base empty.html
in which the tiddlers will be servered.
Also, if the TiddlyWiki is not being downloaded, add
the UniversalBackstage by injecting a script tag.
"""
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
if space_name:
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
def <|fim_middle|>(self):
beta = external = False
release = self.environ.get('tiddlyweb.query', {}).get(
'twrelease', [False])[0]
externalize = self.environ.get('tiddlyweb.query', {}).get(
'external', [False])[0]
download = self.environ.get('tiddlyweb.query', {}).get(
'download', [False])[0]
if release == 'beta':
beta = True
if externalize:
external = True
# If somebody is downloading, don't allow them to
# externalize.
if download:
external = False
wiki = None
if beta or external:
config_var = build_config_var(beta, external)
LOGGER.debug('looking for %s', config_var)
base_wiki_file = self.environ.get('tiddlyweb.config',
{}).get(config_var, '')
if base_wiki_file:
LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
wiki = read_utf8_file(base_wiki_file)
if not wiki:
wiki = WikiSerialization._get_wiki(self)
tag = "<!--POST-SCRIPT-START-->"
if not download:
wiki = wiki.replace(tag, '<script type="text/javascript" '
'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
return wiki
<|fim▁end|> | _get_wiki |
<|file_name|>Parameter.py<|end_file_name|><|fim▁begin|>param = dict(
useAIon=True,
verbose=False,
chargePreXlinkIons=[1, 3],
chargePostXlinkIons=[2, 5],
basepeakint = 100.0,
dynamicrange = 0.001,
missedsites = 2,
minlength = 4,
maxlength = 51,
modRes = '',
modMass = 0.0,
linkermass = 136.10005,
ms1tol = dict(measure='ppm', val=5),
ms2tol = dict(measure='da', val=0.01),
minmz = 200,
maxmz = 2000,
mode = 'conservative',
patternstring = '^[ACDEFGHIKLMNPQRSTVWY]*K[ACDEFGHIKLMNPQRSTVWY]+$',
fixedMod = [],
neutralloss=dict(
h2oLoss=dict(
mass=-18.010565,
aa=set('ACDEFGHIKLMNPQRSTVWY')),
nh3Loss=dict(
mass=-17.026549,
aa=set('ACDEFGHIKLMNPQRSTVWY')),
h2oGain=dict(
mass=18.010565,
aa=set('ACDEFGHIKLMNPQRSTVWY'))))
mass = dict(
A=71.037114,
R=156.101111,
N=114.042927,
D=115.026943,<|fim▁hole|> E=129.042593,
Q=128.058578,
G=57.021464,
H=137.058912,
I=113.084064,
L=113.084064,
K=128.094963,
M=131.040485,
F=147.068414,
P=97.052764,
S=87.032028,
T=101.047678,
W=186.079313,
Y=163.063329,
V=99.068414,
Hatom=1.007825032,
Oatom=15.99491462,
neutronmass = 1.008701,
BIonRes=1.0078246,
AIonRes=-26.9870904,
YIonRes=19.0183888,
isotopeInc = [1.008701/4, 1.008701/3, 1.008701/2, 1.008701/1])
modification = dict(
position=[],
deltaMass=[])
for i in range(len(param['fixedMod'])):
aa = param['fixedMod'][i][0]
delta = param['fixedMod'][i][1]
mass[aa] += delta<|fim▁end|> | C=103.009184, |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)<|fim▁hole|>
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()<|fim▁end|> | else: self.fail("time out")
driver.find_element_by_link_text("Download data").click() |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
<|fim_middle|>
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
<|fim_middle|>
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
<|fim_middle|>
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click() |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
<|fim_middle|>
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
<|fim_middle|>
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
<|fim_middle|>
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
<|fim_middle|>
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.driver.quit()
self.assertEqual([], self.verificationErrors) |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): <|fim_middle|>
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | break |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: <|fim_middle|>
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.fail("time out") |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): <|fim_middle|>
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | break |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: <|fim_middle|>
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.fail("time out") |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): <|fim_middle|>
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | break |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: <|fim_middle|>
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.fail("time out") |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): <|fim_middle|>
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | break |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: <|fim_middle|>
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.fail("time out") |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): <|fim_middle|>
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | break |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: <|fim_middle|>
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | self.fail("time out") |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
<|fim_middle|>
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | alert.accept() |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
<|fim_middle|>
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | alert.dismiss() |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | unittest.main() |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def <|fim_middle|>(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | setUp |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def <|fim_middle|>(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | test_download_entered_data |
<|file_name|>download_entered_data_test.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class DownloadEnteredDataTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://kc.kbtdev.org/"
self.verificationErrors = []
self.accept_next_alert = True
def test_download_entered_data(self):
# Open KoBoCAT.
driver = self.driver
driver.get(self.base_url + "")
# Assert that our form's title is in the list of projects and follow its link.
self.assertTrue(self.is_element_present(By.LINK_TEXT, "Selenium test form title."))
driver.find_element_by_link_text("Selenium test form title.").click()
# Wait for and click the "Download data" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "Download data" link.')
try:
if self.is_element_present(By.LINK_TEXT, "Download data"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("Download data").click()
# Wait for and click the "XLS" link.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for "XLS" link.')
try:
if self.is_element_present(By.LINK_TEXT, "XLS"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_link_text("XLS").click()
# Wait for the download page's header and ensure it contains the word "excel" (case insensitive).
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for download page\'s header.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".data-page__header"): break
except: pass
time.sleep(1)
else: self.fail("time out")
self.assertIsNotNone(re.compile('excel', re.IGNORECASE).search(driver.find_element_by_css_selector(".data-page__header").text))
# Wait for the export progress status.
for _ in xrange(self.DEFAULT_WAIT_SECONDS):
self.check_timeout('Waiting for the export progress status.')
try:
if self.is_element_present(By.CSS_SELECTOR, ".refresh-export-progress"): break
except: pass
time.sleep(1)
else: self.fail("time out")
# Wait (a little more than usual) for the export's download link and click it.
for _ in xrange(30):
self.check_timeout('Waiting for the export\'s download link.')
try:
if re.search(r"^Selenium_test_form_title_[\s\S]*$", driver.find_element_by_css_selector("#forms-table a").text): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("#forms-table a").click()
def <|fim_middle|>(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
<|fim▁end|> | is_element_present |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.