Esempio n. 1
0
        def __init__(self, value, key):
            """Initialze internal state.

      Eval the string value and save the result.

      Args:
        value: String to compile as a regular expression.
        key: The YAML field name.

      Raises:
        InvalidCodeInConfiguration: if the code could not be evaluated, or
        the evalauted method is not callable.
      """
            self.value = value
            try:
                self.method = eval(value, _global_temp_globals)
            except Exception as err:
                raise bulkloader_errors.InvalidCodeInConfiguration(
                    'Invalid code for %s. Code: "%s". Details: %s' %
                    (key, value, err))
            if not callable(self.method):
                raise bulkloader_errors.InvalidCodeInConfiguration(
                    'Code for %s did not return a callable.  Code: "%s".' %
                    (key, value))

            self.supports_bulkload_state = False
            try:
                argspec = inspect.getargspec(self.method)
                if 'bulkload_state' in argspec[0]:
                    self.supports_bulkload_state = True
            except TypeError:
                pass
        def __init__(self, value, key):
            """Initialze internal state.

      Eval the string value and save the result.

      Args:
        value: String to compile as a regular expression.
        key: The YAML field name.

      Raises:
        InvalidCodeInConfiguration: if the code could not be evaluated, or
        the evalauted method is not callable.
      """
            self.value = value
            try:
                self.method = eval(value, _global_temp_globals)
            except Exception, err:
                raise bulkloader_errors.InvalidCodeInConfiguration(
                    'Invalid code for %s. Code: "%s". Details: %s' %
                    (key, value, err))