Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
facebook
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mautrix
facebook
Commits
fa8ef9aa
Commit
fa8ef9aa
authored
5 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Don't use @asynccontextmanager as it's Python 3.7 only
parent
3abc627e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mautrix_facebook/portal.py
+15
-12
15 additions, 12 deletions
mautrix_facebook/portal.py
with
15 additions
and
12 deletions
mautrix_facebook/portal.py
+
15
−
12
View file @
fa8ef9aa
...
...
@@ -15,7 +15,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from
typing
import
Dict
,
Deque
,
Optional
,
Tuple
,
Union
,
TYPE_CHECKING
from
collections
import
deque
from
contextlib
import
asynccontextmanager
import
asyncio
import
logging
...
...
@@ -48,6 +47,14 @@ AttachmentClass = Union[AudioAttachment, VideoAttachment, FileAttachment, ImageA
LocationAttachment
,
ShareAttachment
]
class
FakeLock
:
async
def
__aenter__
(
self
)
->
None
:
pass
async
def
__aexit__
(
self
,
exc_type
,
exc
,
tb
)
->
None
:
pass
class
Portal
:
az
:
AppService
loop
:
asyncio
.
AbstractEventLoop
...
...
@@ -72,6 +79,7 @@ class Portal:
_dedup
:
Deque
[
Tuple
[
str
,
str
]]
_avatar_uri
:
Optional
[
ContentURI
]
_send_locks
:
Dict
[
str
,
asyncio
.
Lock
]
_noop_lock
:
FakeLock
=
FakeLock
()
def
__init__
(
self
,
fbid
:
str
,
fb_receiver
:
str
,
fb_type
:
ThreadType
,
mxid
:
Optional
[
RoomID
]
=
None
,
name
:
str
=
""
,
photo_id
:
str
=
""
,
...
...
@@ -254,25 +262,20 @@ class Portal:
# endregion
# region Matrix event handling
@asynccontextmanager
async
def
require_send_lock
(
self
,
user_id
:
str
)
->
None
:
def
require_send_lock
(
self
,
user_id
:
str
)
->
asyncio
.
Lock
:
try
:
lock
=
self
.
_send_locks
[
user_id
]
except
KeyError
:
lock
=
asyncio
.
Lock
()
self
.
_send_locks
[
user_id
]
=
lock
async
with
lock
:
yield
return
lock
@asynccontextmanager
async
def
optional_send_lock
(
self
,
user_id
:
str
)
->
None
:
def
optional_send_lock
(
self
,
user_id
:
str
)
->
Union
[
asyncio
.
Lock
,
FakeLock
]:
try
:
lock
=
self
.
_send_locks
[
user_id
]
return
self
.
_send_locks
[
user_id
]
except
KeyError
:
yield
return
async
with
lock
:
yield
pass
return
self
.
_noop_lock
async
def
handle_matrix_message
(
self
,
sender
:
'
u.User
'
,
message
:
MessageEventContent
,
event_id
:
EventID
)
->
None
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment