-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP / POC of dynamic dispatch for connectors
- Loading branch information
Alex Richey
authored and
Alex Richey
committed
Jan 6, 2025
1 parent
000ad1e
commit d4f5a7e
Showing
6 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dcpy.models.connectors import Connector | ||
|
||
_connectors = {} | ||
|
||
|
||
def register(connector: Connector): | ||
_connectors[connector.c_type] = connector | ||
|
||
|
||
def push(c_type: str, **kwargs) -> str: | ||
connector: Connector = _connectors[c_type] | ||
connector.push(**kwargs) | ||
return "" | ||
|
||
|
||
def pull(c_type: str, **kwargs) -> str: | ||
connector: Connector = _connectors[c_type] | ||
connector.pull(**kwargs) | ||
return "" | ||
|
||
|
||
from .socrata.publish import SocrataConnector | ||
|
||
register(SocrataConnector()) | ||
|
||
from .web import WebConnector | ||
|
||
register(WebConnector()) | ||
|
||
from .ftp import FTPConnector | ||
|
||
register(FTPConnector()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Placeholder | ||
|
||
from dcpy.models.connectors import Connector | ||
|
||
class FTPConnector(Connector): | ||
c_type = "ftp" | ||
|
||
def push(self, **kwargs): | ||
raise Exception(f"Push not implemented for {self.c_type}") | ||
def pull(self, **kwargs): | ||
raise Exception(f"Pull not implemented for {self.c_type}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import abc | ||
|
||
# TODO: question... I implemented methods as abc because w/ concrete methods, | ||
# static checkers like pylance will complain about type-safety of the overridden **kwargs. | ||
# I do wonder if there's a more elegant way. | ||
class Connector(abc.ABC): | ||
|
||
c_type: str | ||
|
||
@abc.abstractmethod | ||
def push(self, **kwargs): | ||
raise Exception(f"push not implemented for {self.c_type}") | ||
|
||
@abc.abstractmethod | ||
def pull(self, **kwargs): | ||
raise Exception(f"pull not implemented for {self.c_type}") |