Mercurial > p > roundup > code
comparison test/memorydb.py @ 5381:0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
(Also likewise "not in" where appropriate.) Tool-generated patch.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 22:08:17 +0000 |
| parents | 35ea9b1efc14 |
| children | e9fb7c539a52 |
comparison
equal
deleted
inserted
replaced
| 5380:64c4e43fbb84 | 5381:0942fe89e82e |
|---|---|
| 263 # | 263 # |
| 264 # Classes | 264 # Classes |
| 265 # | 265 # |
| 266 def __getattr__(self, classname): | 266 def __getattr__(self, classname): |
| 267 """A convenient way of calling self.getclass(classname).""" | 267 """A convenient way of calling self.getclass(classname).""" |
| 268 if self.classes.has_key(classname): | 268 if classname in self.classes: |
| 269 return self.classes[classname] | 269 return self.classes[classname] |
| 270 raise AttributeError(classname) | 270 raise AttributeError(classname) |
| 271 | 271 |
| 272 def addclass(self, cl): | 272 def addclass(self, cl): |
| 273 cn = cl.classname | 273 cn = cl.classname |
| 274 if self.classes.has_key(cn): | 274 if cn in self.classes: |
| 275 raise ValueError(cn) | 275 raise ValueError(cn) |
| 276 self.classes[cn] = cl | 276 self.classes[cn] = cl |
| 277 if cn not in self.items: | 277 if cn not in self.items: |
| 278 self.items[cn] = cldb() | 278 self.items[cn] = cldb() |
| 279 self.ids[cn] = 0 | 279 self.ids[cn] = 0 |
| 390 class Class(back_anydbm.Class): | 390 class Class(back_anydbm.Class): |
| 391 pass | 391 pass |
| 392 | 392 |
| 393 class FileClass(back_anydbm.FileClass): | 393 class FileClass(back_anydbm.FileClass): |
| 394 def __init__(self, db, classname, **properties): | 394 def __init__(self, db, classname, **properties): |
| 395 if not properties.has_key('content'): | 395 if 'content' not in properties: |
| 396 properties['content'] = hyperdb.String(indexme='yes') | 396 properties['content'] = hyperdb.String(indexme='yes') |
| 397 if not properties.has_key('type'): | 397 if 'type' not in properties: |
| 398 properties['type'] = hyperdb.String() | 398 properties['type'] = hyperdb.String() |
| 399 back_anydbm.Class.__init__(self, db, classname, **properties) | 399 back_anydbm.Class.__init__(self, db, classname, **properties) |
| 400 | 400 |
| 401 def export_files(self, dirname, nodeid): | 401 def export_files(self, dirname, nodeid): |
| 402 dest = self.exportFilename(dirname, nodeid) | 402 dest = self.exportFilename(dirname, nodeid) |
| 410 f = open(source, 'rb') | 410 f = open(source, 'rb') |
| 411 self.db.files[self.classname, nodeid, None] = f.read() | 411 self.db.files[self.classname, nodeid, None] = f.read() |
| 412 f.close() | 412 f.close() |
| 413 mime_type = None | 413 mime_type = None |
| 414 props = self.getprops() | 414 props = self.getprops() |
| 415 if props.has_key('type'): | 415 if 'type' in props: |
| 416 mime_type = self.get(nodeid, 'type') | 416 mime_type = self.get(nodeid, 'type') |
| 417 if not mime_type: | 417 if not mime_type: |
| 418 mime_type = self.default_mime_type | 418 mime_type = self.default_mime_type |
| 419 if props['content'].indexme: | 419 if props['content'].indexme: |
| 420 self.db.indexer.add_text((self.classname, nodeid, 'content'), | 420 self.db.indexer.add_text((self.classname, nodeid, 'content'), |
| 427 """The newly-created class automatically includes the "messages", | 427 """The newly-created class automatically includes the "messages", |
| 428 "files", "nosy", and "superseder" properties. If the 'properties' | 428 "files", "nosy", and "superseder" properties. If the 'properties' |
| 429 dictionary attempts to specify any of these properties or a | 429 dictionary attempts to specify any of these properties or a |
| 430 "creation" or "activity" property, a ValueError is raised. | 430 "creation" or "activity" property, a ValueError is raised. |
| 431 """ | 431 """ |
| 432 if not properties.has_key('title'): | 432 if 'title' not in properties: |
| 433 properties['title'] = hyperdb.String(indexme='yes') | 433 properties['title'] = hyperdb.String(indexme='yes') |
| 434 if not properties.has_key('messages'): | 434 if 'messages' not in properties: |
| 435 properties['messages'] = hyperdb.Multilink("msg") | 435 properties['messages'] = hyperdb.Multilink("msg") |
| 436 if not properties.has_key('files'): | 436 if 'files' not in properties: |
| 437 properties['files'] = hyperdb.Multilink("file") | 437 properties['files'] = hyperdb.Multilink("file") |
| 438 if not properties.has_key('nosy'): | 438 if 'nosy' not in properties: |
| 439 # note: journalling is turned off as it really just wastes | 439 # note: journalling is turned off as it really just wastes |
| 440 # space. this behaviour may be overridden in an instance | 440 # space. this behaviour may be overridden in an instance |
| 441 properties['nosy'] = hyperdb.Multilink("user", do_journal="no") | 441 properties['nosy'] = hyperdb.Multilink("user", do_journal="no") |
| 442 if not properties.has_key('superseder'): | 442 if 'superseder' not in properties: |
| 443 properties['superseder'] = hyperdb.Multilink(classname) | 443 properties['superseder'] = hyperdb.Multilink(classname) |
| 444 Class.__init__(self, db, classname, **properties) | 444 Class.__init__(self, db, classname, **properties) |
| 445 | 445 |
| 446 # vim: set et sts=4 sw=4 : | 446 # vim: set et sts=4 sw=4 : |
