vendor/zasync/1.1

changeset 36:025ee8ba2d50 1.1-nux

Removed trailing whitespace
author rspivak
date Thu, 22 Feb 2007 15:25:22 +0000
parents 4f2bae7490b2
children e70bf02ce6dd
files client/zasync/plugins.py
diffstat 1 files changed, 64 insertions(+), 64 deletions(-) [+]
line diff
     1.1 --- a/client/zasync/plugins.py
     1.2 +++ b/client/zasync/plugins.py
     1.3 @@ -28,10 +28,10 @@
     1.4  #### simple schedule
     1.5  
     1.6  def schedule(seconds):
     1.7 -    """proof of concept and "Hello World"; use to fire your callbacks after 
     1.8 -    seconds (approximately).  zope_exec is better for potentially 
     1.9 +    """proof of concept and "Hello World"; use to fire your callbacks after
    1.10 +    seconds (approximately).  zope_exec is better for potentially
    1.11      expensive tasks because it is cancellable (can time out) and you can guage
    1.12 -    better if the expensive task has started.  You might schedule a zope_exec 
    1.13 +    better if the expensive task has started.  You might schedule a zope_exec
    1.14      within a schedule callback, if you needed a scheduled expensive task."""
    1.15      d = defer.Deferred()
    1.16      reactor.callLater(seconds, d.callback, seconds)
    1.17 @@ -44,18 +44,18 @@
    1.18      # XXX also? instead? incorporate easy and introspectable chaining into
    1.19      # zopeDeferreds
    1.20      """aggregate calls to other plugins.  each call may either be a number
    1.21 -    (integer or float) of seconds to pause, or a tuple of (plugin name, args 
    1.22 -    tuple, kwargs dict).  For example, 
    1.23 -    
    1.24 +    (integer or float) of seconds to pause, or a tuple of (plugin name, args
    1.25 +    tuple, kwargs dict).  For example,
    1.26 +
    1.27      aggregatePlugins(
    1.28          ('zope_exec', ('/my_site', 'home/my_script'), {}),
    1.29          5,
    1.30          ('zope_exec', ('/my_site', 'home/my_other_script'), {}))
    1.31 -    
    1.32 +
    1.33      would ask zope_exec to call my_script in one transaction, wait 5 seconds,
    1.34      and then call my_other_script.
    1.35 -    
    1.36 -    If any of the plugins fail, the failure is returned without proceeding 
    1.37 +
    1.38 +    If any of the plugins fail, the failure is returned without proceeding
    1.39      further down the remaining calls.  The failure is annotated with a list of
    1.40      the completed calls ('completed_calls'), the call active during the failure
    1.41      ('active_call'), and remaining calls('remaining_calls').
    1.42 @@ -65,7 +65,7 @@
    1.43      return thunkmaker.deferred
    1.44  
    1.45  class AggregateThunkMaker(object):
    1.46 -    
    1.47 +
    1.48      def __init__(self, zopeDeferredTuple, *calls):
    1.49          self.deferred = defer.Deferred()
    1.50          self.pending = list(calls)
    1.51 @@ -98,9 +98,9 @@
    1.52                          timeout = call_info["timeout"]
    1.53                          remainingSeconds = client.active[self.zopeDeferredId][0]
    1.54                          client.makeCall(
    1.55 -                            self.path, self.zopeDeferredId, plugin, args, kwargs, 
    1.56 +                            self.path, self.zopeDeferredId, plugin, args, kwargs,
    1.57                              remainingSeconds, timeout, self.returnResult)
    1.58 -            
    1.59 +
    1.60      def returnResult(self, value, path, zopeDeferredId, error=False):
    1.61          if error:
    1.62              value.completed_calls = tuple(self.completed)
    1.63 @@ -118,23 +118,23 @@
    1.64  except ImportError:
    1.65      pass
    1.66  else:
    1.67 -    def query_unprotected_ldap(uri, base, scope, filterstr, attrlist=None): 
    1.68 +    def query_unprotected_ldap(uri, base, scope, filterstr, attrlist=None):
    1.69          """Query unprotected ldap (i.e., not ldaps).  arguments are the URI of
    1.70 -        the ldap server, the base of the query, the scope of the search, and 
    1.71 +        the ldap server, the base of the query, the scope of the search, and
    1.72          the query string.  The scope should be one of the following three
    1.73          strings:
    1.74          - 'object' (equivalent to python ldap's SCOPE_BASE constant)
    1.75          - 'subtree' (SCOPE_SUBTREE)
    1.76          - 'children' (SCOPE_ONELEVEL)
    1.77 -        
    1.78 +
    1.79          example values:
    1.80          'ldap://ldap.example.edu', 'dc=example,dc=edu', 'subtree', query
    1.81 -        
    1.82 +
    1.83          Failures are exceptions as defined by the python ldap package.
    1.84          """
    1.85          scope = {
    1.86              'object':ldap.SCOPE_BASE,
    1.87 -            'subtree':ldap.SCOPE_SUBTREE, 
    1.88 +            'subtree':ldap.SCOPE_SUBTREE,
    1.89              'children':ldap.SCOPE_ONELEVEL}.get(scope)
    1.90          if scope is None:
    1.91              raise ValueError(
    1.92 @@ -150,29 +150,29 @@
    1.93          d.addErrback(abandon_query, l, msgid)
    1.94          reactor.callLater(2, poll_results, d, l, msgid)
    1.95          return d
    1.96 -    
    1.97 +
    1.98      def query_protected_ldap(uri, username, password, base, scope, filterstr,
    1.99 -                             attrlist=None): 
   1.100 +                             attrlist=None):
   1.101          """Query protected ldap (i.e., ldaps, over SSL).  arguments are the URI
   1.102 -        of the ldap server, the user name (including ldap qualifiers, as in the 
   1.103 -        example below), the user password, the base of the query, the scope of 
   1.104 -        the search, and the query string.  The scope should be one of the 
   1.105 +        of the ldap server, the user name (including ldap qualifiers, as in the
   1.106 +        example below), the user password, the base of the query, the scope of
   1.107 +        the search, and the query string.  The scope should be one of the
   1.108          following three strings:
   1.109          - 'object' (equivalent to python ldap's SCOPE_BASE constant)
   1.110          - 'subtree' (SCOPE_SUBTREE)
   1.111          - 'children' (SCOPE_ONELEVEL)
   1.112 -        
   1.113 -        example values ('ldapuser' and 'ldappass' are username and password 
   1.114 +
   1.115 +        example values ('ldapuser' and 'ldappass' are username and password
   1.116          # values):
   1.117 -        'ldaps://ldap.example.edu:636', 
   1.118 -        'uid=ldapuser,ou=users,ou=special,dc=example,dc=edu', 'ldappass', 
   1.119 +        'ldaps://ldap.example.edu:636',
   1.120 +        'uid=ldapuser,ou=users,ou=special,dc=example,dc=edu', 'ldappass',
   1.121          'dc=example,dc=edu', 'subtree', query
   1.122 -        
   1.123 +
   1.124          Failures are exceptions as defined by the python ldap package.
   1.125          """
   1.126          scope = {
   1.127              'object':ldap.SCOPE_BASE,
   1.128 -            'subtree':ldap.SCOPE_SUBTREE, 
   1.129 +            'subtree':ldap.SCOPE_SUBTREE,
   1.130              'children':ldap.SCOPE_ONELEVEL}.get(scope)
   1.131          if scope is None:
   1.132              raise ValueError(
   1.133 @@ -189,12 +189,12 @@
   1.134          d.addErrback(abandon_query, l, msgid)
   1.135          reactor.callLater(2, poll_results, d, l, msgid)
   1.136          return d
   1.137 -    
   1.138 +
   1.139      def abandon_query(failure, connection, msgid):
   1.140          logging.getLogger('zasync.plugins').info('abandoning ldap search')
   1.141          connection.abandon(msgid)
   1.142          return failure
   1.143 -    
   1.144 +
   1.145      def poll_results(deferred, connection, msgid):
   1.146          if not deferred.called:
   1.147              logging.getLogger('zasync.plugins').debug('polling ldap')
   1.148 @@ -220,7 +220,7 @@
   1.149  from Products.zasync.manager import Expression, sanitize, cleanFailure
   1.150  from Products.zasync.bucketqueue import BucketQueue
   1.151  
   1.152 -MAXTHREADPOOL = 1 # a real thread pool doesn't seem to be a problem, but 
   1.153 +MAXTHREADPOOL = 1 # a real thread pool doesn't seem to be a problem, but
   1.154  # our use doesn't need more than one thread, and this removes one possible
   1.155  # bug source.  May increase again; should make it configurable in a way
   1.156  # other than changing this file....
   1.157 @@ -261,7 +261,7 @@
   1.158      finally:
   1.159          taskStatusLock.release()
   1.160      return val
   1.161 -        
   1.162 +
   1.163  
   1.164  def setTaskStatus(key, value):
   1.165      taskStatusLock.acquire()
   1.166 @@ -269,12 +269,12 @@
   1.167          taskStatus[key] = value
   1.168      finally:
   1.169          taskStatusLock.release()
   1.170 -    
   1.171 +
   1.172  
   1.173  # zopeDeferredTuple is (tool path, zope deferred id)
   1.174  
   1.175  def legacy_zope_exec(zopeDeferredTuple, homepath, action, *chain):
   1.176 -    """For backwards compatibility with zope exec calls that did not include 
   1.177 +    """For backwards compatibility with zope exec calls that did not include
   1.178      request data, register this function for the zope exec plugin instead of
   1.179      the standard one."""
   1.180      return zope_exec(zopeDeferredTuple, homepath, None, action, *chain)
   1.181 @@ -292,26 +292,26 @@
   1.182      a value for CALLBACK is needed but not provided in a dictionary, it is
   1.183      effectively 'result'; if a value for ERRBACK is needed but not provided in
   1.184      a dictionary, it is effectively 'failure'.
   1.185 -    
   1.186 -    homepath is a path from the root (which may be a boolean False value such 
   1.187 -    as None, a tuple or list of path elements, or a string, but will be 
   1.188 +
   1.189 +    homepath is a path from the root (which may be a boolean False value such
   1.190 +    as None, a tuple or list of path elements, or a string, but will be
   1.191      normalized to a string) to an object that will be available as "home" in the
   1.192 -    action expressions, and is also used as a domain so that only a single 
   1.193 -    zope_exec within a given homepath will be executed at a time.  Note that 
   1.194 +    action expressions, and is also used as a domain so that only a single
   1.195 +    zope_exec within a given homepath will be executed at a time.  Note that
   1.196      nested domains are effectively completely different domains: a zope_exec
   1.197 -    with a "/" homepath may be attempted at the same time as a zope_exec 
   1.198 +    with a "/" homepath may be attempted at the same time as a zope_exec
   1.199      with a "/cmf_site" homepath.
   1.200 -    
   1.201 -    Actions are performed as (and in the security context of) the user who owns 
   1.202 +
   1.203 +    Actions are performed as (and in the security context of) the user who owns
   1.204      the zope deferred.  A dummy request is available.
   1.205 -    
   1.206 +
   1.207      The code checks between each action and immediately prior to committing to
   1.208 -    see if the deferred has been cancelled (timed out); if it has been 
   1.209 +    see if the deferred has been cancelled (timed out); if it has been
   1.210      cancelled, the job is aborted.  zope_exec are not called (although errbacks
   1.211      on the zope deferred will be called, as usual).
   1.212 -    
   1.213 +
   1.214      expressions have the following names available to them:
   1.215 -    
   1.216 +
   1.217      - nothing: None
   1.218      - user: the user object (the owner of the zope deferred)
   1.219      - home: the object referred to by the homepath
   1.220 @@ -320,16 +320,16 @@
   1.221      - deferred: the Zope deferred
   1.222      - root: the physical Zope root
   1.223      - modules: the standard Zope secure module importer
   1.224 -    - result: the result of the most recent previous successful call 
   1.225 +    - result: the result of the most recent previous successful call
   1.226                (initializes to None)
   1.227      - failure: the failure of the most recent previous unsuccessful call
   1.228                 (initializes to None)
   1.229      - results: a dictionary of results returned from past actions, as described
   1.230                 above.
   1.231      - request: the faux request
   1.232 -    
   1.233 +
   1.234      Example of putting a call:
   1.235 -    
   1.236 +
   1.237      root.asynchronous_call_manager.putCall(
   1.238          "zope_exec", # name of plugin
   1.239          "/another_site", # homepath
   1.240 @@ -418,10 +418,10 @@
   1.241              logger.debug(
   1.242                  'zope_exec: added schedule_mainthread to zasync chore list')
   1.243          if len_threadIds + 1 < MAXTHREADPOOL and taskQueue.primed():
   1.244 -            reactor.callLater(0.1, start_worker) # if start_worker is called by 
   1.245 +            reactor.callLater(0.1, start_worker) # if start_worker is called by
   1.246              # scheduleServerRetry as set up in schedule_mainthread, then it is
   1.247              # possible that more threads could be needed.  We check here, and
   1.248 -            # if it seems we could use some more, then we schedule another 
   1.249 +            # if it seems we could use some more, then we schedule another
   1.250              # thread to possibly start in a tenth of a second (giving active
   1.251              # threads a healthy chance to take a stab at the queue before we
   1.252              # look again)
   1.253 @@ -440,7 +440,7 @@
   1.254  def schedule_mainthread():
   1.255      # do jobs that the zope_exec_worker needs done in the main
   1.256      # thread.  Basically needed for letting zasync return failures or results
   1.257 -    # to Zope.  The housekeeping function in the client module kicks this 
   1.258 +    # to Zope.  The housekeeping function in the client module kicks this
   1.259      # regularly.
   1.260      global callbacks, serverDown
   1.261      logger = logging.getLogger('zasync.plugins')
   1.262 @@ -470,7 +470,7 @@
   1.263  
   1.264  def zope_exec_worker():
   1.265      """the thread method."""
   1.266 -    # XXX generalize this to not require zope deferred so other plugins can use 
   1.267 +    # XXX generalize this to not require zope deferred so other plugins can use
   1.268      logger = logging.getLogger('zasync.plugins')
   1.269      thread_id = thread.get_ident()
   1.270      logger.debug(
   1.271 @@ -561,7 +561,7 @@
   1.272                                  raise ValueError(
   1.273                                      "each action must be a string, a tuple "
   1.274                                      "pair, or a dict", action)
   1.275 -                            if (not call or 
   1.276 +                            if (not call or
   1.277                                  success and call=='result' or
   1.278                                  not success and call=='failure'): # no-ops
   1.279                                  continue
   1.280 @@ -606,7 +606,7 @@
   1.281                                      res.printDetailedTraceback(out)
   1.282                                      logger.debug(
   1.283                                          '%s\n\n%s\n\n%s',
   1.284 -                                        msg, out.getvalue(), 
   1.285 +                                        msg, out.getvalue(),
   1.286                                          res.getErrorMessage())
   1.287                                  else:
   1.288                                      logger.debug(msg, exc_info=True)
   1.289 @@ -620,9 +620,9 @@
   1.290                              # been communicated within the main zasync thread
   1.291                      except ConflictError:
   1.292                          remembered_failure = cleanFailure(failure.Failure())
   1.293 -                        transaction.abort() 
   1.294 +                        transaction.abort()
   1.295                          logger.debug(
   1.296 -                            'zope_exec: worker %s got conflict error', 
   1.297 +                            'zope_exec: worker %s got conflict error',
   1.298                              thread_id, exc_info=True)
   1.299                          if attempt < max_conflict_resolution_attempts-1:
   1.300                              time.sleep(attempt + 1) # XXX better idea?
   1.301 @@ -640,18 +640,18 @@
   1.302                                  (zopeDeferredTuple, homepath, actions),
   1.303                                  bucket=taskQueue.releaseBucket())
   1.304                              zopeDeferredTuple = None # foils the last finally.
   1.305 -                        # setting this module global communicates to the 
   1.306 +                        # setting this module global communicates to the
   1.307                          # schedule_mainthread chore that the start_worker
   1.308 -                        # function will need to be called once the server is 
   1.309 +                        # function will need to be called once the server is
   1.310                          # back online again
   1.311                          serverDown = True
   1.312                          raise
   1.313                      except:
   1.314                          # in other code, we often try to be nice even if the
   1.315                          # tool disappears for a moment.  We don't bother here,
   1.316 -                        # which lets the normal zasync code try to communicate 
   1.317 +                        # which lets the normal zasync code try to communicate
   1.318                          # the failure back to the log (and Zope, if the tool
   1.319 -                        # and the associated deferred happen to magically 
   1.320 +                        # and the associated deferred happen to magically
   1.321                          # reappear).
   1.322                          f = cleanFailure(failure.Failure())
   1.323                          transaction.abort()
   1.324 @@ -715,13 +715,13 @@
   1.325                          elif success:
   1.326                              logger.debug(
   1.327                                  'zope_exec: worker %s get final result %r; '
   1.328 -                                'scheduling zope deferred callback', 
   1.329 +                                'scheduling zope deferred callback',
   1.330                                  thread_id, result)
   1.331                              callbacks.put((deferred, result))
   1.332                          else:
   1.333                              logger.debug(
   1.334                                  'zope_exec: worker %s get final failure (%s); '
   1.335 -                                'scheduling zope deferred errback', 
   1.336 +                                'scheduling zope deferred errback',
   1.337                                  thread_id, fail.getErrorMessage())
   1.338                              callbacks.put((deferred, fail))
   1.339                          break
   1.340 @@ -766,7 +766,7 @@
   1.341          finally:
   1.342              threadPoolLock.release()
   1.343          deferred = getTaskStatus(zopeDeferredTuple, True)
   1.344 -        if deferred is not None: # looks like we still need to clean up the 
   1.345 +        if deferred is not None: # looks like we still need to clean up the
   1.346                                   # deferred we were just working on.
   1.347              if deferred is not CANCEL:
   1.348                  logger.debug(