Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/clipboard/typeregistry.py
blob: 97ac37b80689a7cd673fe35b962426cc321865c7 (plain)
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
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
import logging
from gettext import gettext as _
import urlparse
import posixpath

class FileType:
    """Generic base class for all classes representing clipboard item formats.

    XXX This class's name is misleading; it represents a clipboard item
    format and not a file type per se.  Perhaps it should be renamed to
    ClipboardItemFormat?
    """
    
    def __init__(self, formats):
        """Initializer for this class (and all subclasses).
        
        formats -- A dictionary of key-value pairs where the keys are MIME type
            strings and the data values are the clipboard data in each
            respective format.  A reference to this dictionary is stored within
            the object for possible use later.
        
        This initializer is invoked when the clipboard item format object is
        instantiated by the TypeRegistry class's get_type method.
        
        """
        self._formats = formats

    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        This base-class implementation raises a NotImplementedError exception.
        
        returns A localized string containing the clipboard item format name.
        """
        raise NotImplementedError

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        This base-class implementation raises a NotImplementedError exception.
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        raise NotImplementedError

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        This base-class implementation raises a NotImplementedError exception.
        
        returns A string containing the item preview.
        """
        raise NotImplementedError

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        This base-class implementation raises a NotImplementedError exception.
        
        returns A string containing the activity identifier. 
        """
        raise NotImplementedError
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This base-class implementation currently raises a
        NotImplementedError exception, but could (and should) be rewritten to
        handle this functionality for *all* subclasses, since the code is
        identical for all or most subclasses anyway.
       
        returns True if this class handles the given MIME type, False otherwise.
        """
        raise NotImplementedError
        
    matches_mime_type = classmethod(matches_mime_type)

    
class TextFileType(FileType):
    """Represents the text clipboard item format.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """

    _types = set(['text/plain', 'UTF8_STRING', 'STRING'])

    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Text snippet')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-text'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        For the text file format, this returns a text string containing up to
        49 characters of the actual item's text.
        
        returns A preview string containing up to 49 characters of the item's
            text.
        """
        for format, data in self._formats.iteritems():
            if format in TextFileType._types:
                text = data.get_data()
                if len(text) < 50:
                    return text
                else:
                    return text[0:49] + "..."

        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return 'org.laptop.AbiWordActivity'
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class ImageFileType(FileType):
    """Represents the "image" clipboard item format.
    
    This clipboard item format represents *any* image format, including JPEG,
    GIF, PNG and TIFF formats.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """

    _types = set(['image/jpeg', 'image/gif', 'image/png', 'image/tiff'])

    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Image')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-image'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return ''
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class UriFileType(FileType):
    """Represents the URI clipboard item format.
    
    Not to be confused with the multiple-URI UriListFileType class.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['_NETSCAPE_URL'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Web Page')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-link'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        For the URI clipboard item format, this is the URI itself.
        
        returns A string containing the item preview, in this case the URI itself.
        """
        for format, data in self._formats.iteritems():
            if format in UriFileType._types:
                string = data.get_data()
                title = string.split("\n")[1]
                return title
        
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return ''

    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class PdfFileType(FileType):
    """Represents the PDF clipboard item format.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['application/pdf', 'application/x-pdf'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('PDF file')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-text'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return 'org.laptop.sugar.Xbook'
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class MsWordFileType(FileType):
    """Represents the MS Word clipboard item format (*cringe*).
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['application/msword'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('MS Word file')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-text'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return 'org.laptop.AbiWordActivity'
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
       
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class RtfFileType(TextFileType):
    """Represents the RTF clipboard item format (a subclass of TextFileType).
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['application/rtf', 'text/rtf'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('RTF file')
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class AbiwordFileType(TextFileType):
    """Represents the AbiWord clipboard item format.
   
    (XXX This class's name is misleading; it represents a clipboard item format,
    not a file type per se.)
    (XXX AbiWord format is a full word processing format, like the OO Text and MS Word
    formats, and should not be a subclass of TextFileType!  Otherwise the OO Text and
    MS Word format types should also be made subclasses of TextFileType.)
    """
    
    _types = set(['application/x-abiword'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Abiword file')
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class SqueakProjectFileType(FileType):
    """Represents the Squeak Project clipboard item format.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['application/x-squeak-project'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Squeak project')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-squeak-project'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return 'org.vpri.EtoysActivity'
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class OOTextFileType(FileType):
    """Represents the OpenDocument Text (OpenOffice.org Writer) clipboard item format.
    
    Note to the uninitiated: OpenDocument Text is a full word processing format,
    not a simple text file.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['application/vnd.oasis.opendocument.text'])
    
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('OpenOffice text file')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:object-text'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return 'org.laptop.AbiWordActivity'
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class UriListFileType(FileType):
    """Represents the URI-list clipboard item format.
   
    Not to be confused with the single-URI UriFileType class.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['text/uri-list'])

    def _is_image(self):
        """Determines whether this URI list represents an image.
        
        Called by the get_name and get_icon methods.  For this URI list to be
        considered to represent an image, it must fulfil two criteria: (1) it
        must have only one URI in it, and (2) the URI must end with an extension
        indicating an image type (currently ".jpg", ".jpeg", ".gif", ".png", or
        ".svg").
        
        returns True if there is one URI in the list and it represents an image,
            False otherwise.
        """
        uris = self._formats['text/uri-list'].get_data().split('\n')
        if len(uris) == 1:
            uri = urlparse.urlparse(uris[0])
            ext = posixpath.splitext(uri.path)[1]
            logging.debug(ext)
            # FIXME: Bad hack, the type registry should treat text/uri-list as a special case.
            if ext in ['.jpg', '.jpeg', '.gif', '.png', '.svg']:
                return True
        
        return False

    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        if self._is_image():
            return _('Image')
        else:
            return _('File')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        if self._is_image():
            return 'theme:object-image'
        else:
            return 'theme:stock-missing'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return ''
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class XoFileType(FileType):
    """Represents the "xo" (OLPC package) clipboard item format.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    
    _types = set(['application/vnd.olpc-x-sugar'])

    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Activity package')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:stock-missing'

    def get_preview(self):
        """Returns an appropriate preview of the clipboard item data for this item format.
        
        XXX Currently returns an empty string.
        
        returns A string containing the item preview.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        returns A string containing the activity identifier. 
        """
        return ''
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        XXX This subclass method is unnecessary; a single base class method
        in the FileType class would be sufficient to handle all or most
        subclasses, since the code is identical for all or most subclasses
        anyway.
        
        returns True if this class handles the given MIME type, False otherwise.
        """
        return mime_type in cls._types
        
    matches_mime_type = classmethod(matches_mime_type)

    
class UnknownFileType(FileType):
    """Represents an unknown clipboard item format.
    
    XXX This class's name is misleading; it represents a clipboard item format
    and not a file type per se.
    """
    def get_name(self):
        """Returns a localized human-readable name for this clipboard item format.
        
        Since this clipboard item format is unknown, the format name will be
        simply "Object" or something to that effect.
        
        returns A localized string containing the clipboard item format name.
        """
        return _('Object')

    def get_icon(self):
        """XXX Returns a "tag" to be used to get an icon for this clipboard item format (I think).
        
        returns XXX A string "tag" to be used to get the icon for this clipboard
            item format (I think).
        """
        return 'theme:stock-missing'

    def get_preview(self):
        """Returns a "preview" for this clipboard item format.
        
        Since this clipboard item format is unknown, there can be no preview for
        it, so the "preview" will be an empty string.
        
        returns An empty string, since there can be no preview for an unknown
            clipboard item format.
        """
        return ''

    def get_activity(self):
        """Returns the activity identifier associated with this clipboard item format.
        
        Since this clipboard item format is unknown, there can be no activity
        associated with it, so the activity identifier will be an empty string.
        
        returns A string containing the activity identifier (an empty string in
            this case).
        """
        return ''
        
    def matches_mime_type(cls, mime_type):
        """Class method to determine whether this class handles a given MIME type.
        
        mime_type -- A string containing the MIME type.
        
        Always returns true, since UnknownFileType is the clipboard item format
        class of last resort and must be used if no other class handles the
        given MIME type.
        
        returns True if this class handles the given MIME type (always true in
            this case).
        """
        return true
        
    matches_mime_type = classmethod(matches_mime_type)

    
class TypeRegistry:
    """Represents a registry of all clipboard item formats.
    
    There will be one single global instantiation of this object, accessible via
    the global typeregistry.get_instance method.
    """
    def __init__(self):
        """Initializes the registry.
        """
        self._types = []
        self._types.append(PdfFileType)
        self._types.append(MsWordFileType)
        self._types.append(RtfFileType)
        self._types.append(OOTextFileType)
        self._types.append(UriListFileType)
        self._types.append(UriFileType)
        self._types.append(ImageFileType)
        self._types.append(AbiwordFileType)
        self._types.append(TextFileType)
        self._types.append(SqueakProjectFileType)
        self._types.append(XoFileType)
    
    def get_type(self, formats):
        """Returns a matching clipboard item format object for the passed-in clipboard data.
        
        formats -- A dictionary of key-value pairs where the keys are MIME type
            strings and the data values are the clipboard data in each
            respective format.
        
        A reference to the given clipboard data format dictionary is stored
        within the returned object for possible use later.
        
        XXX The order of the clipboard item formats in the TypeRegistry object's
        internal list matters.  For example, if clipboard item data is available
        in both MS Word and OO Text formats, the MS Word type will currently be
        matched first, and therefore an MsWordFileType object will be returned.
        Is this really what is desired?  The ordering should definitely be given
        some thought.
        
        returns A clipboard item format object of a type matching one of the
            MIME type keys in the formats dictionary, or an UnknownFileType
            object if none of the other types is appropriate.
        """
        for file_type in self._types:
            for format, data in formats.iteritems():
                if file_type.matches_mime_type(format):
                    return file_type(formats)

        return UnknownFileType(formats)
    
_type_registry = None
def get_instance():
    """Returns the global clipboard item format registry object (global method).
    
    Returns a reference to the global clipboard item format registry object,
    instantiating it first if necessary.
    
    returns A TypeRegistry object representing the global clipboard item format
        registry.
    """
    global _type_registry
    if not _type_registry:
        _type_registry = TypeRegistry()
    return _type_registry