Coverage for heritrace / utils / uri_utils.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-07-02 10:16 +0000

1# SPDX-FileCopyrightText: 2025 Arcangelo Massari <arcangelo.massari@unibo.it> 

2# 

3# SPDX-License-Identifier: ISC 

4 

5import validators 

6from flask import current_app 

7from rdflib import URIRef 

8 

9 

10def generate_unique_uri( 

11 entity_type: str | None = None, context_data: dict | None = None 

12) -> URIRef: 

13 """ 

14 Generate a unique URI for a given entity type using the application's URI generator. 

15 The counter increment is handled internally by the URI generator. 

16 

17 Args: 

18 entity_type: The type of entity to generate a URI for 

19 context_data: Additional context data for special URI generation (e.g., Citation 

20 entities) 

21 

22 Returns: 

23 URIRef: The generated unique URI 

24 """ 

25 entity_type = str(entity_type) 

26 uri = current_app.config["URI_GENERATOR"].generate_uri(entity_type, context_data) 

27 return URIRef(uri) 

28 

29 

30def is_valid_url(value: str | None) -> bool: 

31 return bool(value and validators.url(value)) # type: ignore[arg-type]