code: def resolve_session(self, subject_context):
          
          if (subject_context.resolve_session() is not None):
              msg = ("Context already contains a session.  Returning.")
              logger.debug(msg)
              return subject_context
  
          try:
              # Context couldn't resolve it directly, let's see if we can
              # since we  have direct access to the session manager:
              session = self.resolve_context_session(subject_context)
  
              # if session is None, given that subject_context.session
              # is None there is no harm done by setting it to None again
              subject_context.session = session
  
          except InvalidSessionException:
              msg = ("Resolved subject_subject_context context session is "
                     "invalid.  Ignoring and creating an anonymous "
                     "(session-less) Subject instance.")
              logger.debug(msg, exc_info=True)
  
          return subject_context
docs: This method attempts to resolve any associated session based on the
          context and returns a context that represents this resolved Session to
          ensure it may be referenced, if needed, by the invoked do_create_subject
          that performs actual ``Subject`` construction.
  
          If there is a ``Session`` already in the context (because that is what the
          caller wants to use for Subject construction) or if no session is
          resolved, this method effectively does nothing, returning an
          unmodified context as it was received by the method.
  
          :param subject_context: the subject context data that may resolve a
                                  Session instance
          :returns: the context