本文整理汇总了Python中thedeployer.packages.depfile.validator.Validator.validate_string方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.validate_string方法的具体用法?Python Validator.validate_string怎么用?Python Validator.validate_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thedeployer.packages.depfile.validator.Validator
的用法示例。
在下文中一共展示了Validator.validate_string方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_db
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def create_db(self, name, character_set = "", collate = "", if_not_exists = True, retry = 1):
"""
creates new database using data base name, character_set, and collate
@param name: name of database to be created
@param character_set: character set of the database
@param collate: the collation of the database
@param if_not_exist: only creates the database if it does not exist
@param retry: The number of times to retry execution on error
@rtype: bool
@return: True on success
@raise InvalidParameterError: If method parameters are invalid in type.
@raise DbCreateError: if failed to create the database.
"""
if False == Validator.validate_non_empty_string(name):
raise InvalidParameterError('name', 'name should be a non-empty string')
if False == Validator.validate_string(character_set):
raise InvalidParameterError('character_set', 'character_set should be a string')
if False == Validator.validate_string(collate):
raise InvalidParameterError('collate', 'collate should be a string')
if False == Validator.validate_boolean(if_not_exists):
raise InvalidParameterError('if_not_exist', 'should be a boolean')
while True:
try:
statement = "CREATE DATABASE %s %s"
conn = MySQLdb.connect(host = self.__host, user = self.__username, passwd = self.__password, port = self.__port)
transaction = conn.cursor()
if True == if_not_exists:
statement = statement % ("IF NOT EXISTS", name)
else:
statement = statement % ("", name)
if 0 != len(character_set):
statement = statement + " CHARACTER SET = %s " % (character_set)
if 0 != len(collate):
statement = statement + " COLLATE = %s " % (collate)
AppLogger.debug('Executing SQL command "%s"' % (statement))
transaction.execute(statement)
return True
except Exception, e:
retry = retry - 1
if 0 == retry:
raise DbCreateError, str(e)
示例2: __init__
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def __init__(self, match_pattern):
'''
@param match_pattern: regular expretion string
'''
if not Validator.validate_string(match_pattern):
raise InvalidParameterError("match_pattern", "Must be a string value")
self.match_pattern = match_pattern
示例3: __init__
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def __init__(self, host, port, username = "", password = ""):
"""
"""
if not Validator.validate_non_empty_string(host):
raise InvalidParameterError("host", "Must be non-empty String")
if not Validator.validate_integer(port):
raise InvalidParameterError("port", "Must be an integer value")
if not Validator.validate_string(username):
raise InvalidParameterError("username", "Must be a string value")
if not Validator.validate_string(password):
raise InvalidParameterError("password", "Must be a string value")
super(SqlClient, self).__init__()
self.__host = host
self.__port = port
self.__username = username
self.__password = password
self.__platform = Platform.get_current()
示例4: __init__
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def __init__(self, repository_path, username = '', password = ''):
"""
@param repository_path: path of the root of the repository
@param username: user name to access the subversion (if it was authenticated)
@param password: password to access the subversion (if it was authenticated)
"""
if not Validator.validate_non_empty_string(repository_path):
raise InvalidParameterError("repository_path", "Must be a non-empty string")
if not Validator.validate_string(username):
raise InvalidParameterError("username", "Must be a string")
if not Validator.validate_string(password):
raise InvalidParameterError("password", "Must be a string")
VersionControlSystemClient.__init__(self, repository_path, username, password)
self.__client = pysvn.Client()
if username and password:
self.set_user(username, password)
self.local_client = LocalClient()
示例5: export
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def export(self, local_path, path = "/", revision = 0, retry = 1):
"""
export a directory from the subversion server that is spesified by path parameter
@param local_path: local path on local machine where the directory will be checked out.
@param path: path of directory on subversion servern that will be checked out.
@param replace: if true replaces the existing local working diretory.
@param revision: revision number to checkout, 0 to checkout the last revision.
@param retry: number of retries before fail.
@raise CheckOutError in case of failure
"""
if not Validator.validate_non_empty_string(local_path):
raise InvalidParameterError("local_path", "Must be non-empty string")
if not Validator.validate_string(path):
raise InvalidParameterError("path", "Must be a string value")
if not Validator.validate_integer(revision):
raise InvalidParameterError("revision", "Must be an integer value")
if not Validator.validate_integer(retry):
raise InvalidParameterError("retry", "Must be an integer value")
export_path = os.path.join(self.repository_path, path.lstrip("/"))
if os.path.exists(local_path):
raise FileExistsError, "the path where you check out is already exists"
while True:
try:
if 0 == revision:
return self.__client.export(
export_path,
local_path,
True,
)
else:
return self.__client.export(
export_path,
local_path,
True,
pysvn.Revision(pysvn.opt_revision_kind.number, revision)
)
except Exception, e:
retry -= 1
if 0 == retry:
raise CheckOutError(
'Failed to export "%s" to "%s"."' % (export_path, local_path)
)
else:
shutil.rmtree(local_path, True)
示例6: match
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def match(self, match_string):
'''
matches pattern in body of response
@param match_string: string to be matched (body of response)
'''
if not Validator.validate_string(match_string):
raise InvalidParameterError("match_string", "Must be a string value")
matchs = re.findall(self.match_pattern, match_string)
if not matchs:
raise MatchDataError
data = matchs[0]
data_key = (re.findall('name[ ]*=[ ]*".*"',data))[0]
data_value = (re.findall('value[ ]*=[ ]*".*"',data))[0]
if not (data_key and data_value):
raise MatchDataError
return (data_key.split('"'))[1], (data_value.split('"'))[1]
示例7: __init__
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def __init__(self, platform, root):
"""
This is an abstract class and cannot be instantiated directly.
@param __platform: the server's platform
"""
if self.__class__ == FileClient:
raise NotSupportedError()
if Platform != platform.__class__:
raise InvalidParameterError('platform', 'Must be instance of Platform')
# prepare the root
if False == Validator.validate_string(root):
raise InvalidParameterError('root', 'root should be a string')
if len(root) != 0 and (platform.get_platform() == Platform.PLATFORM_POSIX):
if root[0] != '/':
raise InvalidParameterError('root', "root should start with '/'")
elif len(root) != 0 and platform.get_platform() == Platform.PLATFORM_WINDOWS:
if not re.match(r'[a-zA-Z]:\\', root[0:3]):
raise InvalidParameterError('root', "root should start format like 'C:\\'")
#if len(root) != 0 and (platform.get_platform() == Platform.PLATFORM_POSIX) and root[-1] != '/':
#root += '/'
#elif len(root) != 0 and platform.get_platform() == Platform.PLATFORM_WINDOWS and root[-1] != '\\':
#root += '\\'
if len(root) == 0:
root = platform.get_root()
else:
root = root.rstrip(platform.get_separator()) + platform.get_separator()
self.__platform = platform
self.__root = root
示例8: get_file_list
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_string [as 别名]
def get_file_list(self, path, recursive = False, retry = 1):
"""
list file on subversion server given a spesified path
raise ListFileError on failure
"""
if not Validator.validate_string(path):
raise InvalidParameterError("local_path", "Must be a string value")
if not Validator.validate_boolean(recursive):
raise InvalidParameterError("recursive", "Must be a boolean value")
if not Validator.validate_integer(retry):
raise InvalidParameterError("retry", "Must be an integer value")
path = self.local_client.get_platform().trim_path(path)
while retry:
retry -= 1
try:
return self.__client.ls(self.repository_path + path, recurse = recursive)
except Exception, e:
if retry == 0:
raise ListFileError("Repository path: " + self.repository_path + path, str(e))
else:
break