# Path: rx/exceptions.py
# class InvalidOperationException(Exception):
#   def __init__(self, text):
#     super(InvalidOperationException, self).__init__("Invalid operation: %s" % text)
# 
# Path: rx/observable.py
# class Producer(Observable):
#   """Base class for implementation of query operators, providing
#   performance benefits over the use of Observable.Create"""
# 
#   def subscribeCore(self, observer):
#     return self.subscribeRaw(observer, True)
# 
#   def subscribeRaw(self, observer, enableSafequard):
#     sink = SingleAssignmentDisposable()
#     subscription = SingleAssignmentDisposable()
# 
#     d = CompositeDisposable(sink, subscription)
# 
#     if enableSafequard:
#       observer = AutoDetachObserver(observer, d)
# 
#     def assignSink(s):
#       sink.disposable = s
# 
#     def scheduled():
#       subscription.disposable = self.run(observer, subscription, assignSink)
#       return Disposable.empty()
# 
#     if Scheduler.currentThread.isScheduleRequired():
#       Scheduler.currentThread.schedule(scheduled)
#     else:
#       scheduled()
# 
#     return d
# 
#   def run(self, observer, cancel, setSink):
#     raise NotImplementedError()


from rx.exceptions import InvalidOperationException
from rx.observable import Producer
import rx.linq.sink
    def __init__(self, parent, observer, cancel):
      super(SingleAsync.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.value = self.parent.defaultValue
      self.hasValue = False

    def onNext(self, value):
      b = False

      try:
        b = self.parent.predicate(value)
      except Exception as e:
        self.observer.onError(e)
        self.dispose()

      if b:
        if self.hasValue:
          self.observer.onError(InvalidOperationException("More than one element in observable"))
          self.dispose()
          return

        self.value = value
        self.hasValue = True

    def onError(self, exception):
      self.observer.onError(exception)
      self.dispose()

    def onCompleted(self):
      if not self.hasValue and self.parent.throwOnEmpty:

# Path: rx/exceptions.py
# class InvalidOperationException(Exception):
#   def __init__(self, text):
#     super(InvalidOperationException, self).__init__("Invalid operation: %s" % text)
# 
# Path: rx/observable.py
# class Producer(Observable):
#   """Base class for implementation of query operators, providing
#   performance benefits over the use of Observable.Create"""
# 
#   def subscribeCore(self, observer):
#     return self.subscribeRaw(observer, True)
# 
#   def subscribeRaw(self, observer, enableSafequard):
#     sink = SingleAssignmentDisposable()
#     subscription = SingleAssignmentDisposable()
# 
#     d = CompositeDisposable(sink, subscription)
# 
#     if enableSafequard:
#       observer = AutoDetachObserver(observer, d)
# 
#     def assignSink(s):
#       sink.disposable = s
# 
#     def scheduled():
#       subscription.disposable = self.run(observer, subscription, assignSink)
#       return Disposable.empty()
# 
#     if Scheduler.currentThread.isScheduleRequired():
#       Scheduler.currentThread.schedule(scheduled)
#     else:
#       scheduled()
# 
#     return d
# 
#   def run(self, observer, cancel, setSink):
#     raise NotImplementedError()


# Path: rx/linq/singleAsync.py
from rx.exceptions import InvalidOperationException
from rx.observable import Producer
import rx.linq.sink

    def __init__(self, parent, observer, cancel):
      super(SingleAsync.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.value = self.parent.defaultValue
      self.hasValue = False

    def onNext(self, value):
      b = False

      try:
        b = self.parent.predicate(value)
      except Exception as e:
        self.observer.onError(e)
        self.dispose()

      if b:
        if self.hasValue:
          self.observer.onError(InvalidOperationException("More than one element in observable"))
          self.dispose()
          return

        self.value = value
        self.hasValue = True

    def onError(self, exception):
      self.observer.onError(exception)
      self.dispose()

    def onCompleted(self):
      if not self.hasValue and self.parent.throwOnEmpty:

        self.observer.onError(InvalidOperationException("No elements in observable"))