oldaplib 0.3.8__py3-none-any.whl → 0.3.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,7 +80,7 @@ class ObservableSet(Notify):
80
80
  def __str__(self) -> str:
81
81
  return str(self._setdata)
82
82
 
83
- def __eq__(self, other: Iterable) -> bool:
83
+ def __eq__(self, other: Iterable[Any]) -> bool:
84
84
  if isinstance(other, ObservableSet):
85
85
  return self._setdata == other._setdata
86
86
  elif isinstance(other, set):
@@ -90,7 +90,7 @@ class ObservableSet(Notify):
90
90
  else:
91
91
  raise OldapErrorNotImplemented(f'Set.__eq__() not implemented for {type(other).__name__}')
92
92
 
93
- def __or__(self, other: Iterable) -> Self:
93
+ def __or__(self, other: Iterable[Any]) -> Self:
94
94
  if isinstance(other, ObservableSet):
95
95
  return ObservableSet(self._setdata.__or__(other._setdata), self._notifier, self._notify_data)
96
96
  elif isinstance(other, set):
@@ -100,25 +100,24 @@ class ObservableSet(Notify):
100
100
  else:
101
101
  raise OldapErrorNotImplemented(f'Set.__or__() not implemented for {type(other).__name__}')
102
102
 
103
- def __ror__(self, other: Self) -> Self:
104
- pass
103
+ def __ror__(self, other: Iterable[Any]) -> Self:
104
+ return ObservableSet(set(other).__or__(self._setdata), self._notifier, self._notify_data)
105
+
106
+ def __rsub__(self, other: Iterable[Any]) -> Self:
107
+ return ObservableSet(set(other).__sub__(self._setdata), self._notifier, self._notify_data)
105
108
 
106
- def __ior__(self, other: Iterable) -> Self:
109
+ def __ior__(self, other: Iterable[Any]) -> Self:
107
110
  tmp_copy = deepcopy(self)
108
111
  if isinstance(other, ObservableSet):
109
112
  self._setdata.__ior__(other._setdata)
110
- elif isinstance(other, set):
111
- self._setdata.__ior__(other)
112
- elif isinstance(other, Iterable):
113
- return ObservableSet(self._setdata.__ior__(set(other)), self._notifier, self._notify_data)
114
113
  else:
115
- raise OldapErrorNotImplemented(f'Set.i__or__() not implemented for {type(other).__name__}')
114
+ self._setdata.__ior__(set(other))
116
115
  if not self._old_value:
117
116
  self._old_value = tmp_copy
118
117
  self.notify()
119
118
  return self
120
119
 
121
- def __and__(self, other: Iterable) -> Self:
120
+ def __and__(self, other: Iterable[Any]) -> Self:
122
121
  if isinstance(other, ObservableSet):
123
122
  return ObservableSet(self._setdata.__and__(other._setdata), self._notifier, self._notify_data)
124
123
  elif isinstance(other, set):
@@ -128,7 +127,7 @@ class ObservableSet(Notify):
128
127
  else:
129
128
  raise OldapErrorNotImplemented(f'Set.__and__() not implemented for {type(other).__name__}')
130
129
 
131
- def __iand__(self, other: Iterable) -> Self:
130
+ def __iand__(self, other: Iterable[Any]) -> Self:
132
131
  tmp_copy = deepcopy(self)
133
132
  if isinstance(other, ObservableSet):
134
133
  self._setdata.__iand__(other._setdata)
@@ -146,7 +145,7 @@ class ObservableSet(Notify):
146
145
  def __rsub__(self, other: Self) -> Self:
147
146
  pass
148
147
 
149
- def __sub__(self, other: Iterable) -> Self:
148
+ def __sub__(self, other: Iterable[Any]) -> Self:
150
149
  if isinstance(other, ObservableSet):
151
150
  return ObservableSet(self._setdata.__sub__(other._setdata), self.notify, self._notify_data)
152
151
  elif isinstance(other, set):
@@ -156,7 +155,7 @@ class ObservableSet(Notify):
156
155
  else:
157
156
  raise OldapErrorNotImplemented(f'Set.__sub__() not implemented for {type(other).__name__}')
158
157
 
159
- def __isub__(self, other: Iterable) -> Self:
158
+ def __isub__(self, other: Iterable[Any]) -> Self:
160
159
  tmp_copy = deepcopy(self)
161
160
  if isinstance(other, ObservableSet):
162
161
  self._setdata.__isub__(other._setdata)
@@ -171,34 +170,45 @@ class ObservableSet(Notify):
171
170
  self.notify()
172
171
  return self
173
172
 
174
- def update(self, items: Iterable):
173
+ @classmethod
174
+ def coerce(cls, value: Iterable[Any], *, notifier=None, notify_data=None) -> "ObservableSet":
175
+ return value if isinstance(value, cls) else cls(value, notifier=notifier, notify_data=notify_data)
176
+
177
+ def update(self, items: Iterable[Any]):
175
178
  tmp_copy = deepcopy(self)
176
179
  self._setdata.update(items)
177
180
  if not self._old_value:
178
181
  self._old_value = tmp_copy
179
182
  self.notify()
180
183
 
181
- def intersection_update(self, items: Iterable):
184
+ def intersection_update(self, items: Iterable[Any]):
182
185
  tmp_copy = deepcopy(self)
183
186
  self._setdata.intersection_update(items)
184
187
  if not self._old_value:
185
188
  self._old_value = tmp_copy
186
189
  self.notify()
187
190
 
188
- def difference_update(self, items: Iterable):
191
+ def difference_update(self, items: Iterable[Any]):
189
192
  tmp_copy = deepcopy(self)
190
193
  self._setdata.difference_update(items)
191
194
  if not self._old_value:
192
195
  self._old_value = tmp_copy
193
196
  self.notify()
194
197
 
195
- def symmetric_difference_update(self, items: Iterable):
198
+ def symmetric_difference_update(self, items: Iterable[Any]):
196
199
  tmp_copy = deepcopy(self)
197
200
  self._setdata.symmetric_difference_update(items)
198
201
  if not self._old_value:
199
202
  self._old_value = tmp_copy
200
203
  self.notify()
201
204
 
205
+ def replace(self, items: Iterable[Any]) -> None:
206
+ tmp_copy = deepcopy(self)
207
+ self._setdata = set(items)
208
+ if not self._old_value:
209
+ self._old_value = tmp_copy
210
+ self.notify()
211
+
202
212
  def add(self, item: Any) -> None:
203
213
  tmp_copy = deepcopy(self)
204
214
  self._setdata.add(item)
@@ -443,33 +443,24 @@ class ResourceInstance:
443
443
 
444
444
  def get_data_permission(self, context: Context, permission: DataPermission) -> bool:
445
445
  permission_query = context.sparql_context
446
- # language=sparql
447
446
  permission_query += f'''
448
- SELECT (COUNT(?permset) as ?numOfPermsets)
449
- FROM oldap:onto
450
- FROM shared:onto
451
- FROM {self._graph}:onto
452
- FROM NAMED oldap:admin
453
- FROM NAMED {self._graph}:data
454
- WHERE {{
455
- BIND({self._iri.toRdf} as ?iri)
447
+ ASK {{
456
448
  GRAPH {self._graph}:data {{
457
- ?iri oldap:grantsPermission ?permset .
449
+ {self._iri.toRdf} oldap:grantsPermission ?permset .
458
450
  }}
459
- BIND({self._con.userIri.toRdf} as ?user)
460
451
  GRAPH oldap:admin {{
461
- ?user oldap:hasPermissions ?permset .
452
+ {self._con.userIri.toRdf} oldap:hasPermissions ?permset .
462
453
  ?permset oldap:givesPermission ?DataPermission .
463
454
  ?DataPermission oldap:permissionValue ?permval .
464
455
  }}
465
456
  FILTER(?permval >= {permission.numeric.toRdf})
466
457
  }}'''
458
+
467
459
  if self._con.in_transaction():
468
- jsonobj = self._con.transaction_query(permission_query)
460
+ result = self._con.transaction_query(permission_query)
469
461
  else:
470
- jsonobj = self._con.query(permission_query)
471
- res = QueryProcessor(context, jsonobj)
472
- return res[0]['numOfPermsets'] > 0
462
+ result = self._con.query(permission_query)
463
+ return result['boolean']
473
464
 
474
465
  def create(self, indent: int = 0, indent_inc: int = 4) -> str:
475
466
  result, message = self.check_for_permissions(AdminPermission.ADMIN_CREATE)
@@ -707,12 +698,13 @@ class ResourceInstance:
707
698
 
708
699
  context = Context(name=self._con.context_name)
709
700
  inuse = context.sparql_context
710
- inuse = f'''
711
- SELECT (COUNT(?res) as ?nres)
712
- WHERE {{
713
- ?res ?prop {self._iri.toRdf} .
701
+ inuse += f"""
702
+ ASK {{
703
+ GRAPH ?g {{
704
+ ?res ?prop {self._iri.toRdf} .
705
+ }}
714
706
  }}
715
- '''
707
+ """
716
708
 
717
709
  context = Context(name=self._con.context_name)
718
710
  sparql = context.sparql_context
@@ -730,9 +722,8 @@ class ResourceInstance:
730
722
  self._con.transaction_abort()
731
723
  raise OldapErrorNoPermission(f'No permission to update resource "{self._iri}"')
732
724
  try:
733
- jsonobj = self._con.transaction_query(inuse)
734
- res = QueryProcessor(context, jsonobj)
735
- if res[0]['nres'] > 0:
725
+ result = self._con.transaction_query(inuse)
726
+ if result['boolean']:
736
727
  raise OldapErrorInUse(f'Resource "{self._iri}" is in use and cannot be deleted.')
737
728
  except OldapError:
738
729
  self._con.transaction_abort()
@@ -791,9 +782,6 @@ class ResourceInstanceFactory:
791
782
 
792
783
  self._datamodel = DataModel.read(con=self._con, project=self._project, ignore_cache=True)
793
784
 
794
- #self._oldap_project = Project.read(self._con, "oldap")
795
- #self._oldap_datamodel = DataModel.read(con=self._con, project=self._oldap_project)
796
-
797
785
  def createObjectInstance(self, name: Xsd_NCName | str) -> Type: ## ToDo: Get name automatically from IRI
798
786
  classiri = Xsd_QName(self._project.projectShortName, name)
799
787
  resclass = self._datamodel.get(classiri)
@@ -849,7 +837,6 @@ class ResourceInstanceFactory:
849
837
  raise OldapErrorNotFound(f'Resource with iri <{iri}> not found.')
850
838
  return data
851
839
 
852
-
853
840
  def read(self, iri: Iri | str) -> ResourceInstance:
854
841
  if not isinstance(iri, Iri):
855
842
  iri = Iri(iri, validate=True)
@@ -901,9 +888,18 @@ class ResourceInstanceFactory:
901
888
  Instance = self.createObjectInstance(objtype)
902
889
  return Instance(iri=iri, **kwargs)
903
890
 
904
- def search_fulltext(self, s: str, count_only: bool = False, limit: int = 100, offset: int = 0) -> int | dict[Iri, dict[str, Xsd]]:
905
- graph = self._project.projectShortName
906
- context = Context(name=self._con.context_name)
891
+ @staticmethod
892
+ def search_fulltext(con: IConnection,
893
+ projectShortName: Xsd_NCName | str,
894
+ s: str,
895
+ count_only: bool = False,
896
+ limit: int = 100,
897
+ offset: int = 0) -> int | dict[Iri, dict[str, Xsd]]:
898
+ if not isinstance(projectShortName, Xsd_NCName):
899
+ graph = Xsd_NCName(projectShortName)
900
+ else:
901
+ graph = projectShortName
902
+ context = Context(name=con.context_name)
907
903
  sparql = context.sparql_context
908
904
  if (count_only):
909
905
  sparql += "SELECT (COUNT(DISTINCT ?s) as ?numResult)"
@@ -920,7 +916,7 @@ class ResourceInstanceFactory:
920
916
  (datatype(?o) = xsd:string || datatype(?o) = rdf:langString || lang(?o) != ""))
921
917
  FILTER(CONTAINS(LCASE(STR(?o)), "{s}")) # case-insensitive substring match
922
918
  GRAPH oldap:admin {{
923
- {self._con.userIri.toRdf} oldap:hasPermissions ?permset .
919
+ {con.userIri.toRdf} oldap:hasPermissions ?permset .
924
920
  ?permset oldap:givesPermission ?DataPermission .
925
921
  ?DataPermission oldap:permissionValue ?permval .
926
922
  }}
@@ -929,21 +925,31 @@ class ResourceInstanceFactory:
929
925
  '''
930
926
  if not count_only:
931
927
  sparql += f'LIMIT {limit} OFFSET {offset}'
932
- jsonres = self._con.query(sparql)
928
+ try:
929
+ jsonres = con.query(sparql)
930
+ except OldapError:
931
+ print(sparql)
932
+ raise
933
933
  res = QueryProcessor(context, jsonres)
934
934
  if count_only:
935
- if isinstance(res[0]['numResult'], Xsd_integer):
936
- tmp = cast(Xsd_integer, res[0]['numResult'])
937
- return int(tmp)
938
- else:
939
- raise OldapErrorInconsistency(f'Expected integer as value, got "{res[0]["numResult"]}"')
935
+ return res[0]['numResult']
940
936
  else:
941
- result: dict[Iri, dict[str, Xsd]] = {}
942
- for r in res:
943
- iri = cast(Iri, r['s'])
944
- resclass = cast(Iri, r['t'])
945
- result[iri] = {'resclass': resclass, 'property': r['p'], 'value': r['o']}
946
- return result
937
+ return {Iri(r['s']): {r['p']: r['o']} for r in res}
938
+ # jsonres = con.query(sparql)
939
+ # res = QueryProcessor(context, jsonres)
940
+ # if count_only:
941
+ # if isinstance(res[0]['numResult'], Xsd_integer):
942
+ # tmp = cast(Xsd_integer, res[0]['numResult'])
943
+ # return int(tmp)
944
+ # else:
945
+ # raise OldapErrorInconsistency(f'Expected integer as value, got "{res[0]["numResult"]}"')
946
+ # else:
947
+ # result: dict[Iri, dict[str, Xsd]] = {}
948
+ # for r in res:
949
+ # iri = cast(Iri, r['s'])
950
+ # resclass = cast(Iri, r['t'])
951
+ # result[iri] = {'resclass': resclass, 'property': r['p'], 'value': r['o']}
952
+ # return result
947
953
 
948
954
 
949
955
 
oldaplib/src/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.8"
1
+ __version__ = "0.3.10"
@@ -645,7 +645,9 @@ class TestObjectFactory(unittest.TestCase):
645
645
  pubDate="1995-09-27",
646
646
  grantsPermission=Iri('oldap:GenericView'))
647
647
  b.create()
648
- res = factory.search_fulltext('tales')
648
+ res = ResourceInstanceFactory.search_fulltext(con=self._connection,
649
+ projectShortName='test',
650
+ s='tales')
649
651
 
650
652
  for x, y in res.items():
651
653
  print(x, y)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: oldaplib
3
- Version: 0.3.8
3
+ Version: 0.3.10
4
4
  Summary: Open Media Access Server Library (Linked Open Data middleware/RESTApi)
5
5
  License: GNU Affero General Public License version 3
6
6
  Author: Lukas Rosenthaler
@@ -48,7 +48,7 @@ oldaplib/src/helpers/json_encoder.py,sha256=c78h9uf58zfLaK8X7S1KCK4otY3iEltGnPBy
48
48
  oldaplib/src/helpers/langstring.py,sha256=KfyYisMKEYstv-CUPlKkjMg9fbTjrOV3IDn2HOUfdtY,30350
49
49
  oldaplib/src/helpers/numeric.py,sha256=swRKU51zbwss9UDGTC6FzhTTPK_BVfy5On0KCK-zZnQ,966
50
50
  oldaplib/src/helpers/observable_dict.py,sha256=w_I4fG8tKBibimcmSxeKgvDF-zy2aHSBUluXIBeNCHE,3287
51
- oldaplib/src/helpers/observable_set.py,sha256=xB7PB1ko5mA2-sQqwvAUA_xAuT-RGAcwjF1B5Gw0g_4,13966
51
+ oldaplib/src/helpers/observable_set.py,sha256=IWkcgMBh5P-J3TkLijyaLmvxLqmAPdp-ayNkJKD_qf0,14427
52
52
  oldaplib/src/helpers/oldaperror.py,sha256=2gKgV8FYiEjbcox1KN1PlOIPY4KclxVTnCIOQ6Ivvc0,1321
53
53
  oldaplib/src/helpers/query_processor.py,sha256=1RJnQ9u6BS58xK0PcTbffzF2W-_K42kw37Vbh2HO5sA,10369
54
54
  oldaplib/src/helpers/semantic_version.py,sha256=HLFQO2CPVDz_GKZaFCjR5q_G-aSLQ2XYohCA2tCU9go,3218
@@ -59,7 +59,7 @@ oldaplib/src/helpers/tools.py,sha256=sNbiOLucTGNFzZmiWwPLFOb80VTXQH0Zd9uCGubhzAk
59
59
  oldaplib/src/iconnection.py,sha256=XlOc2Kh4tK_UOHydLQwlWjUFLUze-Aq_vEZpf9KS1-s,3677
60
60
  oldaplib/src/in_project.py,sha256=2KuhHPj8DNveFRBeImrRfxlCOYhBK-mcxXYUp6s--j8,10672
61
61
  oldaplib/src/model.py,sha256=VACR3T6zJYFaE5J1PFFdP0OSwhbu4sahoLMWg6_L_rE,19267
62
- oldaplib/src/objectfactory.py,sha256=JaIDrdOiprLxhJkgCnrUtcp9UdKcHrHPQBG8cBWqvrg,47027
62
+ oldaplib/src/objectfactory.py,sha256=RIKm45-fApX1--fW_G5NzDzdnoCbW08e4Sb2fgufViI,47088
63
63
  oldaplib/src/oldaplist.py,sha256=sGAvEEJukRCjM70G0NFaR-L9YPleQTOtdWGExj3oYL8,42933
64
64
  oldaplib/src/oldaplist_helpers.py,sha256=1Gur0nS1PCKb9iUtCKPUFDOYjw6vvAwYpe-G3DdxlEc,14213
65
65
  oldaplib/src/oldaplistnode.py,sha256=NnC2juEGTtEkDO6OlB9PjSw_zTF-wSsRUgEk-6VV9DA,87344
@@ -70,7 +70,7 @@ oldaplib/src/propertyclass.py,sha256=pnaDsmyGKQnJaaOHXA0XyLcp4zn1b1vC9sLbjXls4lM
70
70
  oldaplib/src/resourceclass.py,sha256=EIxyd7Z_w59wDxWLXCaLvhhvh5SjLEUWb8gqmZz8LLM,102046
71
71
  oldaplib/src/user.py,sha256=Z4GXPRkaHXx3glUpPXQdFqYMxQPOuqayDwkTAE5RGjU,48820
72
72
  oldaplib/src/userdataclass.py,sha256=FbZkcRt0pKbOeqsZ7HbpwoKE-XPWH2AqpHG1GcsrBPo,12364
73
- oldaplib/src/version.py,sha256=kd0YV9qLZ1Lpx7vbSzAMrAwjgdZJD_tInTnDqY6-nTY,21
73
+ oldaplib/src/version.py,sha256=88sMV1NYWroy2-572uHnugaP-FYZbIQpcERC-gtfC5s,22
74
74
  oldaplib/src/xsd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
75
75
  oldaplib/src/xsd/floatingpoint.py,sha256=rDReKqh0mXyc4F5wslgTUxbeGf3-PGERyughj5_62YI,8852
76
76
  oldaplib/src/xsd/iri.py,sha256=w1Dr0z-REi7yPe3GPGnyzGrLVMvLY03kEeK-AmZ9sxw,8383
@@ -126,7 +126,7 @@ oldaplib/test/test_hasproperty.py,sha256=r991g8kBTfv1CGs9Hf0fli-AUp7Ob7rOHWYD74h
126
126
  oldaplib/test/test_in_project.py,sha256=DYT-guwRQ9crnfEt7cQZxoEMxThin7QeymNce3jaZx4,7779
127
127
  oldaplib/test/test_langstring.py,sha256=37BeKiQzj63G-SyS_paK_SEG7ulRbGrE89Mz40UB_bE,15146
128
128
  oldaplib/test/test_language_in.py,sha256=ELqHO-YIsZSCPF3E3rWde4J7rERL7En7sV_pzQ00zgs,8826
129
- oldaplib/test/test_objectfactory.py,sha256=IrU714mcpI2rterqauYA0XC_wKZdQSNrLAosCvrYo7M,34440
129
+ oldaplib/test/test_objectfactory.py,sha256=J9EIu7Ln-G-vzNhvFGKw-mnhXug1EVWs_20petgPoB4,34613
130
130
  oldaplib/test/test_observable_dict.py,sha256=GxD0sM0nsVfVRBu92SFGkJ6--YXq4ibBWI4IpjZZzDU,1396
131
131
  oldaplib/test/test_observable_set.py,sha256=JWZSoAsr8XIEBXPVgSVJjQQEEc8uSAme5IrFYLYVVXw,6313
132
132
  oldaplib/test/test_oldaplist.py,sha256=9wo3tEOHt5bIuXyvSSyTzjhtdKrQHiiAA6EfVBuq4wI,20114
@@ -157,6 +157,6 @@ oldaplib/testdata/source_type.yaml,sha256=dSihKikw3O-IlGf6anj5KWMoBYLaweLVF1Zojm
157
157
  oldaplib/testdata/test_move_left_of_toL.yaml,sha256=2m1OSQrQFlsCQxeJrjzBAO74LMprNDo_HuyrYGsOeXI,787
158
158
  oldaplib/testdata/testlist.yaml,sha256=AT11nXEG81Sfyb-tr1gQV0H_dZBrOCcFuHf7YtL8P2g,1994
159
159
  oldaplib/testit.http,sha256=qW7mnr6aNLXFG6lQdLgyhXILOPN6qc5iFVZclLyVvkY,303
160
- oldaplib-0.3.8.dist-info/METADATA,sha256=N4D0KOzlouWjyXz5ooC6ld_LhEblkrJNVfuSwwqPTMA,2854
161
- oldaplib-0.3.8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
162
- oldaplib-0.3.8.dist-info/RECORD,,
160
+ oldaplib-0.3.10.dist-info/METADATA,sha256=l6lpn1epR1VxIa_BuW-Tu3DMD4GkMjw08gxRW4RUepk,2855
161
+ oldaplib-0.3.10.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
162
+ oldaplib-0.3.10.dist-info/RECORD,,