Open the database file, filename, and return corresponding object. The flag argument, used to control how the database is opened in the other DBM implementations, supports only the semantics of 'c' and 'n' values. Other values will default to the semantics of 'c' value: the databas
(file, flag='c', mode=0o666)
| 317 | |
| 318 | |
| 319 | def open(file, flag='c', mode=0o666): |
| 320 | """Open the database file, filename, and return corresponding object. |
| 321 | |
| 322 | The flag argument, used to control how the database is opened in the |
| 323 | other DBM implementations, supports only the semantics of 'c' and 'n' |
| 324 | values. Other values will default to the semantics of 'c' value: |
| 325 | the database will always opened for update and will be created if it |
| 326 | does not exist. |
| 327 | |
| 328 | The optional mode argument is the UNIX mode of the file, used only when |
| 329 | the database has to be created. It defaults to octal code 0o666 (and |
| 330 | will be modified by the prevailing umask). |
| 331 | |
| 332 | """ |
| 333 | |
| 334 | # Modify mode depending on the umask |
| 335 | try: |
| 336 | um = _os.umask(0) |
| 337 | _os.umask(um) |
| 338 | except AttributeError: |
| 339 | pass |
| 340 | else: |
| 341 | # Turn off any bits that are set in the umask |
| 342 | mode = mode & (~um) |
| 343 | if flag not in ('r', 'w', 'c', 'n'): |
| 344 | raise ValueError("Flag must be one of 'r', 'w', 'c', or 'n'") |
| 345 | return _Database(file, mode, flag=flag) |
searching dependent graphs…