You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB
Python

3 years ago
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class ResourceInterface:
@classmethod
def __subclasshook__(cls, subclass):
return (hasattr(subclass, 'format_text') and
callable(subclass.format_text) and
hasattr(subclass, 'format_data') and
callable(subclass.format_data) or
NotImplemented)
class Author(ResourceInterface):
def __init__(self, author, sort):
self.author = author
self.sort = sort
def format_text(self):
return self.author
def format_data(self):
return self.sort
class Book(ResourceInterface):
def __init__(self, title, author, file):
self.title = title
self.author = author
self.file = file
def format_text(self):
return self.title + " - " + self.author
def format_data(self):
return self.file
class CorsoDiStudio(ResourceInterface):
def __init__(self, cds):
self.cds = cds
def format_text(self):
return self.cds
def format_data(self):
return self.cds
def book_factory(cursor, row):
return Book(row[0], row[1], row[2])
def author_factory(cursor, row):
return Author(row[0], row[1])
#def cds_factory(cursor, row):
# pass