Beispiel #1
0
 def testListValue(self):
     # Empty list
     metdataValue = json_format.convertFromPersistenceFormat("[]")
     self.assertEquals(metdataValue, list())
     # Mixed list
     self.assertEquals(
         json_format.convertFromPersistenceFormat(
             '["a", "b", 1, "2006-10-16T08:19:39Z"]'), [
                 "a", "b",
                 decimal.Decimal(1),
                 datetime.datetime(2006, 10, 16, 10, 19, 39)
             ])
     # Nested list
     jsonString = '[[["2006-10-16T08:19:39Z"]]]'
     self.assertEquals(json_format.convertFromPersistenceFormat(jsonString),
                       [[[datetime.datetime(2006, 10, 16, 10, 19, 39)]]])
Beispiel #2
0
 def _convertToDict(value):
     try:
         dictValue = json_format.convertFromPersistenceFormat(value)
     except PersistenceError:
         dictValue = None
     else:
         if not isinstance(dictValue, dict):
             dictValue = None
     return dictValue
Beispiel #3
0
 def _convertToDict(value):
     try:
         dictValue = json_format.convertFromPersistenceFormat(value)
     except PersistenceError:
         dictValue = None
     else:
         if not isinstance(dictValue, dict):
             dictValue = None
     return dictValue
Beispiel #4
0
class MetadataSubversionAdapter(NullMetadataStorer):
    """ Implements meta data storer interface for subversion. """
    
    def __init__(self, identifier, connectionPool):
        """
        Constructor.
        
        @param identifier: Logical identifier of the resource.
        @type identifier: C{unicode}
        @param connectionPool: Connection pool.
        @type connectionPool: L{Connection<datafinder.persistence.svn.connection_pool.SVNConnectionPool>}
        """
        
        NullMetadataStorer.__init__(self, identifier)
        self.__connectionPool = connectionPool

    def retrieve(self, propertyIds=None):
        """ @see: L{NullMetadataStorer<datafinder.persistence.metadata.metadatastorer.NullMetadataStorer>}"""

        connection = self.__connectionPool.acquire()
        try:
            properties = self._retrieveCustomProperties(connection)
            for key, value in properties.iteritems():
                properties[key] = json_format.MetadataValue(value)
            systemProperties = self._retrieveSystemProperties(connection)
            properties.update(systemProperties)
            return self._filterResult(propertyIds, properties)
        finally:
            self.__connectionPool.release(connection)

    @staticmethod
    def _filterResult(propertyIds, properties):
        if not propertyIds is None and len(propertyIds) > 0:
            filteredProps = dict()
            for propertyId in propertyIds:
                if propertyId in properties:
                    filteredProps[propertyId] = properties[propertyId]
        else:
            filteredProps = properties
        return filteredProps

    def _retrieveCustomProperties(self, connection):
        customProperties = dict()
        try:
            jsonString = connection.getProperty(self.identifier, JSON_PROPERTY_NAME)
        except SubversionError:
            parentId = util.determineParentPath(self.identifier)
            try:
                connection.update(parentId)
                jsonString = connection.getProperty(self.identifier, JSON_PROPERTY_NAME)
            except SubversionError, error:
                raise PersistenceError(str(error))
        if not jsonString is None:
            customProperties = json_format.convertFromPersistenceFormat(jsonString)
        return customProperties
Beispiel #5
0
    def testDictValues(self):
        # Empty dict
        metdataValue = json_format.convertFromPersistenceFormat("{}")
        self.assertEquals(metdataValue, dict())
        # Mixed and nested dict
        jsonString = '{"name": "me", "age": 30, ' \
                   + '"address":{"street": "there", "number": 1, ' \
                   + '"city": {"name": "there", "build": ["2006-10-16T08:19:39Z"]}}}'

        expectedResult = {
            "name": "me",
            "age": decimal.Decimal(30),
            "address": {
                "street": "there",
                "number": decimal.Decimal(1),
                "city": {
                    "name": "there",
                    "build": [datetime.datetime(2006, 10, 16, 10, 19, 39)]
                }
            }
        }
        self.assertEquals(json_format.convertFromPersistenceFormat(jsonString),
                          expectedResult)
Beispiel #6
0
 def testNumericValue(self):
     self.assertEquals(json_format.convertFromPersistenceFormat("4.5"),
                       decimal.Decimal("4.5"))
     self.assertEquals(json_format.convertFromPersistenceFormat("5"),
                       decimal.Decimal("5"))
Beispiel #7
0
 def testStringValue(self):
     self.assertEquals(json_format.convertFromPersistenceFormat(u'"test"'),
                       u"test")
     self.assertEquals(json_format.convertFromPersistenceFormat('"test"'),
                       "test")
Beispiel #8
0
 def testBoolValue(self):
     self.assertTrue(json_format.convertFromPersistenceFormat("true"))
     self.assertFalse(json_format.convertFromPersistenceFormat("false"))
Beispiel #9
0
 def testDatetimeValue(self):
     # From Iso8601.
     persistedValue = u'"2006-10-16T08:19:39Z"'
     metdataValue = json_format.convertFromPersistenceFormat(persistedValue)
     self.assertEquals(metdataValue,
                       datetime.datetime(2006, 10, 16, 10, 19, 39))