本文整理汇总了Python中lib.drupy.DrupyPHP.is_object方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.is_object方法的具体用法?Python DrupyPHP.is_object怎么用?Python DrupyPHP.is_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.is_object方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import is_object [as 别名]
def copy(source, dest = 0, replace = FILE_EXISTS_RENAME):
"""
Copies a file to a new location.
This is a powerful function that in many ways
performs like an advanced version of copy().
- Checks if source and dest are valid and readable/writable.
- Performs a file copy if source is not equal to dest.
- If file already exists in dest either the call will
error out, replace the
file or rename the file based on the replace parameter.
@param source A string specifying the file location of the original file.
This parameter will contain the resulting destination filename in case of
success.
@param dest A string containing the directory source should be copied to.
If this value is omitted, Drupal's 'files' directory will be used.
@param replace Replace behavior when the destination file already exists.
- FILE_EXISTS_REPLACE - Replace the existing file
- FILE_EXISTS_RENAME - Append _{incrementing number} until
the filename is unique
- FILE_EXISTS_ERROR - Do nothing and return False.
@return True for success, False for failure.
"""
php.Reference.check(source)
dest = file_create_path(dest)
directory = dest
basename = file_check_path(directory)
# Make sure we at least have a valid directory.
if (basename == False):
if hasattr(source, 'filepath'):
source._ = source.filepath
drupal_set_message(t('The selected file %file could not be ' + \
'uploaded, because the destination %directory is not ' + \
'properly configured.', \
{'%file' : source._, '%directory' : dest}), 'error')
watchdog('file system', 'The selected file %file could not ' + \
'be uploaded, because the destination %directory could ' + \
'not be found, or because its permissions do ' + \
'not allow the file to be written.', \
{'%file' : source._, '%directory' : dest}, WATCHDOG_ERROR)
return False
# Process a file upload object.
if (php.is_object(source._)):
file = source._
source._ = file.filepath
if (not basename):
basename = file.filename
source._ = php.realpath(source._)
if (not php.file_exists(source._)):
drupal_set_message(t('The selected file %file could not be copied, ' + \
'because no file by that name exists. ' + \
'Please check that you supplied the correct filename.', \
{'%file' : source._}), 'error')
return False
# If the destination file is not specified then use the filename
# of the source file.
basename = (basename if basename else basename(source._))
dest._ = directory + '/' + basename
# Make sure source and destination filenames are not the same, makes no sense
# to copy it if they are + In fact copying the file will most
# likely result in
# a 0 byte file + Which is bad. Real bad.
if (source._ != php.realpath(dest._)):
dest._ = file_destination(dest._, replace)
if (not dest._):
drupal_set_message(t('The selected file %file could not be copied, ' + \
'because a file by that name already exists in the destination.', \
{'%file' : source._}), 'error')
return False
if (not copy(source._, dest._)):
drupal_set_message(t('The selected file %file could not be copied.', \
{'%file' : source._}), 'error')
return False
# Give everyone read access so that FTP'd users or
# non-webserver users can see/read these files,
# and give group write permissions so group members
# can alter files uploaded by the webserver.
chmod(dest._, 0664)
if (php.isset(file) and php.is_object(file)):
file.filename = basename
file.filepath = dest._
source._ = file
else:
source._ = dest
return True # Everything went ok.