File: OsmApi.py

package info (click to toggle)
python-osmapi 5.0.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 848 kB
  • sloc: python: 4,113; xml: 1,599; makefile: 46; sh: 14
file content (764 lines) | stat: -rw-r--r-- 28,464 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
"""
The OsmApi module is a wrapper for the OpenStreetMap API.
As such it provides an easy access to the functionality of the API.

You can find this module [on PyPI](https://pypi.python.org/pypi/osmapi)
or [on GitHub](https://github.com/metaodi/osmapi).

Find all information about changes of the different versions of this module
[in the CHANGELOG](https://github.com/metaodi/osmapi/blob/master/CHANGELOG.md).


## Notes:

* **dictionary keys** are _unicode_
* **changeset** is _integer_
* **version** is _integer_
* **tag** is a _dictionary_
* **timestamp** is _unicode_
* **user** is _unicode_
* **uid** is _integer_
* node **lat** and **lon** are _floats_
* way **nd** is list of _integers_
* relation **member** is a _list of dictionaries_ like
`{"role": "", "ref":123, "type": "node"}`
* Since version 5.0 of this library, all method names are in snake_case,
the CamelCase versions are deprecated and will be removed in version 6.0.
"""

import re
import logging
import warnings
from contextlib import contextmanager
from typing import Any, Optional, Generator
from xml.dom.minidom import Element
import requests

from osmapi import __version__
from . import errors
from . import http
from . import xmlbuilder
from .node import NodeMixin
from .way import WayMixin
from .relation import RelationMixin
from .changeset import ChangesetMixin
from .note import NoteMixin
from .capabilities import CapabilitiesMixin

logger = logging.getLogger(__name__)


class OsmApi(
    NodeMixin,
    WayMixin,
    RelationMixin,
    ChangesetMixin,
    NoteMixin,
    CapabilitiesMixin,
):
    """
    Main class of osmapi, instanciate this class to use osmapi
    """

    def __init__(
        self,
        username: Optional[str] = None,
        password: Optional[str] = None,
        passwordfile: Optional[str] = None,
        appid: str = "",
        created_by: str = f"osmapi/{__version__}",
        api: str = "https://www.openstreetmap.org",
        session: Optional[requests.Session] = None,
        timeout: int = 30,
    ) -> None:
        """
        Initialized the OsmApi object.

        There are two different ways to authenticate a user.
        Either `username` and `password` are supplied directly or the path
        to a `passwordfile` is given, where on the first line username
        and password must be colon-separated (<user>:<pass>).

        To credit the application that supplies changes to OSM, an `appid`
        can be provided.  This is a string identifying the application.
        If this is omitted "osmapi" is used.

        It is possible to configure the URL to connect to using the `api`
        parameter.  By default this is the SSL version of the production API
        of OpenStreetMap, for testing purposes, one might prefer the official
        test instance at "api06.dev.openstreetmap.org" or any other valid
        OSM-API. To use an encrypted connection (HTTPS) simply add 'https://'
        in front of the hostname of the `api` parameter (e.g.
        https://api.openstreetmap.com).

        The `session` parameter can be used to provide a custom requests
        http session object (requests.Session). This might be useful for
        OAuth authentication, custom adapters, hooks etc.

        Finally the `timeout` parameter is used by the http session to
        throw an expcetion if the the timeout (in seconds) has passed without
        an answer from the server.
        """
        # Get username
        self._username: Optional[str] = None
        if username:
            self._username = username
        elif passwordfile:
            with open(passwordfile) as f:
                pass_line = f.readline()
            self._username = pass_line.partition(":")[0].strip()

        # Get password
        self._password: Optional[str] = None
        if password:
            self._password = password
        elif passwordfile:
            with open(passwordfile) as f:
                for line in f:
                    key, _, value = line.strip().partition(":")
                    if key == self._username:
                        self._password = value

        # Get API
        self._api: str = api.strip("/")

        # Get created_by
        if not appid:
            self._created_by: str = created_by
        else:
            self._created_by = f"{appid} ({created_by})"

        # Initialisation
        self._current_changeset_id: int = 0

        # Http connection
        self.http_session: Optional[requests.Session] = session
        self._timeout: int = timeout
        auth: Optional[tuple[str, str]] = None
        if self._username and self._password:
            auth = (self._username, self._password)
        self._session: http.OsmApiSession = http.OsmApiSession(
            self._api,
            self._created_by,
            auth=auth,
            session=self.http_session,
            timeout=self._timeout,
        )

    def __enter__(self) -> "OsmApi":
        self._session = http.OsmApiSession(
            self._api,
            self._created_by,
            session=self.http_session,
            timeout=self._timeout,
        )
        return self

    def __exit__(self, *args: Any) -> None:
        self.close()

    def close(self) -> None:
        if self._session:
            self._session.close()

    ##################################################
    # Capabilities                                   #
    ##################################################

    def Capabilities(self) -> dict[str, dict[str, Any]]:
        """
        Returns the API capabilities as a dict.

        .. deprecated::
            Use :meth:`capabilities` instead.

        The capabilities can be used by a client to
        gain insights of the server in use.
        """
        warnings.warn(
            "Capabilities() is deprecated, use capabilities() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.capabilities()

    ##################################################
    # Node - Deprecated CamelCase methods           #
    ##################################################

    def NodeGet(self, NodeId: int, NodeVersion: int = -1) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`node_get` instead."""
        warnings.warn(
            "NodeGet() is deprecated, use node_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_get(NodeId, NodeVersion)

    def NodeCreate(self, NodeData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`node_create` instead."""
        warnings.warn(
            "NodeCreate() is deprecated, use node_create() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_create(NodeData)

    def NodeUpdate(self, NodeData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`node_update` instead."""
        warnings.warn(
            "NodeUpdate() is deprecated, use node_update() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_update(NodeData)

    def NodeDelete(self, NodeData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`node_delete` instead."""
        warnings.warn(
            "NodeDelete() is deprecated, use node_delete() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_delete(NodeData)

    def NodeHistory(self, NodeId: int) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`node_history` instead."""
        warnings.warn(
            "NodeHistory() is deprecated, use node_history() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_history(NodeId)

    def NodeWays(self, NodeId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`node_ways` instead."""
        warnings.warn(
            "NodeWays() is deprecated, use node_ways() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_ways(NodeId)

    def NodeRelations(self, NodeId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`node_relations` instead."""
        warnings.warn(
            "NodeRelations() is deprecated, use node_relations() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.node_relations(NodeId)

    def NodesGet(self, NodeIdList: list[int]) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`nodes_get` instead."""
        warnings.warn(
            "NodesGet() is deprecated, use nodes_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.nodes_get(NodeIdList)

    ##################################################
    # Way - Deprecated CamelCase methods            #
    ##################################################

    def WayGet(self, WayId: int, WayVersion: int = -1) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`way_get` instead."""
        warnings.warn(
            "WayGet() is deprecated, use way_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_get(WayId, WayVersion)

    def WayCreate(self, WayData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`way_create` instead."""
        warnings.warn(
            "WayCreate() is deprecated, use way_create() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_create(WayData)

    def WayUpdate(self, WayData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`way_update` instead."""
        warnings.warn(
            "WayUpdate() is deprecated, use way_update() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_update(WayData)

    def WayDelete(self, WayData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`way_delete` instead."""
        warnings.warn(
            "WayDelete() is deprecated, use way_delete() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_delete(WayData)

    def WayHistory(self, WayId: int) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`way_history` instead."""
        warnings.warn(
            "WayHistory() is deprecated, use way_history() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_history(WayId)

    def WayRelations(self, WayId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`way_relations` instead."""
        warnings.warn(
            "WayRelations() is deprecated, use way_relations() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_relations(WayId)

    def WayFull(self, WayId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`way_full` instead."""
        warnings.warn(
            "WayFull() is deprecated, use way_full() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.way_full(WayId)

    def WaysGet(self, WayIdList: list[int]) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`ways_get` instead."""
        warnings.warn(
            "WaysGet() is deprecated, use ways_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.ways_get(WayIdList)

    ##################################################
    # Relation - Deprecated CamelCase methods       #
    ##################################################

    def RelationGet(self, RelationId: int, RelationVersion: int = -1) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`relation_get` instead."""
        warnings.warn(
            "RelationGet() is deprecated, use relation_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_get(RelationId, RelationVersion)

    def RelationCreate(self, RelationData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_create` instead."""
        warnings.warn(
            "RelationCreate() is deprecated, use relation_create() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_create(RelationData)

    def RelationUpdate(self, RelationData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_update` instead."""
        warnings.warn(
            "RelationUpdate() is deprecated, use relation_update() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_update(RelationData)

    def RelationDelete(self, RelationData: dict[str, Any]) -> Optional[dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_delete` instead."""
        warnings.warn(
            "RelationDelete() is deprecated, use relation_delete() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_delete(RelationData)

    def RelationHistory(self, RelationId: int) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_history` instead."""
        warnings.warn(
            "RelationHistory() is deprecated, use relation_history() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_history(RelationId)

    def RelationRelations(self, RelationId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_relations` instead."""
        warnings.warn(
            "RelationRelations() is deprecated, use relation_relations() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_relations(RelationId)

    def RelationFullRecur(self, RelationId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_full_recur` instead."""
        warnings.warn(
            "RelationFullRecur() is deprecated, use relation_full_recur() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_full_recur(RelationId)

    def RelationFull(self, RelationId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`relation_full` instead."""
        warnings.warn(
            "RelationFull() is deprecated, use relation_full() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relation_full(RelationId)

    def RelationsGet(self, RelationIdList: list[int]) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`relations_get` instead."""
        warnings.warn(
            "RelationsGet() is deprecated, use relations_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.relations_get(RelationIdList)

    ##################################################
    # Changeset - Deprecated CamelCase methods      #
    ##################################################

    @contextmanager
    def Changeset(
        self, ChangesetTags: Optional[dict[str, str]] = None
    ) -> Generator[int, None, None]:
        """.. deprecated:: Use :meth:`changeset` instead."""
        warnings.warn(
            "Changeset() is deprecated, use changeset() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        with self.changeset(ChangesetTags) as changeset_id:
            yield changeset_id

    def ChangesetGet(
        self, ChangesetId: int, include_discussion: bool = False
    ) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`changeset_get` instead."""
        warnings.warn(
            "ChangesetGet() is deprecated, use changeset_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_get(ChangesetId, include_discussion)

    def ChangesetUpdate(self, ChangesetTags: Optional[dict[str, str]] = None) -> int:
        """.. deprecated:: Use :meth:`changeset_update` instead."""
        warnings.warn(
            "ChangesetUpdate() is deprecated, use changeset_update() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_update(ChangesetTags)

    def ChangesetCreate(self, ChangesetTags: Optional[dict[str, str]] = None) -> int:
        """.. deprecated:: Use :meth:`changeset_create` instead."""
        warnings.warn(
            "ChangesetCreate() is deprecated, use changeset_create() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_create(ChangesetTags)

    def ChangesetClose(self) -> int:
        """.. deprecated:: Use :meth:`changeset_close` instead."""
        warnings.warn(
            "ChangesetClose() is deprecated, use changeset_close() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_close()

    def ChangesetUpload(
        self, ChangesData: list[dict[str, Any]]
    ) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`changeset_upload` instead."""
        warnings.warn(
            "ChangesetUpload() is deprecated, use changeset_upload() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_upload(ChangesData)

    def ChangesetDownload(self, ChangesetId: int) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`changeset_download` instead."""
        warnings.warn(
            "ChangesetDownload() is deprecated, use changeset_download() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_download(ChangesetId)

    def ChangesetsGet(  # noqa
        self,
        min_lon: Optional[float] = None,
        min_lat: Optional[float] = None,
        max_lon: Optional[float] = None,
        max_lat: Optional[float] = None,
        userid: Optional[int] = None,
        username: Optional[str] = None,
        closed_after: Optional[str] = None,
        created_before: Optional[str] = None,
        only_open: bool = False,
        only_closed: bool = False,
    ) -> dict[int, dict[str, Any]]:
        """.. deprecated:: Use :meth:`changesets_get` instead."""
        warnings.warn(
            "ChangesetsGet() is deprecated, use changesets_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changesets_get(
            min_lon,
            min_lat,
            max_lon,
            max_lat,
            userid,
            username,
            closed_after,
            created_before,
            only_open,
            only_closed,
        )

    def ChangesetComment(self, ChangesetId: int, comment: str) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`changeset_comment` instead."""
        warnings.warn(
            "ChangesetComment() is deprecated, use changeset_comment() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_comment(ChangesetId, comment)

    def ChangesetSubscribe(self, ChangesetId: int) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`changeset_subscribe` instead."""
        warnings.warn(
            "ChangesetSubscribe() is deprecated, use changeset_subscribe() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_subscribe(ChangesetId)

    def ChangesetUnsubscribe(self, ChangesetId: int) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`changeset_unsubscribe` instead."""
        warnings.warn(
            "ChangesetUnsubscribe() is deprecated, use changeset_unsubscribe() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.changeset_unsubscribe(ChangesetId)

    ##################################################
    # Note - Deprecated CamelCase methods           #
    ##################################################

    def NotesGet(
        self,
        min_lon: float,
        min_lat: float,
        max_lon: float,
        max_lat: float,
        limit: int = 100,
        closed: int = 7,
    ) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`notes_get` instead."""
        warnings.warn(
            "NotesGet() is deprecated, use notes_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.notes_get(min_lon, min_lat, max_lon, max_lat, limit, closed)

    def NoteGet(self, id: int) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`note_get` instead."""
        warnings.warn(
            "NoteGet() is deprecated, use note_get() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.note_get(id)

    def NoteCreate(self, NoteData: dict[str, Any]) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`note_create` instead."""
        warnings.warn(
            "NoteCreate() is deprecated, use note_create() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.note_create(NoteData)

    def NoteComment(self, note_id: int, comment: str) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`note_comment` instead."""
        warnings.warn(
            "NoteComment() is deprecated, use note_comment() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.note_comment(note_id, comment)

    def NoteClose(self, note_id: int, comment: Optional[str] = None) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`note_close` instead."""
        warnings.warn(
            "NoteClose() is deprecated, use note_close() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.note_close(note_id, comment)

    def NoteReopen(self, note_id: int, comment: Optional[str] = None) -> dict[str, Any]:
        """.. deprecated:: Use :meth:`note_reopen` instead."""
        warnings.warn(
            "NoteReopen() is deprecated, use note_reopen() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.note_reopen(note_id, comment)

    def NotesSearch(
        self, query: str, limit: int = 100, closed: int = 7
    ) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`notes_search` instead."""
        warnings.warn(
            "NotesSearch() is deprecated, use notes_search() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.notes_search(query, limit, closed)

    def _NoteAction(
        self, path: str, comment: Optional[str] = None, optionalAuth: bool = True
    ) -> dict[str, Any]:
        """Internal method - calls _note_action."""
        return self._note_action(path, comment, optionalAuth)

    ##################################################
    # Map - Deprecated CamelCase methods            #
    ##################################################

    def Map(
        self, min_lon: float, min_lat: float, max_lon: float, max_lat: float
    ) -> list[dict[str, Any]]:
        """.. deprecated:: Use :meth:`map` instead."""
        warnings.warn(
            "Map() is deprecated, use map() instead",
            DeprecationWarning,
            stacklevel=2,
        )
        return self.map(min_lon, min_lat, max_lon, max_lat)

    ##################################################
    # Internal method                                #
    ##################################################

    def _do(  # type: ignore[return-value]  # noqa: C901
        self, action: str, osm_type: str, osm_data: dict[str, Any]
    ) -> dict[str, Any]:
        if not self._current_changeset_id:
            raise errors.NoChangesetOpenError(
                "You need to open a changeset before uploading data"
            )
        if "timestamp" in osm_data:
            osm_data.pop("timestamp")
        osm_data["changeset"] = self._current_changeset_id
        if action == "create":
            if osm_data.get("id", -1) > 0:
                raise errors.OsmTypeAlreadyExistsError(
                    f"This {osm_type} already exists"
                )
            try:
                result = self._session._put(
                    f"/api/0.6/{osm_type}/create",
                    xmlbuilder._xml_build(osm_type, osm_data, data=self),
                )
            except errors.ApiError as e:
                if e.status == 409 and re.search(
                    r"The changeset .* was closed at .*", e.payload
                ):
                    raise errors.ChangesetClosedApiError(
                        e.status, e.reason, e.payload
                    ) from e
                elif e.status == 409:
                    raise errors.VersionMismatchApiError(
                        e.status, e.reason, e.payload
                    ) from e
                elif e.status == 412:
                    raise errors.PreconditionFailedApiError(
                        e.status, e.reason, e.payload
                    ) from e
                else:
                    raise
            osm_data["id"] = int(result.strip())
            osm_data["version"] = 1
            return osm_data
        elif action == "modify":
            try:
                result = self._session._put(
                    f"/api/0.6/{osm_type}/{osm_data['id']}",
                    xmlbuilder._xml_build(osm_type, osm_data, data=self),
                )
            except errors.ApiError as e:
                logger.error(e.reason)
                if e.status == 409 and re.search(
                    r"The changeset .* was closed at .*", e.payload
                ):
                    raise errors.ChangesetClosedApiError(
                        e.status, e.reason, e.payload
                    ) from e
                elif e.status == 409:
                    raise errors.VersionMismatchApiError(
                        e.status, e.reason, e.payload
                    ) from e
                elif e.status == 412:
                    raise errors.PreconditionFailedApiError(
                        e.status, e.reason, e.payload
                    ) from e
                else:
                    raise
            osm_data["version"] = int(result.strip())
            return osm_data
        elif action == "delete":
            try:
                result = self._session._delete(
                    f"/api/0.6/{osm_type}/{osm_data['id']}",
                    xmlbuilder._xml_build(osm_type, osm_data, data=self),
                )
            except errors.ApiError as e:
                if e.status == 409 and re.search(
                    r"The changeset .* was closed at .*", e.payload
                ):
                    raise errors.ChangesetClosedApiError(
                        e.status, e.reason, e.payload
                    ) from e
                elif e.status == 409:
                    raise errors.VersionMismatchApiError(
                        e.status, e.reason, e.payload
                    ) from e
                elif e.status == 412:
                    raise errors.PreconditionFailedApiError(
                        e.status, e.reason, e.payload
                    ) from e
                else:
                    raise
            osm_data["version"] = int(result.strip())
            osm_data["visible"] = False
            return osm_data

    def _add_changeset_data(self, change_data: list[dict[str, Any]], type: str) -> str:
        data = ""
        for changed_element in change_data:
            changed_element["changeset"] = self._current_changeset_id
            xml_data = xmlbuilder._xml_build(type, changed_element, False, data=self)
            data += xml_data.decode("utf-8")
        return data

    def _assign_id_and_version(
        self, response_data: list[Element], request_data: list[dict[str, Any]]
    ) -> None:
        for response, element in zip(response_data, request_data):
            element["id"] = int(response.getAttribute("new_id"))
            element["version"] = int(response.getAttribute("new_version"))