コード例 #1
0
ファイル: virtual_namespace.py プロジェクト: mh6100/repy_v2
    def evaluate(self, context):
        """
    <Purpose>
      Evaluates the wrapped code within a context.

    <Arguments>
      context: A global context to use when executing the code.
      This should be a SafeDict object, but if a dict object is provided
      it will automatically be converted to a SafeDict object.

    <Exceptions>
      Any that may be raised by the code that is being evaluated.
      A RepyArgumentError exception will be raised if the provided context is not
      a safe dictionary object or a ContextUnsafeError if the
      context is a dict but cannot be converted into a SafeDict.

    <Returns>
      The context dictionary that was used during evaluation.
      If the context was a dict object, this will be a new
      SafeDict object. If the context was a SafeDict object,
      then this will return the same context object.
    """
        # Try to convert a normal dict into a SafeDict
        if type(context) is dict:
            try:
                context = safe.SafeDict(context)
            except Exception as e:
                raise ContextUnsafeError(
                    "Provided context is not safe! Exception: " + str(e))

        # Type check
        if not isinstance(context, safe.SafeDict):
            raise RepyArgumentError(
                "Provided context is not a safe dictionary!")

        # Call safe_run with the underlying dictionary
        safe.safe_run(self.code, context.__under__)

        # Return the dictionary we used
        return context
コード例 #2
0
    <Exceptions>
      Any that may be raised by the code that is being evaluated.
      A RepyArgumentError exception will be raised if the provided context is not
      a safe dictionary object or a ContextUnsafeError if the
      context is a dict but cannot be converted into a SafeDict.

    <Returns>
      The context dictionary that was used during evaluation.
      If the context was a dict object, this will be a new
      SafeDict object. If the context was a SafeDict object,
      then this will return the same context object.
    """
        # Try to convert a normal dict into a SafeDict
        if type(context) is dict:
            try:
                context = safe.SafeDict(context)
            except Exception, e:
                raise ContextUnsafeError, "Provided context is not safe! Exception: " + str(
                    e)

        # Type check
        if not isinstance(context, safe.SafeDict):
            raise RepyArgumentError, "Provided context is not a safe dictionary!"

        # Call safe_run with the underlying dictionary
        safe.safe_run(self.code, context.__under__)

        # Return the dictionary we used
        return context
コード例 #3
0
ファイル: virtual_namespace.py プロジェクト: Ashmita89/attic
    <Exceptions>
      Any that may be raised by the code that is being evaluated.
      A RepyArgumentError exception will be raised if the provided context is not
      a safe dictionary object or a ContextUnsafeError if the
      context is a dict but cannot be converted into a SafeDict.

    <Returns>
      The context dictionary that was used during evaluation.
      If the context was a dict object, this will be a new
      SafeDict object. If the context was a SafeDict object,
      then this will return the same context object.
    """
    # Try to convert a normal dict into a SafeDict
    if type(context) is dict:
      try:
        context = safe.SafeDict(context)
      except Exception, e:
        raise ContextUnsafeError, "Provided context is not safe! Exception: "+str(e)

    # Type check
    if not isinstance(context, safe.SafeDict):
      raise RepyArgumentError, "Provided context is not a safe dictionary!"

    # Call safe_run with the underlying dictionary
    safe.safe_run(self.code, context.__under__)

    # Return the dictionary we used
    return context