本文整理汇总了Python中thedeployer.packages.depfile.validator.Validator.validate方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.validate方法的具体用法?Python Validator.validate怎么用?Python Validator.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thedeployer.packages.depfile.validator.Validator
的用法示例。
在下文中一共展示了Validator.validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate [as 别名]
def __init__(self, id, address, port, document_root, language):
"""
Constructor for the class.
@param id: The identifier of this server, must be a non-empty string.
@param address: The web address (excluding the protocol, for the web server.
@param port: The port of the server.
@param document_root: The document root of the server.
@param language: A language this server supports, like PHP5.
"""
if not Validator.validate(address, 'domain'):
raise InvalidParameterError('address', 'Must be a valid domain name, excluding the protocol or path.')
if not Validator.validate(port, 'port'):
raise InvalidParameterError('port', 'Must be an integer value between 0 and 65535')
if not Validator.validate(document_root, 'non_empty_string'):
raise InvalidParameterError('document_root', 'Must be a non-empty string')
if not Validator.validate(language, 'non_empty_string'):
raise InvalidParameterError('language', 'Must be a non-empty string')
self.__address = address
self.__port = port
self.__document_root = document_root
self.__language = language
Server.__init__(self, id, Server.REMOTE)
WebClient.__init__(self)
示例2: is_exists
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate [as 别名]
def is_exists(self, path):
"""
Checks whether a file or directory exists at the specified path.
@param path: The path to check.
@rtype: Boolean
@return: True on success, False on failure.
"""
if not Validator.validate(path, 'non_empty_string'):
raise InvalidParameterError('path', 'should be a non-empty string')
return os.path.exists(path)
示例3: get_temp_name
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate [as 别名]
def get_temp_name(self, parent, prefix = ""):
"""
Returns the path to a non-existing temporary file name in the directory parent. The file can be
optionally prefixed with "prefix".
@param parent: The parent directory to store the file at.
@param prefix: A prefix to add to the file name.
@rtype: string
@return: The path of the file.
@raise TemporaryFileError: If it cannot return such path.
"""
if not Validator.validate(parent, 'non_empty_string'):
raise InvalidParameterError('parent', 'should be a non-empty string')
if not Validator.validate(prefix, 'string'):
raise InvalidParameterError('prefix', 'should be a string value')
try:
return self.get_platform().basename(os.tempnam(parent, prefix))
except Exception, e:
raise TemporaryFileError, str(e)
示例4: download
# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate [as 别名]
def download(cls, url, destination, replace = False, retry = 1):
"""
downloads a file from the web
@param url: the url of the file to be downloaded
@param destination: the destination where the file will be downloaded to
@param replace: if set True then the downloaded file will replae any existinf file
@param retry: number of retries
@rtype: bool
@return: True on success
@raise FileDownloadError: if error during downloading
"""
if not Validator.validate(url, "url"):
raise InvalidParameterError("url", "should be a non-empty string starts with 'http://'")
if not Validator.validate(destination, "non_empty_string"):
raise InvalidParameterError('destination', 'should be non-empty string')
if not Validator.validate(replace, 'boolean'):
raise InvalidParameterError('replace', 'should be a boolean value')
if not Validator.validate(retry, 'integer'):
raise InvalidParameterError('getting', 'should be an integer value')
separator = Platform.get_current().get_separator()
if not (re.match(r'/', destination) or re.match(r'[a-zA-Z]:\\', destination)):
destination = destination.rstrip(separator)
while retry:
retry -= 1
try:
result = urllib2.urlopen(url, "")
if os.path.exists(destination):
if os.path.isdir(destination):
if result.headers.has_key('content-disposition'):
tmp = result.headers.dict['content-disposition']
index = tmp.find('filename=')
if index == -1:
name = 'attachment'
else:
name = tmp[index+9: ]
name = name.split(' ')[0]
else:
name = result.geturl()
name = name.split('?')[0]
name = name.rstrip('/')
index = name.rfind('/')
name = name[index+1:]
destination = destination + separator + name
else:
if os.path.isfile(destination):
if replace:
os.remove(destination)
else:
raise FileExistsError, 'the destination file already exists'
else:
raise FileExistsError, 'destination is non-file, system cannot replace a non file'
file = open(destination, "wb")
buffer = result.read(4096)
while len(buffer) != 0:
file.write(buffer)
buffer = result.read(4096)
file.close()
except Exception, e:
if retry == 0:
raise FileDownloadError, str(e)
else:
break