Skip to content

Commit 8e12d34

Browse files
authored
Merge pull request #665 from ably/AIT-305/rename-files
chore: rename realtime_channel.py and default_vcdiff_decoder.py
2 parents 8177a47 + c1f170e commit 8e12d34

File tree

10 files changed

+82
-74
lines changed

10 files changed

+82
-74
lines changed

ably/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ably.types.options import Options, VCDiffDecoder
1313
from ably.util.crypto import CipherParams
1414
from ably.util.exceptions import AblyAuthException, AblyException, IncompatibleClientIdException
15-
from ably.vcdiff.default_vcdiff_decoder import AblyVCDiffDecoder
15+
from ably.vcdiff.defaultvcdiffdecoder import AblyVCDiffDecoder
1616

1717
logger = logging.getLogger(__name__)
1818
logger.addHandler(logging.NullHandler())
Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import asyncio
44
import logging
5-
from typing import TYPE_CHECKING, Any
5+
from typing import TYPE_CHECKING
66

77
from ably.realtime.connection import ConnectionState
88
from ably.rest.channel import Channel
99
from ably.rest.channel import Channels as RestChannels
1010
from ably.transport.websockettransport import ProtocolMessageAction
11+
from ably.types.channeloptions import ChannelOptions
1112
from ably.types.channelstate import ChannelState, ChannelStateChange
1213
from ably.types.flags import Flag, has_flag
1314
from ably.types.message import Message, MessageAction, MessageVersion
@@ -20,75 +21,10 @@
2021

2122
if TYPE_CHECKING:
2223
from ably.realtime.realtime import AblyRealtime
23-
from ably.util.crypto import CipherParams
2424

2525
log = logging.getLogger(__name__)
2626

2727

28-
class ChannelOptions:
29-
"""Channel options for Ably Realtime channels
30-
31-
Attributes
32-
----------
33-
cipher : CipherParams, optional
34-
Requests encryption for this channel when not null, and specifies encryption-related parameters.
35-
params : Dict[str, str], optional
36-
Channel parameters that configure the behavior of the channel.
37-
"""
38-
39-
def __init__(self, cipher: CipherParams | None = None, params: dict | None = None):
40-
self.__cipher = cipher
41-
self.__params = params
42-
# Validate params
43-
if self.__params and not isinstance(self.__params, dict):
44-
raise AblyException("params must be a dictionary", 40000, 400)
45-
46-
@property
47-
def cipher(self):
48-
"""Get cipher configuration"""
49-
return self.__cipher
50-
51-
@property
52-
def params(self) -> dict[str, str]:
53-
"""Get channel parameters"""
54-
return self.__params
55-
56-
def __eq__(self, other):
57-
"""Check equality with another ChannelOptions instance"""
58-
if not isinstance(other, ChannelOptions):
59-
return False
60-
61-
return (self.__cipher == other.__cipher and
62-
self.__params == other.__params)
63-
64-
def __hash__(self):
65-
"""Make ChannelOptions hashable"""
66-
return hash((
67-
self.__cipher,
68-
tuple(sorted(self.__params.items())) if self.__params else None,
69-
))
70-
71-
def to_dict(self) -> dict[str, Any]:
72-
"""Convert to dictionary representation"""
73-
result = {}
74-
if self.__cipher is not None:
75-
result['cipher'] = self.__cipher
76-
if self.__params:
77-
result['params'] = self.__params
78-
return result
79-
80-
@classmethod
81-
def from_dict(cls, options_dict: dict[str, Any]) -> ChannelOptions:
82-
"""Create ChannelOptions from dictionary"""
83-
if not isinstance(options_dict, dict):
84-
raise AblyException("options must be a dictionary", 40000, 400)
85-
86-
return cls(
87-
cipher=options_dict.get('cipher'),
88-
params=options_dict.get('params'),
89-
)
90-
91-
9228
class RealtimeChannel(EventEmitter, Channel):
9329
"""
9430
Ably Realtime Channel
@@ -139,7 +75,7 @@ def __init__(self, realtime: AblyRealtime, name: str, channel_options: ChannelOp
13975
self.__internal_state_emitter = EventEmitter()
14076

14177
# Initialize presence for this channel
142-
from ably.realtime.realtimepresence import RealtimePresence
78+
from ably.realtime.presence import RealtimePresence
14379
self.__presence = RealtimePresence(self)
14480

14581
# Pass channel options as dictionary to parent Channel class
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ably.util.exceptions import AblyException
2121

2222
if TYPE_CHECKING:
23-
from ably.realtime.realtime_channel import RealtimeChannel
23+
from ably.realtime.channel import RealtimeChannel
2424

2525
log = logging.getLogger(__name__)
2626

ably/realtime/realtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import logging
33
from typing import Optional
44

5+
from ably.realtime.channel import Channels
56
from ably.realtime.connection import Connection, ConnectionState
6-
from ably.realtime.realtime_channel import Channels
77
from ably.rest.rest import AblyRest
88

99
log = logging.getLogger(__name__)

ably/types/channeloptions.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
from ably.util.crypto import CipherParams
6+
from ably.util.exceptions import AblyException
7+
8+
9+
class ChannelOptions:
10+
"""Channel options for Ably Realtime channels
11+
12+
Attributes
13+
----------
14+
cipher : CipherParams, optional
15+
Requests encryption for this channel when not null, and specifies encryption-related parameters.
16+
params : Dict[str, str], optional
17+
Channel parameters that configure the behavior of the channel.
18+
"""
19+
20+
def __init__(self, cipher: CipherParams | None = None, params: dict | None = None):
21+
self.__cipher = cipher
22+
self.__params = params
23+
# Validate params
24+
if self.__params and not isinstance(self.__params, dict):
25+
raise AblyException("params must be a dictionary", 40000, 400)
26+
27+
@property
28+
def cipher(self):
29+
"""Get cipher configuration"""
30+
return self.__cipher
31+
32+
@property
33+
def params(self) -> dict[str, str]:
34+
"""Get channel parameters"""
35+
return self.__params
36+
37+
def __eq__(self, other):
38+
"""Check equality with another ChannelOptions instance"""
39+
if not isinstance(other, ChannelOptions):
40+
return False
41+
42+
return (self.__cipher == other.__cipher and
43+
self.__params == other.__params)
44+
45+
def __hash__(self):
46+
"""Make ChannelOptions hashable"""
47+
return hash((
48+
self.__cipher,
49+
tuple(sorted(self.__params.items())) if self.__params else None,
50+
))
51+
52+
def to_dict(self) -> dict[str, Any]:
53+
"""Convert to dictionary representation"""
54+
result = {}
55+
if self.__cipher is not None:
56+
result['cipher'] = self.__cipher
57+
if self.__params:
58+
result['params'] = self.__params
59+
return result
60+
61+
@classmethod
62+
def from_dict(cls, options_dict: dict[str, Any]) -> ChannelOptions:
63+
"""Create ChannelOptions from dictionary"""
64+
if not isinstance(options_dict, dict):
65+
raise AblyException("options must be a dictionary", 40000, 400)
66+
67+
return cls(
68+
cipher=options_dict.get('cipher'),
69+
params=options_dict.get('params'),
70+
)

test/ably/realtime/realtimechannel_publish_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import pytest
44

5+
from ably.realtime.channel import ChannelState
56
from ably.realtime.connection import ConnectionState
6-
from ably.realtime.realtime_channel import ChannelOptions, ChannelState
77
from ably.transport.websockettransport import ProtocolMessageAction
8+
from ably.types.channeloptions import ChannelOptions
89
from ably.types.message import Message
910
from ably.util.crypto import CipherParams
1011
from ably.util.exceptions import AblyException, IncompatibleClientIdException

test/ably/realtime/realtimechannel_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import pytest
44

5+
from ably.realtime.channel import ChannelState, RealtimeChannel
56
from ably.realtime.connection import ConnectionState
6-
from ably.realtime.realtime_channel import ChannelOptions, ChannelState, RealtimeChannel
77
from ably.transport.websockettransport import ProtocolMessageAction
8+
from ably.types.channeloptions import ChannelOptions
89
from ably.types.message import Message
910
from ably.util.exceptions import AblyException
1011
from test.ably.testapp import TestApp

test/ably/realtime/realtimechannel_vcdiff_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ably import AblyVCDiffDecoder
77
from ably.realtime.connection import ConnectionState
8-
from ably.realtime.realtime_channel import ChannelOptions
8+
from ably.types.channeloptions import ChannelOptions
99
from ably.types.options import VCDiffDecoder
1010
from test.ably.testapp import TestApp
1111
from test.ably.utils import BaseAsyncTestCase, WaitableEvent

test/ably/realtime/realtimeresume_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5+
from ably.realtime.channel import ChannelState
56
from ably.realtime.connection import ConnectionState
6-
from ably.realtime.realtime_channel import ChannelState
77
from ably.transport.websockettransport import ProtocolMessageAction
88
from test.ably.testapp import TestApp
99
from test.ably.utils import BaseAsyncTestCase, random_string

0 commit comments

Comments
 (0)