示例#1
0
 def testCreateWriterDirectInstantiation(self):
     """
 Only FileWriter can be instantiated by CreateWriter.
 All others in writers.py must be instantiated via their constructor.
 """
     location = os.path.join(TEST_DATA, 'aes')
     self.assertTrue(os.path.isdir(location))
     # make sure all writers are available
     util.ImportBackends()
     # Check all non-FileWriters
     for sc in writers.Writer.__subclasses__():
         if not issubclass(sc, writers.FileWriter):
             self.assertIsNone(sc.CreateWriter(location))
示例#2
0
def CreateWriter(location):
  """Factory function for Writers
  
    @param location: where (file, uri, etc) the writer should write to
    @type location: string
  """
  # make sure all writers are available
  util.ImportBackends()
  for sc in Writer.__subclasses__():
    writer = sc.CreateWriter(location)
    if writer:
      return writer
  raise errors.KeyczarError(
    "Unable to create a writer for %s. Does the location exist?" % location)
示例#3
0
def CreateReader(location):
    """Factory function for Reader's
  
    @param location: where (file, uri, etc) the reader should read from
    @type location: string
  """
    # make sure all readers are available
    util.ImportBackends()
    # return the first that accepts the location
    for sc in Reader.__subclasses__():
        reader = sc.CreateReader(location)
        if reader:
            return reader
    raise errors.KeyczarError(
        "Unable to create a reader for %s. Does the location exist?" %
        location)