Skip to content

Commit b7209e1

Browse files
uri parsing
1 parent e232500 commit b7209e1

4 files changed

Lines changed: 23 additions & 19 deletions

File tree

build_and_push.sh

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

33
# Configuration
44
PACKAGE_NAME="montycat"
5-
VERSION="0.1.44"
5+
VERSION="0.1.45"
66
PYPI_TOKEN="${PYPI_TOKEN:-}"
77

88
# Exit on any error

montycat/core/engine.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import orjson
22
from typing import Union, List, Optional, Any
3+
from urllib.parse import urlparse
34
from .tools import Permission
45
from .utils import send_data
56

@@ -37,7 +38,7 @@ def __init__(self, host: str, port: int, username: str, password: str, store: Un
3738
def from_uri(cls, uri: str) -> 'Engine':
3839
"""
3940
Creates an Engine instance from a URI string in the format:
40-
montycat://host/port/username/password[/store]
41+
montycat://username:password@host:port[/store]
4142
4243
The store is optional. If not provided, it will be set to None.
4344
@@ -52,21 +53,24 @@ def from_uri(cls, uri: str) -> 'Engine':
5253
"""
5354
if not uri.startswith("montycat://"):
5455
raise ValueError("URI must use 'montycat://' protocol")
55-
parts = uri[len("montycat://"):].split("/")
56-
if len(parts) == 4:
57-
host, port_str, username, password = parts
58-
store = None
59-
elif len(parts) == 5:
60-
host, port_str, username, password, store = parts
61-
else:
62-
raise ValueError("Missing or extra parts in URI")
63-
if any(part == "" for part in [host, port_str, username, password]):
64-
raise ValueError("Host, port, username, and password must be non-empty")
65-
try:
66-
port = int(port_str)
67-
except ValueError:
68-
raise ValueError("Port must be an integer")
69-
return cls(host, port, username, password, store)
56+
57+
parsed = urlparse(uri)
58+
59+
if not parsed.username or not parsed.password:
60+
raise ValueError("Username and password must be provided")
61+
if not parsed.hostname or not parsed.port:
62+
raise ValueError("Host and port must be provided")
63+
64+
# Optional store
65+
store = parsed.path[1:] if parsed.path and len(parsed.path) > 1 else None
66+
67+
return cls(
68+
host=parsed.hostname,
69+
port=parsed.port,
70+
username=parsed.username,
71+
password=parsed.password,
72+
store=store
73+
)
7074

7175
async def _execute_query_with_credentials(self, command: List[Any]) -> Any:
7276
"""

montycat/store_classes/kv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ async def list_all_schemas_in_keyspace(cls):
368368
return await cls._run_query(query)
369369

370370
@classmethod
371-
def show_store_properties(cls):
371+
def show_properties(cls):
372372
"""
373373
Displays the properties of the store associated with the provided class settings.
374374

setup.py

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

33
setup(
44
name='montycat',
5-
version='0.1.44',
5+
version='0.1.45',
66
description='A Python client for MontyCat, NoSQL store utilizing Data Mesh architecture.',
77
packages=find_packages(),
88
zip_safe=False,

0 commit comments

Comments
 (0)