<s> from rx import Observable , AnonymousObservable <EOL> from rx . linq . connectableobservable import ConnectableObservable <EOL> from rx . disposables import CompositeDisposable <EOL> from rx . internal import extensionmethod <EOL> @ extensionmethod ( Observable ) <EOL> def multicast ( self , subject = None , subject_selector = None , selector = None ) : <EOL> """<STR_LIT>""" <EOL> source = self <EOL> if subject_selector : <EOL> def subscribe ( observer ) : <EOL> connectable = source . multicast ( subject = subject_selector ( ) ) <EOL> return CompositeDisposable ( selector ( connectable ) . subscribe ( observer ) , connectable . connect ( ) ) <EOL> return AnonymousObservable ( subscribe ) <EOL> else : <EOL> return ConnectableObservable ( source , subject ) </s>
