How to use the synapseclient.dict_object.DictObject function in synapseclient

To help you get started, we’ve selected a few synapseclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sage-Bionetworks / synapsePythonClient / synapseclient / entity.py View on Github external
:returns: a 3-tuple (properties, annotations, local_state).
    """
    if isinstance(entity, Entity):
        # Defensive programming: return copies
        return entity.properties.copy(), entity.annotations.copy(), entity.local_state()

    if not isinstance(entity, collections.Mapping):
        raise SynapseMalformedEntityError("Can't split a %s object." % entity.__class__.__name__)

    if 'concreteType' in entity and entity['concreteType'] in _entity_type_to_class:
        entity_class = _entity_type_to_class[entity['concreteType']]
    else:
        entity_class = Entity

    properties = DictObject()
    annotations = DictObject()
    local_state = DictObject()

    property_keys = entity_class._property_keys
    local_keys = entity_class._local_keys
    for key, value in six.iteritems(entity):
        if key in property_keys:
            properties[key] = value
        elif key in local_keys:
            local_state[key] = value
        else:
            annotations[key] = value

    return properties, annotations, local_state
github Sage-Bionetworks / synapsePythonClient / synapseclient / entity.py View on Github external
def _update_file_handle(self, file_handle_update_dict=None):
        """
        Sets the file handle
        
        Should not need to be called by users
        """

        # replace the file handle dict
        fh_dict = DictObject(file_handle_update_dict) if file_handle_update_dict is not None else DictObject()
        self.__dict__['_file_handle'] = fh_dict

        if file_handle_update_dict is not None \
                and file_handle_update_dict.get('concreteType') == "org.sagebionetworks.repo.model.file.ExternalFileHandle"\
                and utils.urlparse(file_handle_update_dict.get('externalURL')).scheme != 'sftp':
            self.__dict__['synapseStore'] = False

        # initialize all nonexistent keys to have value of None
        for key in self.__class__._file_handle_keys:
            if key not in fh_dict:
                fh_dict[key] = None
github Sage-Bionetworks / synapsePythonClient / synapseclient / multipart_upload.py View on Github external
:returns: A `MultipartUploadStatus`_

    .. _MultipartUploadStatus:
     http://docs.synapse.org/rest/org/sagebionetworks/repo/model/file/MultipartUploadStatus.html
    """
    upload_request = {
        'contentMD5Hex': md5,
        'fileName': filename,
        'generatePreview': preview,
        'contentType': contentType,
        'partSizeBytes': partSize,
        'fileSizeBytes': fileSize,
        'storageLocationId': storageLocationId
    }

    return DictObject(**syn.restPOST(uri='/file/multipart?forceRestart=%s' % forceRestart,
                                     body=json.dumps(upload_request),
                                     endpoint=syn.fileHandleEndpoint))
github Sage-Bionetworks / synapsePythonClient / synapseclient / evaluation.py View on Github external
'versionNumber' in kwargs):
            raise KeyError

        super(Submission, self).__init__(kwargs)

    def postURI(self):
        return '/evaluation/submission?etag=%s' % self.etag

    def putURI(self):
        return '/evaluation/submission/%s' % self.id

    def deleteURI(self):
        return '/evaluation/submission/%s' % self.id


class SubmissionStatus(DictObject):
    """
    Builds an Synapse submission status object.

    :param score:      The score of the submission
    :param status:     Status can be one of {'OPEN', 'CLOSED', 'SCORED', 'INVALID'}.
    """

    @classmethod
    def getURI(cls, id):
        return '/evaluation/submission/%s/status' % id

    def __init__(self, **kwargs):
        super(SubmissionStatus, self).__init__(kwargs)

    def postURI(self):
        return '/evaluation/submission/%s/status' % self.id
github Sage-Bionetworks / synapsePythonClient / synapseclient / client.py View on Github external
def getWikiHeaders(self, owner):
        """
        Retrieves the header of all Wiki's belonging to the owner.
        
        :param owner: An Evaluation or Entity
        
        :returns: A list of Objects with three fields: id, title and parentId.
        """

        uri = '/entity/%s/wikiheadertree' % id_of(owner)
        return [DictObject(**header) for header in self.restGET(uri)['results']]
github Sage-Bionetworks / synapsePythonClient / synapseclient / multipart_upload.py View on Github external
def _complete_multipart_upload(syn, uploadId):
    """
    :returns: A MultipartUploadStatus_.

    .. MultipartUploadStatus:
     http://docs.synapse.org/rest/org/sagebionetworks/repo/model/file/MultipartUploadStatus.html
    """
    uri = '/file/multipart/{uploadId}/complete'.format(uploadId=uploadId)
    return DictObject(**syn.restPUT(uri, endpoint=syn.fileHandleEndpoint))
github Sage-Bionetworks / synapsePythonClient / synapseclient / client.py View on Github external
Example::

            syn._findPrincipals('test')

            [{u'displayName': u'Synapse Test',
              u'email': u'syn...t@sagebase.org',
              u'firstName': u'Synapse',
              u'isIndividual': True,
              u'lastName': u'Test',
              u'ownerId': u'1560002'},
             {u'displayName': ... }]

        """
        uri = '/userGroupHeaders?prefix=%s' % query_string
        return [DictObject(**result) for result in self._GET_paginated(uri)]
github Sage-Bionetworks / synapsePythonClient / synapseclient / wiki.py View on Github external
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import six

import os
import json

from synapseclient.dict_object import DictObject
from synapseclient.utils import id_of


class Wiki(DictObject):
    """
    Represents a wiki page in Synapse with content specified in markdown.

    :param title:           Title of the Wiki
    :param owner:           Parent Entity that the Wiki will belong to
    :param markdown:        Content of the Wiki (cannot be defined if markdownFile is defined)
    :param markdownFile:    Path to file which contains the Content of Wiki (cannot be defined if markdown is defined)
    :param attachments:     List of paths to files to attach
    :param fileHandles:     List of file handle IDs representing files to be attached
    :param parentWikiId:    (optional) For sub-pages, specify parent wiki page
    """

    __PROPERTIES = ('title', 'markdown', 'attachmentFileHandleIds', 'id', 'etag', 'createdBy', 'createdOn',
                    'modifiedBy', 'modifiedOn', 'parentWikiId')

    def __init__(self, **kwargs):