Skip to content

Commit 757d45e

Browse files
committed
migrate to rxpy v4
1 parent 2e5382b commit 757d45e

File tree

139 files changed

+654
-565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+654
-565
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ venv-rx
22
*.pyc
33
__pycache__
44
*.egg-info
5+
.vscode
6+
.DS_Store
7+
notebook
58
build
69
dist

Chapter01/echo1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
import rx
2+
import reactivex as rx
33

44
argv = rx.from_(sys.argv[1:])
55

Chapter01/echo2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
2-
import rx
3-
import rx.operators as ops
2+
import reactivex as rx
3+
from reactivex import operators as ops
44

55
argv = rx.from_(sys.argv[1:])
66
argv = argv.pipe(

Chapter02/event_loop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ async def wait(delay):
99
print("waited for {} seconds at {}:{}:{}".format(delay, now.hour, now.minute, now.second))
1010
return True
1111

12-
loop = asyncio.get_event_loop()
12+
loop = asyncio.new_event_loop()
1313
loop.run_until_complete(wait(2))

Chapter02/http_echo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def start_server(runner):
1515
app.router.add_route('GET', '/echo/{what}', echo_handler)
1616
runner = web.AppRunner(app)
1717

18-
loop = asyncio.get_event_loop()
18+
loop = asyncio.new_event_loop()
1919
loop.create_task(start_server(runner))
2020

2121
loop.run_forever()

Chapter03/cycle_subject.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import rx
2-
import rx.operators as ops
3-
from rx.subject import Subject
1+
import reactivex as rx
2+
from reactivex import operators as ops
3+
from reactivex.subject import Subject
44

55

66
def component_a(input):

Chapter03/rx_http_echo.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
22
from aiohttp import web
3-
import rx
4-
import rx.operators as ops
5-
from rx.subject import Subject
3+
import reactivex as rx
4+
from reactivex import operators as ops
5+
from reactivex.subject import Subject
66

77

88
def http_driver(sink, loop):
@@ -26,6 +26,7 @@ async def on_request_data(request, path):
2626
data, status = response_future.result()
2727

2828
response = web.StreamResponse(status=status, reason=None)
29+
response.content_type = "text/plain"
2930
await response.prepare(request)
3031
if data is not None:
3132
await response.write(data)
@@ -108,7 +109,7 @@ def echo_server(source):
108109

109110

110111
def main():
111-
loop = asyncio.get_event_loop()
112+
loop = asyncio.new_event_loop()
112113
http_proxy = Subject()
113114
sources = {
114115
'http': http_driver(http_proxy, loop),

Chapter04/catch_exception.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
33

44

55
err = rx.throw("error!")

Chapter04/create1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
def on_subscribe(observer, scheduler):

Chapter04/create2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
def sum_even(source):

Chapter04/dispose.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
numbers = rx.from_([1, 2, 3])

Chapter04/from_callback.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
def foo(what, handler):

Chapter04/from_future.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22
import asyncio
33

44

@@ -7,9 +7,10 @@ async def foo(future):
77
future.set_result(2)
88

99

10-
loop = asyncio.get_event_loop()
10+
loop = asyncio.new_event_loop()
11+
asyncio.set_event_loop(loop)
1112
done = loop.create_future()
12-
asyncio.ensure_future(foo(done))
13+
t = asyncio.ensure_future(foo(done), loop=loop)
1314

1415
number = rx.from_future(done)
1516
print("subscribing...")
@@ -20,5 +21,5 @@ async def foo(future):
2021
)
2122

2223
print("staring mainloop")
23-
loop.run_until_complete(done)
24+
loop.run_until_complete(t)
2425
loop.close()

Chapter04/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22
import datetime
33
import time
44

Chapter04/just.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33
number = rx.just(1)
44
number.subscribe(

Chapter04/of1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33
numbers = rx.of(1, 2, 3, 4)
44
numbers.subscribe(

Chapter04/of2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
def create_numbers_observable(*args):

Chapter04/publish_connect1.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
3+
34

45
numbers = rx.from_([1, 2, 3])
56
pub_numbers = numbers.pipe(ops.publish())

Chapter04/publish_connect2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
33

44

55
numbers = rx.from_([1, 2, 3])

Chapter04/publish_connect3.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
3+
34

45
numbers = rx.from_([1, 2, 3])
56
pub_numbers = numbers.pipe(ops.publish())

Chapter04/range1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
numbers = rx.range(1, 4)

Chapter04/range2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33
numbers = rx.from_(range(1, 5))
44
numbers.subscribe(

Chapter04/range3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33
numbers = rx.from_(range(1, 10, 2))
44
numbers.subscribe(

Chapter04/repeat1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
33

44
ones = rx.just(1).pipe(ops.repeat(5))
55
ones.subscribe(

Chapter04/repeat2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
33

44
numbers = rx.from_([1, 2, 3])
55
numbers.pipe(

Chapter04/retry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
import rx.operators as ops
1+
import reactivex as rx
2+
from reactivex import operators as ops
33

44

55
subscribe_count = 0

Chapter04/start1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22
import threading
33

44

Chapter04/start2.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
from rx.scheduler.eventloop import AsyncIOScheduler
1+
import reactivex as rx
2+
from reactivex.scheduler.eventloop import AsyncIOScheduler
33
import threading
44
import asyncio
55

@@ -9,7 +9,7 @@ def foo():
99
return 2
1010

1111

12-
loop = asyncio.get_event_loop()
12+
loop = asyncio.new_event_loop()
1313
done = loop.create_future()
1414
scheduler = AsyncIOScheduler(loop=loop)
1515

Chapter04/subscribe1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import rx
2-
from rx.core import Observer
1+
import reactivex as rx
2+
from reactivex import Observer
33

44

55
class MyObserver(Observer):

Chapter04/subscribe2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33

44
numbers = rx.from_([1, 2, 3])

Chapter04/throw1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33
error = rx.throw("Something wrong happened")
44
error.subscribe(

Chapter04/throw2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rx
1+
import reactivex as rx
22

33
exception = rx.throw(NotImplementedError("I do nothing"))
44
exception.subscribe(

Chapter04/timer1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from rx import Observable
1+
import reactivex as rx
22
import datetime
33
import time
44

55
print("starting at {}".format(datetime.datetime.now()))
6-
one_shot = Observable.timer(1000)
6+
one_shot = rx.timer(1.0)
77
one_shot.subscribe(
88
on_next=lambda i: print("tick {} at {}".format(
99
i, datetime.datetime.now())),

Chapter05/asyncio_scheduler1.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import rx
2-
import rx.operators as ops
3-
from rx.scheduler.eventloop import AsyncIOScheduler
1+
import reactivex as rx
2+
import reactivex.operators as ops
3+
from reactivex.scheduler.eventloop import AsyncIOScheduler
44
import threading
55
import asyncio
66
import threading
77

8-
loop = asyncio.get_event_loop()
8+
loop = asyncio.new_event_loop()
99
asyncio_scheduler = AsyncIOScheduler(loop=loop)
1010
numbers = rx.from_([1, 2, 3, 4], scheduler=asyncio_scheduler)
1111

Chapter05/newthread_scheduler1.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import rx
2-
import rx.operators as ops
3-
from rx.scheduler import NewThreadScheduler
1+
import reactivex as rx
2+
import reactivex.operators as ops
3+
from reactivex.scheduler import NewThreadScheduler
44
import threading
55
import time
66

Chapter05/newthread_scheduler2.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import rx
2-
import rx.operators as ops
3-
from rx.scheduler import NewThreadScheduler
1+
import reactivex as rx
2+
import reactivex.operators as ops
3+
from reactivex.scheduler import NewThreadScheduler
44
import threading
55
import time
66

Chapter05/threadpool_scheduler1.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import rx
2-
import rx.operators as ops
3-
from rx.scheduler import ThreadPoolScheduler
1+
import reactivex as rx
2+
import reactivex.operators as ops
3+
from reactivex.scheduler import ThreadPoolScheduler
44
import threading
55
import time
66

Chapter05/threadpool_scheduler2.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import rx
2-
import rx.operators as ops
3-
from rx.scheduler import ThreadPoolScheduler
1+
import reactivex as rx
2+
import reactivex.operators as ops
3+
from reactivex.scheduler import ThreadPoolScheduler
44
import threading
55
import time
66

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023, Romain Picard
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Chapter06/audio-encode-server/README.rst

+12

Chapter06/audio-encode-server/audio_encode_server/encoder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from collections import namedtuple
3-
import rx
3+
import reactivex as rx
44
import sox
55

66
from cyclotron import Component

0 commit comments

Comments
 (0)