Code Duplication    Length = 31-38 lines in 17 locations

crabpy/gateway/capakey.py 1 location

@@ 241-278 (lines=38) @@
238
        afdeling.set_gateway(self)
239
        return afdeling
240
241
    @deprecate(DEPRECATIONWARNING.format('.list_secties_by_afdeling'))
242
    def list_secties_by_afdeling(self, afdeling):
243
        '''
244
        List all `secties` in a `kadastrale afdeling`.
245
246
        :param afdeling: The :class:`Afdeling` for which the `secties` are \
247
            wanted. Can also be the id of and `afdeling`.
248
        :rtype: A :class:`list` of `Sectie`.
249
        '''
250
        try:
251
            aid = afdeling.id
252
        except AttributeError:
253
            aid = afdeling
254
            afdeling = self.get_kadastrale_afdeling_by_id(aid)
255
        afdeling.clear_gateway()
256
257
        def creator():
258
            res = capakey_gateway_request(
259
                self.client, 'ListKadSectiesByKadAfdelingcode', aid
260
            )
261
            try:
262
                return [
263
                    Sectie(
264
                        r.KadSectiecode,
265
                        afdeling
266
                    ) for r in res.KadSectieItem
267
                ]
268
            except AttributeError:
269
                # Handle bad error handling on the CAPAKEY side
270
                return []
271
        if self.caches['long'].is_configured:
272
            key = 'ListKadSectiesByKadAfdelingcode#%s' % aid
273
            secties = self.caches['long'].get_or_create(key, creator)
274
        else:
275
            secties = creator()
276
        for s in secties:
277
            s.set_gateway(self)
278
        return secties
279
280
    @deprecate(DEPRECATIONWARNING.format('.get_sectie_by_id_and_afdeling'))
281
    def get_sectie_by_id_and_afdeling(self, id, afdeling):

crabpy/gateway/crab.py 16 locations

@@ 728-764 (lines=37) @@
725
            h.set_gateway(self)
726
        return huisnummers
727
728
    def list_huisnummers_by_perceel(self, perceel, sort=1):
729
        '''
730
        List all `huisnummers` on a `Pereel`.
731
732
        Generally there will only be one, but multiples are possible.
733
734
        :param perceel: The :class:`Perceel` for which the \
735
            `huisnummers` are wanted.
736
        :rtype: A :class: `list` of :class:`Huisnummer`
737
        '''
738
        try:
739
            id = perceel.id
740
        except AttributeError:
741
            id = perceel
742
743
        def creator():
744
            res = crab_gateway_request(
745
                self.client, 'ListHuisnummersWithStatusByIdentificatorPerceel',
746
                id, sort
747
            )
748
            try:
749
                huisnummers= []
750
                for r in res.HuisnummerWithStatusItem:
751
                    h = self.get_huisnummer_by_id(r.HuisnummerId)
752
                    h.clear_gateway()
753
                    huisnummers.append(h)
754
                return huisnummers
755
            except AttributeError:
756
                return []
757
        if self.caches['short'].is_configured:
758
            key = 'ListHuisnummersWithStatusByIdentificatorPerceel#%s%s' % (id, sort)
759
            huisnummers = self.caches['short'].get_or_create(key, creator)
760
        else:
761
            huisnummers = creator()
762
        for h in huisnummers:
763
            h.set_gateway(self)
764
        return huisnummers
765
766
    def get_huisnummer_by_id(self, id):
767
        '''
@@ 690-726 (lines=37) @@
687
        straat.set_gateway(self)
688
        return straat
689
690
    def list_huisnummers_by_straat(self, straat, sort=1):
691
        '''
692
        List all `huisnummers` in a `Straat`.
693
694
        :param straat: The :class:`Straat` for which the \
695
            `huisnummers` are wanted.
696
        :rtype: A :class: `list` of :class:`Huisnummer`
697
        '''
698
        try:
699
            id = straat.id
700
        except AttributeError:
701
            id = straat
702
703
        def creator():
704
            res = crab_gateway_request(
705
                self.client, 'ListHuisnummersWithStatusByStraatnaamId',
706
                id, sort
707
            )
708
            try:
709
                return[
710
                    Huisnummer(
711
                        r.HuisnummerId,
712
                        r.StatusHuisnummer,
713
                        r.Huisnummer,
714
                        id
715
                    ) for r in res.HuisnummerWithStatusItem
716
                ]
717
            except AttributeError:
718
                return []
719
        if self.caches['short'].is_configured:
720
            key = 'ListHuisnummersWithStatusByStraatnaamId#%s%s' % (id, sort)
721
            huisnummers = self.caches['short'].get_or_create(key, creator)
722
        else:
723
            huisnummers = creator()
724
        for h in huisnummers:
725
            h.set_gateway(self)
726
        return huisnummers
727
728
    def list_huisnummers_by_perceel(self, perceel, sort=1):
729
        '''
@@ 614-650 (lines=37) @@
611
            'ListHerkomstAdresposities', sort, 'Herkomstadrespositie'
612
        )
613
614
    def list_straten(self, gemeente, sort=1):
615
        '''
616
        List all `straten` in a `Gemeente`.
617
618
        :param gemeente: The :class:`Gemeente` for which the \
619
            `straten` are wanted.
620
        :rtype: A :class:`list` of :class:`Straat`
621
        '''
622
        try:
623
            id = gemeente.id
624
        except AttributeError:
625
            id = gemeente
626
627
        def creator():
628
            res = crab_gateway_request(
629
                self.client, 'ListStraatnamenWithStatusByGemeenteId',
630
                id, sort
631
            )
632
            try:
633
                return[
634
                    Straat(
635
                        r.StraatnaamId,
636
                        r.StraatnaamLabel,
637
                        id,
638
                        r.StatusStraatnaam
639
                    )for r in res.StraatnaamWithStatusItem
640
                ]
641
            except AttributeError:
642
                return []
643
        if self.caches['long'].is_configured:
644
            key = 'ListStraatnamenWithStatusByGemeenteId#%s%s' % (id, sort)
645
            straten = self.caches['long'].get_or_create(key, creator)
646
        else:
647
            straten = creator()
648
        for s in straten:
649
            s.set_gateway(self)
650
        return straten
651
652
    def get_straat_by_id(self, id):
653
        '''
@@ 249-284 (lines=36) @@
246
            g.set_gateway(self)
247
        return gemeente
248
249
    def list_gemeenten(self, gewest=2, sort=1):
250
        '''
251
        List all `gemeenten` in a `gewest`.
252
253
        :param gewest: The :class:`Gewest` for which the \
254
            `gemeenten` are wanted.
255
        :param integer sort: What field to sort on.
256
        :rtype: A :class:`list` of :class:`Gemeente`.
257
        '''
258
        try:
259
            gewest_id = gewest.id
260
        except AttributeError:
261
            gewest_id = gewest
262
            gewest = self.get_gewest_by_id(gewest_id)
263
        gewest.clear_gateway()
264
265
        def creator():
266
            res = crab_gateway_request(
267
                self.client, 'ListGemeentenByGewestId', gewest_id, sort
268
            )
269
            return[
270
                Gemeente(
271
                    r.GemeenteId,
272
                    r.GemeenteNaam,
273
                    r.NISGemeenteCode,
274
                    gewest
275
                )for r in res.GemeenteItem if r.TaalCode == r.TaalCodeGemeenteNaam
276
            ]
277
        if self.caches['permanent'].is_configured:
278
            key = 'ListGemeentenByGewestId#%s#%s' % (gewest_id, sort)
279
            gemeenten = self.caches['permanent'].get_or_create(key, creator)
280
        else:
281
            gemeenten = creator()
282
        for g in gemeenten:
283
            g.set_gateway(self)
284
        return gemeenten
285
286
    def get_gemeente_by_id(self, id):
287
        '''
@@ 1175-1209 (lines=35) @@
1172
        perceel.set_gateway(self)
1173
        return perceel
1174
1175
    def list_gebouwen_by_huisnummer(self, huisnummer):
1176
        '''
1177
        List all `gebouwen` for a :class:`Huisnummer`.
1178
1179
        :param huisnummer: The :class:`Huisnummer` for which the \
1180
            `gebouwen` are wanted.
1181
        :rtype: A :class:`list` of :class:`Gebouw`
1182
        '''
1183
        try:
1184
            id = huisnummer.id
1185
        except AttributeError:
1186
            id = huisnummer
1187
1188
        def creator():
1189
            res = crab_gateway_request(
1190
                self.client, 'ListGebouwenByHuisnummerId', id
1191
            )
1192
            try:
1193
                return [
1194
                    Gebouw(
1195
                        r.IdentificatorGebouw,
1196
                        r.AardGebouw,
1197
                        r.StatusGebouw
1198
                    )for r in res.GebouwItem
1199
                ]
1200
            except AttributeError:
1201
                return []
1202
        if self.caches['short'].is_configured:
1203
            key = 'ListGebouwenByHuisnummerId#%s' % (id)
1204
            gebouwen = self.caches['short'].get_or_create(key, creator)
1205
        else:
1206
            gebouwen = creator()
1207
        for r in gebouwen:
1208
            r.set_gateway(self)
1209
        return gebouwen
1210
1211
    def get_gebouw_by_id(self, id):
1212
        '''
@@ 213-247 (lines=35) @@
210
        provincie.set_gateway(self)
211
        return provincie
212
213
    def list_gemeenten_by_provincie(self, provincie):
214
        '''
215
        List all `gemeenten` in a `provincie`.
216
217
        :param provincie: The :class:`Provincie` for which the \
218
            `gemeenten` are wanted.
219
        :rtype: A :class:`list` of :class:`Gemeente`.
220
        '''
221
        try:
222
            gewest = provincie.gewest
223
            prov = provincie
224
        except AttributeError:
225
            prov = self.get_provincie_by_id(provincie)
226
            gewest = prov.gewest
227
        gewest.clear_gateway()
228
229
        def creator():
230
            gewest_gemeenten = self.list_gemeenten(gewest.id)
231
            return[
232
                Gemeente(
233
                    r.id,
234
                    r.naam,
235
                    r.niscode,
236
                    gewest
237
                )for r in gewest_gemeenten if str(r.niscode)[0] == str(prov.niscode)[0]
238
            ]
239
240
        if self.caches['permanent'].is_configured:
241
            key = 'ListGemeentenByProvincieId#%s' % prov.id
242
            gemeente = self.caches['long'].get_or_create(key, creator)
243
        else:
244
            gemeente = creator()
245
        for g in gemeente:
246
            g.set_gateway(self)
247
        return gemeente
248
249
    def list_gemeenten(self, gewest=2, sort=1):
250
        '''
@@ 1041-1074 (lines=34) @@
1038
            r.set_gateway(self)
1039
        return wegsegmenten
1040
1041
    def list_terreinobjecten_by_huisnummer(self, huisnummer):
1042
        '''
1043
        List all `terreinobjecten` for a :class:`Huisnummer`
1044
1045
        :param huisnummer: The :class:`Huisnummer` for which the \
1046
            `terreinobjecten` are wanted.
1047
        :rtype: A :class:`list` of :class:`Terreinobject`
1048
        '''
1049
        try:
1050
            id = huisnummer.id
1051
        except AttributeError:
1052
            id = huisnummer
1053
1054
        def creator():
1055
            res = crab_gateway_request(
1056
                self.client, 'ListTerreinobjectenByHuisnummerId', id
1057
            )
1058
            try:
1059
                return[
1060
                    Terreinobject(
1061
                        r.IdentificatorTerreinobject,
1062
                        r.AardTerreinobject
1063
                    )for r in res.TerreinobjectItem
1064
                ]
1065
            except AttributeError:
1066
                return []
1067
        if self.caches['short'].is_configured:
1068
            key = 'ListTerreinobjectenByHuisnummerId#%s' % (id)
1069
            terreinobjecten = self.caches['short'].get_or_create(key, creator)
1070
        else:
1071
            terreinobjecten = creator()
1072
        for r in terreinobjecten:
1073
            r.set_gateway(self)
1074
        return terreinobjecten
1075
1076
    def get_terreinobject_by_id(self, id):
1077
        '''
@@ 1006-1039 (lines=34) @@
1003
        wegsegment.set_gateway(self)
1004
        return wegsegment
1005
1006
    def list_wegsegmenten_by_straat(self, straat):
1007
        '''
1008
        List all `wegsegmenten` in a :class:`Straat`
1009
1010
        :param straat: The :class:`Straat` for which the `wegsegmenten` \
1011
                are wanted.
1012
        :rtype: A :class:`list` of :class:`Wegsegment`
1013
        '''
1014
        try:
1015
            id = straat.id
1016
        except AttributeError:
1017
            id = straat
1018
1019
        def creator():
1020
            res = crab_gateway_request(
1021
                self.client, 'ListWegsegmentenByStraatnaamId', id
1022
            )
1023
            try:
1024
                return[
1025
                    Wegsegment(
1026
                        r.IdentificatorWegsegment,
1027
                        r.StatusWegsegment
1028
                    )for r in res.WegsegmentItem
1029
                ]
1030
            except AttributeError:
1031
                return []
1032
        if self.caches['short'].is_configured:
1033
            key = 'ListWegsegmentenByStraatnaamId#%s' % (id)
1034
            wegsegmenten = self.caches['short'].get_or_create(key, creator)
1035
        else:
1036
            wegsegmenten = creator()
1037
        for r in wegsegmenten:
1038
            r.set_gateway(self)
1039
        return wegsegmenten
1040
1041
    def list_terreinobjecten_by_huisnummer(self, huisnummer):
1042
        '''
@@ 937-970 (lines=34) @@
934
        wegobject.set_gateway(self)
935
        return wegobject
936
937
    def list_wegobjecten_by_straat(self, straat):
938
        '''
939
        List all `wegobjecten` in a :class:`Straat`
940
941
        :param straat: The :class:`Straat` for which the `wegobjecten` \
942
                are wanted.
943
        :rtype: A :class:`list` of :class:`Wegobject`
944
        '''
945
        try:
946
            id = straat.id
947
        except AttributeError:
948
            id = straat
949
950
        def creator():
951
            res = crab_gateway_request(
952
                self.client, 'ListWegobjectenByStraatnaamId', id
953
            )
954
            try:
955
                return [
956
                    Wegobject(
957
                        r.IdentificatorWegobject,
958
                        r.AardWegobject
959
                    )for r in res.WegobjectItem
960
                ]
961
            except AttributeError:
962
                return []
963
        if self.caches['short'].is_configured:
964
            key = 'ListWegobjectenByStraatnaamId#%s' % (id)
965
            wegobjecten = self.caches['short'].get_or_create(key, creator)
966
        else:
967
            wegobjecten = creator()
968
        for r in wegobjecten:
969
            r.set_gateway(self)
970
        return wegobjecten
971
972
    def get_wegsegment_by_id(self, id):
973
        '''
@@ 1257-1289 (lines=33) @@
1254
            if int(item.id) == int(res):
1255
                return item
1256
1257
    def list_subadressen_by_huisnummer(self, huisnummer):
1258
        '''
1259
        List all `subadressen` for a :class:`Huisnummer`.
1260
1261
        :param huisnummer: The :class:`Huisnummer` for which the \
1262
            `subadressen` are wanted. OR A huisnummer id.
1263
        :rtype: A :class:`list` of :class:`Gebouw`
1264
        '''
1265
        try:
1266
            id = huisnummer.id
1267
        except AttributeError:
1268
            id = huisnummer
1269
1270
        def creator():
1271
            res = crab_gateway_request(
1272
                self.client, 'ListSubadressenWithStatusByHuisnummerId', id
1273
            )
1274
            try:
1275
                return [ Subadres(
1276
                    r.SubadresId,
1277
                    r.Subadres,
1278
                    r.StatusSubadres
1279
                )for r in res.SubadresWithStatusItem ]
1280
            except AttributeError:
1281
                return []
1282
        if self.caches['short'].is_configured:
1283
            key = 'ListSubadressenWithStatusByHuisnummerId#%s' % (id)
1284
            subadressen = self.caches['short'].get_or_create(key, creator)
1285
        else:
1286
            subadressen = creator()
1287
        for s in subadressen:
1288
            s.set_gateway(self)
1289
        return subadressen
1290
1291
    def get_subadres_by_id(self, id):
1292
        '''
@@ 1110-1142 (lines=33) @@
1107
        terreinobject.set_gateway(self)
1108
        return terreinobject
1109
1110
    def list_percelen_by_huisnummer(self, huisnummer):
1111
        '''
1112
        List all `percelen` for a :class:`Huisnummer`
1113
1114
        :param huisnummer: The :class:`Huisnummer` for which the \
1115
            `percelen` are wanted.
1116
        :rtype: A :class:`list` of :class:`Perceel`
1117
        '''
1118
        try:
1119
            id = huisnummer.id
1120
        except AttributeError:
1121
            id = huisnummer
1122
1123
        def creator():
1124
            res = crab_gateway_request(
1125
                self.client, 'ListPercelenByHuisnummerId', id
1126
            )
1127
            try:
1128
                return [
1129
                    Perceel(
1130
                        r.IdentificatorPerceel
1131
                    )for r in res.PerceelItem
1132
                ]
1133
            except AttributeError:
1134
                return []
1135
        if self.caches['short'].is_configured:
1136
            key = 'ListPercelenByHuisnummerId#%s' % (id)
1137
            percelen = self.caches['short'].get_or_create(key, creator)
1138
        else:
1139
            percelen = creator()
1140
        for r in percelen:
1141
            r.set_gateway(self)
1142
        return percelen
1143
1144
    def get_perceel_by_id(self, id):
1145
        '''
@@ 840-872 (lines=33) @@
837
        huisnummer.set_gateway(self)
838
        return huisnummer
839
840
    def list_postkantons_by_gemeente(self, gemeente):
841
        '''
842
        List all `postkantons` in a :class:`Gemeente`
843
844
        :param gemeente: The :class:`Gemeente` for which the \
845
            `potkantons` are wanted.
846
        :rtype: A :class:`list` of :class:`Postkanton`
847
        '''
848
        try:
849
            id = gemeente.id
850
        except AttributeError:
851
            id = gemeente
852
853
        def creator():
854
            res = crab_gateway_request(
855
                self.client, 'ListPostkantonsByGemeenteId', id
856
            )
857
            try:
858
                return[
859
                    Postkanton(
860
                        r.PostkantonCode
861
                    )for r in res.PostkantonItem
862
                ]
863
            except AttributeError:
864
                return []
865
        if self.caches['long'].is_configured:
866
            key = 'ListPostkantonsByGemeenteId#%s' % (id)
867
            postkantons = self.caches['long'].get_or_create(key, creator)
868
        else:
869
            postkantons = creator()
870
        for r in postkantons:
871
            r.set_gateway(self)
872
        return postkantons
873
874
    def get_postkanton_by_huisnummer(self, huisnummer):
875
        '''
@@ 1422-1453 (lines=32) @@
1419
            a.set_gateway(self)
1420
        return adresposities
1421
1422
    def list_adresposities_by_subadres_and_huisnummer(self, subadres, huisnummer):
1423
        '''
1424
        List all `adresposities` for a subadres and a :class:`Huisnummer`.
1425
1426
        :param subadres: A string representing a certain subadres.
1427
        :param huisnummer: The :class:`Huisnummer` for which the \
1428
            `adresposities` are wanted. OR A huisnummer id.
1429
        :rtype: A :class:`list` of :class:`Adrespositie`
1430
        '''
1431
        try:
1432
            hid = huisnummer.id
1433
        except AttributeError:
1434
            hid = huisnummer
1435
        def creator():
1436
            res = crab_gateway_request(
1437
                self.client, 'ListAdrespositiesBySubadres', subadres, hid
1438
            )
1439
            try:
1440
                return [Adrespositie(
1441
                    r.AdrespositieId,
1442
                    r.HerkomstAdrespositie
1443
                )for r in res.AdrespositieItem]
1444
            except AttributeError:
1445
                return []
1446
        if self.caches['short'].is_configured:
1447
            key = 'ListAdrespositiesBySubadres#%s%s' % (subadres, hid)
1448
            adresposities = self.caches['short'].get_or_create(key, creator)
1449
        else:
1450
            adresposities = creator()
1451
        for a in adresposities:
1452
            a.set_gateway(self)
1453
        return adresposities
1454
1455
    def get_adrespositie_by_id(self, id):
1456
        '''
@@ 1357-1388 (lines=32) @@
1354
            a.set_gateway(self)
1355
        return adresposities
1356
1357
    def list_adresposities_by_nummer_and_straat(self, nummer, straat):
1358
        '''
1359
        List all `adresposities` for a huisnummer and a :class:`Straat`.
1360
1361
        :param nummer: A string representing a certain huisnummer.
1362
        :param straat: The :class:`Straat` for which the \
1363
            `adresposities` are wanted. OR A straat id.
1364
        :rtype: A :class:`list` of :class:`Adrespositie`
1365
        '''
1366
        try:
1367
            sid = straat.id
1368
        except AttributeError:
1369
            sid = straat
1370
        def creator():
1371
            res = crab_gateway_request(
1372
                self.client, 'ListAdrespositiesByHuisnummer', nummer, sid
1373
            )
1374
            try:
1375
                return [Adrespositie(
1376
                    r.AdrespositieId,
1377
                    r.HerkomstAdrespositie
1378
                )for r in res.AdrespositieItem]
1379
            except AttributeError:
1380
                return []
1381
        if self.caches['short'].is_configured:
1382
            key = 'ListAdrespositiesByHuisnummer#%s%s' % (nummer, sid)
1383
            adresposities = self.caches['short'].get_or_create(key, creator)
1384
        else:
1385
            adresposities = creator()
1386
        for a in adresposities:
1387
            a.set_gateway(self)
1388
        return adresposities
1389
1390
    def list_adresposities_by_subadres(self, subadres):
1391
        '''
@@ 1390-1420 (lines=31) @@
1387
            a.set_gateway(self)
1388
        return adresposities
1389
1390
    def list_adresposities_by_subadres(self, subadres):
1391
        '''
1392
        List all `adresposities` for a :class:`Subadres`.
1393
1394
        :param subadres: The :class:`Subadres` for which the \
1395
            `adresposities` are wanted. OR A subadres id.
1396
        :rtype: A :class:`list` of :class:`Adrespositie`
1397
        '''
1398
        try:
1399
            id = subadres.id
1400
        except AttributeError:
1401
            id = subadres
1402
        def creator():
1403
            res = crab_gateway_request(
1404
                self.client, 'ListAdrespositiesBySubadresId', id
1405
            )
1406
            try:
1407
                return [Adrespositie(
1408
                    r.AdrespositieId,
1409
                    r.HerkomstAdrespositie
1410
                )for r in res.AdrespositieItem]
1411
            except AttributeError:
1412
                return []
1413
        if self.caches['short'].is_configured:
1414
            key = 'ListAdrespositiesBySubadresId#%s' % (id)
1415
            adresposities = self.caches['short'].get_or_create(key, creator)
1416
        else:
1417
            adresposities = creator()
1418
        for a in adresposities:
1419
            a.set_gateway(self)
1420
        return adresposities
1421
1422
    def list_adresposities_by_subadres_and_huisnummer(self, subadres, huisnummer):
1423
        '''
@@ 1325-1355 (lines=31) @@
1322
        subadres.set_gateway(self)
1323
        return subadres
1324
1325
    def list_adresposities_by_huisnummer(self, huisnummer):
1326
        '''
1327
        List all `adresposities` for a :class:`Huisnummer`.
1328
1329
        :param huisnummer: The :class:`Huisnummer` for which the \
1330
            `adresposities` are wanted. OR A huisnummer id.
1331
        :rtype: A :class:`list` of :class:`Adrespositie`
1332
        '''
1333
        try:
1334
            id = huisnummer.id
1335
        except AttributeError:
1336
            id = huisnummer
1337
        def creator():
1338
            res = crab_gateway_request(
1339
                self.client, 'ListAdrespositiesByHuisnummerId', id
1340
            )
1341
            try:
1342
                return [Adrespositie(
1343
                    r.AdrespositieId,
1344
                    r.HerkomstAdrespositie
1345
                ) for r in res.AdrespositieItem]
1346
            except AttributeError:
1347
                return []
1348
        if self.caches['short'].is_configured:
1349
            key = 'ListAdrespositiesByHuisnummerId#%s' % (id)
1350
            adresposities = self.caches['short'].get_or_create(key, creator)
1351
        else:
1352
            adresposities = creator()
1353
        for a in adresposities:
1354
            a.set_gateway(self)
1355
        return adresposities
1356
1357
    def list_adresposities_by_nummer_and_straat(self, nummer, straat):
1358
        '''