当前位置: 首页>>代码示例>>Python>>正文


Python drupy.DrupyPHP类代码示例

本文整理汇总了Python中lib.drupy.DrupyPHP的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP类的具体用法?Python DrupyPHP怎么用?Python DrupyPHP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DrupyPHP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: invoke_all

def invoke_all(*args):
  """
   Invoke a hook in all enabled plugins that implement it.
  
   @param hook
     The name of the hook to invoke.
   @param ...
     Arguments to pass to the hook.
   @return
     An array of return values of the hook implementations. If plugins return
     arrays from their implementations, those are merged into one array.
  """
  global plugins
  args = list(args)
  hook = 'hook_%s' % args[0]
  del(args[0])
  return_ = []
  for plugin_ in implements(hook):
    if (lib_bootstrap.drupal_function_exists(hook, plugins[plugin_])):
      function = DrupyImport.getFunction(\
        plugins[plugin_], hook)
      result = php.call_user_func_array(function, args);
      if (result is not None and php.is_array(result)):
        return_ = p.array_merge_recursive(return_, result);
      elif (result is not None):
        return_.append( result );
  return return_
开发者ID:brendoncrawford,项目名称:drupy,代码行数:27,代码来源:plugin.py

示例2: registry_cache_path_files

def registry_cache_path_files():
    """
   Save the files required by the registry for this path.
  """
    used_code = registry_mark_code(None, None, True)
    if used_code:
        files = []
        type_sql = []
        params = []
        for type, names in used_code.items():
            type_sql.append("(name IN (" + db_placeholders(names, "varchar") + ") AND type = '%s')")
            params = php.array_merge(params, names)
            params.append(type)
        res = db_query("SELECT DISTINCT filename FROM {registry} WHERE " + php.implode(" OR ", type_sql), params)
        while True:
            row = db_fetch_object(res)
            if row == None:
                break
            files.append(row.filename)
        if files:
            sort(files)
            # Only write this to cache if the file list we are going to cache
            # is different to what we loaded earlier in the request.
            if files != registry_load_path_files(True):
                menu = menu_get_item()
                cache_set("registry:" + menu["path"], php.implode(";", files), "cache_registry")
开发者ID:sabren,项目名称:drupy,代码行数:26,代码来源:bootstrap.py

示例3: update_page

def update_page(content, show_messages = True):
  """
   Generate a themed update page.
  
   Note: this function is not themeable.
  
   @param content
     The page content to show.
   @param show_messages
     Whether to output status and error messages.
     False can be useful to postpone the messages to a subsequent page.
  """
  # Set required headers.
  drupal_set_header('Content-Type: text/html; charset=utf-8')
  # Assign content and show message flag.
  variables['content'] = content
  variables['show_messages'] = show_messages
  # The maintenance preprocess function is recycled here.
  template_preprocess_maintenance_page(variables)
  # Special handling of warning messages.
  messages = drupal_set_message()
  if (php.isset(messages['warning'])):
    title = ('The following update warnings should be carefully ' + \
      'reviewed before continuing' if \
      (php.count(messages['warning']) > 1) else \
        'The following update warning should be carefully ' + \
        'reviewed before continuing')
    variables['messages'] += '<h4>' + title + ':</h4>'
    variables['messages'] += theme('status_messages', 'warning')
  # This was called as a theme hook (not template), so we need to
  # fix path_to_theme() for the template, to point at the actual
  # theme rather than system plugin as owner of the hook.
  lib_appglobals.theme_path = 'themes/garland'
  return theme_render_template('themes/garland/maintenance-page.tpl.php', \
    variables)
开发者ID:brendoncrawford,项目名称:drupy,代码行数:35,代码来源:theme_maintenance.py

示例4: scan_directory

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
开发者ID:brendoncrawford,项目名称:drupy,代码行数:60,代码来源:file.py

示例5: create_filename

def create_filename(basename, directory):
  """
   Create a full file path from a directory and filename + If a file with the
   specified name already exists, an alternative will be used.
  
   @param basename string filename
   @param directory string directory
   @return
  """
  dest = directory + '/' + basename
  if (php.file_exists(dest)):
    # Destination file already exists, generate an alternative.
    pos = strrpos(basename, '.')
    if (pos):
      name = php.substr(basename, 0, pos)
      ext = php.substr(basename, pos)
    else:
      name = basename
    counter = 0
    while True:
      dest = directory + '/' + name + '_' + counter + ext
      counter += 1
      if (not php.file_exists(dest)):
        break
  return dest
开发者ID:brendoncrawford,项目名称:drupy,代码行数:25,代码来源:file.py

示例6: directory_temp

def directory_temp():
  """
   Determine the default temporary directory.
  
   @return A string containing a temp directory.
  """
  temporary_directory = variable_get('file_directory_temp', None)
  if (is_None(temporary_directory)):
    directories = []
    # Has PHP been set with an upload_tmp_dir?
    if (ini_get('upload_tmp_dir')):
      directories.append( ini_get('upload_tmp_dir') )
    # Operating system specific dirs.
    if (php.substr(PHP_OS, 0, 3) == 'WIN'):
      directories.append( 'c:\\windows\\temp' )
      directories.append( 'c:\\winnt\\temp' )
      path_delimiter = '\\'
    else:
      directories.append( '/tmp' )
      path_delimiter = '/'
    for directory in directories:
      if (not temporary_directory and php.is_dir(directory)):
        temporary_directory = directory
    # if a directory has been found, use it,
    # otherwise default to 'files/tmp' or 'files\\tmp'
    temporary_directory = (temporary_directory if \
      (temporary_directory != None) else \
      (file_directory_path() +  path_delimiter + 'tmp'))
    variable_set('file_directory_temp', temporary_directory)
  return temporary_directory
开发者ID:brendoncrawford,项目名称:drupy,代码行数:30,代码来源:file.py

示例7: destination

def destination(destination, replace):
  """
   Determines the destination path for a file depending on how replacement of
   existing files should be handled.
  
   @param destination A string specifying the desired path.
   @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 The destination file path or False if the file already exists and
     FILE_EXISTS_ERROR was specified.
  """
  if (php.file_exists(destination)):
    if replace == FILE_EXISTS_RENAME:
      basename = basename(destination)
      directory = php.dirname(destination)
      destination = file_create_filename(basename, directory)
    elif replace == FILE_EXISTS_ERROR:
      drupal_set_message(t('The selected file %file could not be copied, \
        because a file by that name already exists in the destination.', \
        {'%file' : destination}), 'error')
      return False
  return destination
开发者ID:brendoncrawford,项目名称:drupy,代码行数:25,代码来源:file.py

示例8: drupal_load

def drupal_load(type_, name):
    """
   Includes a file with the provided type and name. This prevents
   including a theme, engine, plugin, etc., more than once.
  
   @param type
     The type of item to load (i.e. theme, theme_engine, plugin).
   @param name
     The name of the item to load.
  
   @return
     TRUE if the item is loaded or has already been loaded.
  """
    php.static(drupal_load, "files", {})
    if not php.isset(drupal_load.files, type):
        drupal_load.files[type_] = {}
    if php.isset(drupal_load.files[type_], name):
        return True
    else:
        filename = drupal_get_filename(type_, name)
        if filename != False:
            lib_plugin.plugins[name] = DrupyImport.import_file(filename)
            drupal_load.files[type_][name] = True
            return True
        else:
            return False
开发者ID:sabren,项目名称:drupy,代码行数:26,代码来源:bootstrap.py

示例9: drupal_validate_utf8

def drupal_validate_utf8(text):
    """
   Checks whether a string is valid UTF-8.
  
   All functions designed to filter input should use drupal_validate_utf8
   to ensure they operate on valid UTF-8 strings to prevent bypass of the
   filter.
  
   When text containing an invalid UTF-8 lead byte (0xC0 - 0xFF) is presented
   as UTF-8 to Internet Explorer 6, the program may misinterpret subsequent
   bytes. When these subsequent bytes are HTML control characters such as
   quotes or angle brackets, parts of the text that were deemed safe by filters
   end up in locations that are potentially unsafe; An onerror attribute that
   is outside of a tag, and thus deemed safe by a filter, can be interpreted
   by the browser as if it were inside the tag.
  
   This def exploits preg_match behaviour (since PHP 4.3.5) when used
   with the u modifier, as a fast way to find invalid UTF-8. When the matched
   string contains an invalid byte sequence, it will fail silently.
  
   preg_match may not fail on 4 and 5 octet sequences, even though they
   are not supported by the specification.
  
   The specific preg_match behaviour is present since PHP 4.3.5.
  
   @param text
     The text to check.
   @return
     TRUE if the text is valid UTF-8, FALSE if not.
  """
    if php.strlen(text) == 0:
        return True
    return php.preg_match("/^./us", text) == 1
开发者ID:sabren,项目名称:drupy,代码行数:33,代码来源:bootstrap.py

示例10: _query_callback

def _query_callback(match, init = False):
  """
   Helper function for db_query().
  """
  php.static(_query_callback, 'args')
  if (init):
    _query_callback.args = list(match);
    return;
  # We must use type casting to int to convert FALSE/NULL/(TRUE?)
  if match[1] == '%d': 
    # We don't need db_escape_string as numbers are db-safe
    return str(int(php.array_shift(_query_callback.args))); 
  elif match[1] == '%s':
    return db.escape_string(php.array_shift(_query_callback.args));
  elif match[1] == '%n':
    # Numeric values have arbitrary precision, so can't be treated as float.
    # is_numeric() allows hex values (0xFF), but they are not valid.
    value = php.trim(php.array_shift(args));
    return  (value if (php.is_numeric(value) and not \
      php.stripos(value, 'x')) else '0')
  elif match[1] == '%%':
    return '%';
  elif match[1] == '%f':
    return float(php.array_shift(_query_callback.args));
  elif match[1] == '%b': # binary data
    return db.encode_blob(php.array_shift(_query_callback.args));
开发者ID:brendoncrawford,项目名称:drupy,代码行数:26,代码来源:database.py

示例11: create_table_sql

def create_table_sql(name, table):
  """
   Generate SQL to create a new table from a Drupal schema definition.
  
   @param name
     The name of the table to create.
   @param table
     A Schema API table definition array.
   @return
     An array of SQL statements to create the table.
  """
  if (php.empty(table['mysql_suffix'])):
    table['mysql_suffix'] = "/*not 40100 DEFAULT CHARACTER SET UTF8 */"
  sql = "CREATE TABLE {" +  name  + "} (\n"
  # Add the SQL statement for each field.
  for field_name,field in table['fields'].items():
    sql += _db_create_field_sql(field_name, _db_process_field(field)) +  ", \n"
  # Process keys & indexes.
  keys = _db_create_keys_sql(table)
  if (php.count(keys)):
    sql += php.implode(", \n", keys) +  ", \n"
  # Remove the last comma and space.
  sql = php.substr(sql, 0, -3) +  "\n) "
  sql += table['mysql_suffix']
  return array(sql)
开发者ID:brendoncrawford,项目名称:drupy,代码行数:25,代码来源:database_mysqli.py

示例12: cell

def cell(cell, header, ts, i):
  """
   Format a table cell.

   Adds a class attribute to all cells in the currently active column.

   @param cell
     The cell to format.
   @param header
     An array of column headers in the format described in theme_table().
   @param ts
     The current table sort context as returned from hook_init().
   @param i
     The index of the cell's table column.
   @return
     A properly formatted cell, ready for _theme_table_cell().
  """
  if (php.isset(header[i]['data']) and header[i]['data'] == ts['name'] and
     not php.empty(header[i]['field'])):
    if php.is_array(cell):
      if php.isset(cell['class']):
        cell['class'] += ' active'
      else:
        cell['class'] = 'active'
    else:
      cell = {'data': cell, 'class': 'active'}
  return cell
开发者ID:brendoncrawford,项目名称:drupy,代码行数:27,代码来源:tablesort.py

示例13: url_rewrite

def url_rewrite(path, options):
  """
   Rewrite URL's with language based prefix. Parameters are the same
   as those of the url() function.
  """
  # Only modify relative (insite) URLs.
  if (not options['external']):
    # Language can be passed as an option, or we go for current language.
    if (not php.isset(options, 'language')):
      options['language'] = lib_appglobals.language
    lang_type = variable_get('language_negotiation', \
      lib_bootstrap.LANGUAGE_NEGOTIATION_NONE)
    if lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_NONE:
      # No language dependent path allowed in this mode.
      del(options['language'])
      return
    elif lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_DOMAIN:
      if (options['language'].domain):
        # Ask for an absolute URL with our modified base_url.
        options['absolute'] = True
        options['base_url'] = options['language'].domain
      return
    elif lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_PATH_DEFAULT:
      default = language_default()
      if (options['language'].language == default.language):
        return
    if lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_PATH:
      if (not php.empty(options['language'].prefix)):
        options['prefix'] = options['language'].prefix +  '/'
      return
开发者ID:brendoncrawford,项目名称:drupy,代码行数:30,代码来源:language.py

示例14: drupal_set_message

def drupal_set_message(message=None, type="status", repeat=True):
    """
   Set a message which reflects the status of the performed operation.
  
   If the def is called with no arguments, this def returns all set
   messages without clearing them.
  
   @param message
     The message should begin with a capital letter and always ends with a
     period '.'.
   @param type
     The type of the message. One of the following values are possible:
     - 'status'
     - 'warning'
     - 'error'
   @param repeat
     If this is FALSE and the message is already set, then the message won't
     be repeated.
  """
    if message:
        if not php.isset(php.SESSION, "messages"):
            php.SESSION["messages"] = {}
        if not php.isset(php.SESSION["messages"], type):
            php.SESSION["messages"][type] = []
        if repeat or not php.in_array(message, php.SESSION["messages"][type]):
            php.SESSION["messages"][type].append(message)
    # messages not set when DB connection fails
    return php.SESSION["messages"] if php.isset(php.SESSION, "messages") else None
开发者ID:sabren,项目名称:drupy,代码行数:28,代码来源:bootstrap.py

示例15: drupal_get_messages

def drupal_get_messages(type=None, clear_queue=True):
    """
   Return all messages that have been set.
  
   @param type
     (optional) Only return messages of this type.
   @param clear_queue
     (optional) Set to FALSE if you do not want to clear the messages queue
   @return
     An associative array, the key is the message type, the value an array
     of messages. If the type parameter is passed, you get only that type,
     or an empty array if there are no such messages. If type is not passed,
     all message types are returned, or an empty array if none exist.
  """
    messages = drupal_set_message()
    if not php.empty("messages"):
        if type != None and type != False:
            if clear_queue:
                del (php.SESSION["messages"][type])
            if php.isset(messages, type):
                return {type: messages[type]}
        else:
            if clear_queue:
                del (php.SESSION["messages"])
            return messages
    return {}
开发者ID:sabren,项目名称:drupy,代码行数:26,代码来源:bootstrap.py


注:本文中的lib.drupy.DrupyPHP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。