本文整理汇总了Python中lib.drupy.DrupyPHP.stdClass方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.stdClass方法的具体用法?Python DrupyPHP.stdClass怎么用?Python DrupyPHP.stdClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.stdClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scan_directory
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import stdClass [as 别名]
def scan_directory(dir, mask, nomask = ['.', '..', 'CVS'], \
callback = 0, recurse = True, key = 'filename', min_depth = 0, depth = 0):
"""
Finds all files that match a given mask in a given directory.
Directories and files beginning with a period are excluded; this
prevents hidden files and directories (such as SVN working directories)
from being scanned.
@param dir
The base directory for the scan, without trailing slash.
@param mask
The regular expression of the files to find.
@param nomask
An array of files/directories to ignore.
@param callback
The callback function to call for each match.
@param recurse
When True, the directory scan will recurse the entire tree
starting at the provided directory.
@param key
The key to be used for the returned array of files + Possible
values are "filename", for the path starting with dir,
"basename", for the basename of the file, and "name" for the name
of the file without an extension.
@param min_depth
Minimum depth of directories to return files from.
@param depth
Current depth of recursion + This parameter is only used
internally and should not be passed.
@return
An associative array (keyed on the provided key) of objects with
"path", "basename", and "name" members corresponding to the
matching files.
"""
key = (key if php.in_array(key, \
('filename', 'basename', 'name')) else 'filename')
files = []
if php.is_dir(dir):
dir_files = php.scandir(dir)
for file in dir_files:
if (not php.in_array(file, nomask) and file[0] != '.'):
if (php.is_dir("%s/%s" % (dir, file)) and recurse):
# Give priority to files in this folder by
# merging them in after any subdirectory files.
files = php.array_merge(file_scan_directory("%s/%s" % (dir, file), \
mask, nomask, callback, recurse, key, min_depth, depth + 1), files)
elif (depth >= min_depth and ereg(mask, file)):
# Always use this match over anything already
# set in files with the same $key.
filename = "%s/%s" % (dir, file)
basename_ = php.basename(file)
name = php.substr(basename_, 0, php.strrpos(basename_, '.'))
files[key] = php.stdClass()
files[key].filename = filename
files[key].basename = basename_
files[key].name = name
if (callback):
callback(filename)
return files
示例2: drupal_anonymous_user
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import stdClass [as 别名]
def drupal_anonymous_user(session=""):
"""
Generates a default anonymous user object.
@return Object - the user object.
"""
user = php.stdClass()
user.uid = 0
user.hostname = ip_address()
user.roles = {}
user.roles[DRUPAL_ANONYMOUS_RID] = "anonymous user"
user.session = session
user.cache = 0
return user
示例3: save_upload
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import stdClass [as 别名]
def save_upload(source, validators = {}, dest = False, \
replace = FILE_EXISTS_RENAME):
"""
Saves a file upload to a new location + The source file is validated as a
proper upload and handled as such.
The file will be added to the files table as a temporary file.
Temporary files
are periodically cleaned + To make the file permanent file call
file_set_status() to change its status.
@param source
A string specifying the name of the upload field to save.
@param validators
An optional, associative array of callback functions used to validate the
file + The keys are function names and the values arrays of callback
parameters which will be passed in after the user and file objects + The
functions should return an array of error messages, an empty array
indicates that the file passed validation.
The functions will be called in
the order specified.
@param dest
A string containing the directory source should be copied to + If this is
not provided or is not writable, the temporary directory will be used.
@param replace
A boolean indicating whether an existing file of the same name in the
destination directory should overwritten + A False value will generate a
new, unique filename in the destination directory.
@return
An object containing the file information, or False
in the event of an error.
"""
php.static(file_save_upload, 'upload_cache', {})
# Add in our check of the the file name length.
validators['file_validate_name_length'] = {}
# Return cached objects without processing since the file will have
# already been processed and the paths in FILES will be invalid.
if (php.isset(file_save_upload.uploadcache, source)):
return file_save_upload.uploadcache[source]
# If a file was uploaded, process it.
if (php.isset(p.FILES, 'files') and p.FILES['files']['name'][source] and \
php.is_uploaded_file(p.FILES['files']['tmp_name'][source])):
# Check for file upload errors and return False if a
# lower level system error occurred.
# @see http://php.net/manual/en/features.file-upload.errors.php
if p.FILES['files']['error'][source] == UPLOAD_ERR_OK:
pass
elif p.FILES['files']['error'][source] == UPLOAD_ERR_INI_SIZE or \
p.FILES['files']['error'][source] == UPLOAD_ERR_FORM_SIZE:
drupal_set_message(t(\
'The file %file could not be saved, because it exceeds %maxsize, ' + \
'the maximum allowed size for uploads.', \
{'%file' : source, '%maxsize' : \
format_size(file_upload_max_size())}), 'error')
return False
elif p.FILES['files']['error'][source] == UPLOAD_ERR_PARTIAL or \
p.FILES['files']['error'][source] == UPLOAD_ERR_NO_FILE:
drupal_set_message(t('The file %file could not be saved, ' + \
'because the upload did not complete.', {'%file' : source}), 'error')
return False
# Unknown error
else:
drupal_set_message(t('The file %file could not be saved. ' + \
'An unknown error has occurred.', {'%file' : source}), 'error')
return False
# Build the list of non-munged extensions.
# @todo: this should not be here + we need to figure out the right place.
extensions = ''
for rid,name in lib_appglobals.user.roles.items():
extensions += ' ' + variable_get("upload_extensions_rid",
variable_get('upload_extensions_default', \
'jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp'))
# Begin building file object.
file = php.stdClass()
file.filename = file_munge_filename(php.trim(\
basename(p.FILES['files']['name'][source]), '.'), extensions)
file.filepath = p.FILES['files']['tmp_name'][source]
file.filemime = p.FILES['files']['type'][source]
# Rename potentially executable files, to help prevent exploits.
if (php.preg_match('/\.(php|pl|py|cgi|asp|js)$/i', file.filename) and \
(php.substr(file.filename, -4) != '.txt')):
file.filemime = 'text/plain'
file.filepath += '.txt'
file.filename += '.txt'
# If the destination is not provided, or is not writable, then use the
# temporary directory.
if (php.empty(dest) or file_check_path(dest) == False):
dest = file_directory_temp()
file.source = source
file.destination = file_destination(file_create_path(dest + '/' + \
file.filename), replace)
file.filesize = FILES['files']['size'][source]
# Call the validation functions.
errors = {}
for function,args in validators.items():
array_unshift(args, file)
errors = php.array_merge(errors, function(*args))
# Check for validation errors.
if (not php.empty(errors)):
message = t('The selected file %name could not be uploaded.', \
#.........这里部分代码省略.........