コード例 #1
0
    def encode(self, o):
        root_id = id(o)
        if self.check_circular:
            markers = {}
        else:
            markers = None

        def _encode(o):
            try:
                import pandas as pd
            except ImportError:
                pd = None

            if isinstance(o, (list, tuple, dict)):
                if markers is not None:
                    marker_id = id(o)
                    if marker_id in markers:
                        if marker_id == root_id:
                            return {"$ref": "#"}
                        raise ValueError("Circular reference detected")
                    markers[marker_id] = o
                try:
                    if isinstance(o, dict):
                        return {k: _encode(v) for k, v in o.items()}
                    else:
                        return [_encode(v) for v in o]
                finally:
                    if markers is not None:
                        del markers[marker_id]

            if isinstance(o, date):
                return {"$date": int(calendar.timegm(o.timetuple()) * 1000)}
            if isinstance(o, datetime):
                return {"$date": int(calendar.timegm(o.utctimetuple()) * 1000)}

            if isinstance(o, Reference):
                # FIXME if reference is not saved, save it first here
                return {"$ref": o._uri}

            try:
                if pd and pd.api.types.is_integer(o):
                    return int(o)
            except AttributeError:
                # some versions of pandas may not have this API
                pass

            try:
                if pd and pd.api.types.is_float(o):
                    return float(o)
            except AttributeError:
                pass

            return o

        return JSONEncoder.encode(self, _encode(o))
コード例 #2
0
ファイル: converter.py プロジェクト: onecodex/onecodex
    def encode(self, o):
        root_id = id(o)
        if self.check_circular:
            markers = {}
        else:
            markers = None

        def _encode(o):
            if isinstance(o, (list, tuple, dict)):
                if markers is not None:
                    marker_id = id(o)
                    if marker_id in markers:
                        if marker_id == root_id:
                            return {"$ref": "#"}
                        raise ValueError("Circular reference detected")
                    markers[marker_id] = o
                try:
                    if isinstance(o, dict):
                        return {k: _encode(v) for k, v in o.items()}
                    else:
                        return [_encode(v) for v in o]
                finally:
                    if markers is not None:
                        del markers[marker_id]

            if isinstance(o, date):
                return {"$date": int(calendar.timegm(o.timetuple()) * 1000)}
            if isinstance(o, datetime):
                return {"$date": int(calendar.timegm(o.utctimetuple()) * 1000)}

            if isinstance(o, Reference):
                # FIXME if reference is not saved, save it first here
                return {"$ref": o._uri}

            try:
                if pd and pd.api.types.is_integer(o):
                    return int(o)
            except AttributeError:
                # some versions of pandas may not have this API
                pass

            try:
                if pd and pd.api.types.is_float(o):
                    return float(o)
            except AttributeError:
                pass

            return o

        return JSONEncoder.encode(self, _encode(o))
コード例 #3
0
ファイル: converter.py プロジェクト: onecodex/potion-client
    def encode(self, o):
        root_id = id(o)
        if self.check_circular:
            markers = {}
        else:
            markers = None

        def _encode(o):
            if isinstance(o, (list, tuple, dict)):
                if markers is not None:
                    marker_id = id(o)
                    if marker_id in markers:
                        if marker_id == root_id:
                            return {"$ref": "#"}
                        raise ValueError("Circular reference detected")
                    markers[marker_id] = o
                try:
                    if isinstance(o, dict):
                        return {k: _encode(v) for k, v in o.items()}
                    else:
                        return [_encode(v) for v in o]
                finally:
                    if markers is not None:
                        del markers[marker_id]

            if isinstance(o, date):
                return {"$date": int(calendar.timegm(o.timetuple()) * 1000)}
            if isinstance(o, datetime):
                return {"$date": int(calendar.timegm(o.utctimetuple()) * 1000)}

            if isinstance(o, Reference):
                # FIXME if reference is not saved, save it first here
                return {"$ref": o._uri}

            return o

        return JSONEncoder.encode(self, _encode(o))
コード例 #4
0
ファイル: jsapi.py プロジェクト: Zojax/zojax.calendar
                event.attendees = membersToTuple(attendees)
                event.eventUrl = bool(eventUrl) and eventUrl or None
                event.contactName = contactName
                event.contactEmail = bool(contactEmail) and contactEmail or None
                event.contactPhone = contactPhone
                event.text = text

                notify(ObjectModifiedEvent(event))

                msg = {'IsSuccess': True, 'Msg': 'Updated Successfully', 'Data': eventId}
            except Exception, e:
                msg = {'IsSuccess': False, 'Msg': 'Event is not update: %s'%e}
        else:
            msg = {'IsSuccess': False, 'Msg': 'Event is not update'}

        return encoder.encode(msg)


    def addDetailedCalendar(self, startDate, endDate, \
        subject, isAllDayEvent, description, location, colorvalue, timezone, \
        eventUrl, contactName, contactEmail, contactPhone, text, attendees):
        context = self.context
        container = context.context

        try:
            eventCt = getUtility(IContentType, name='calendar.event')
            event = eventCt.create(title=subject)

            event.description = description
            event.startDate = startDate
            event.endDate = endDate
コード例 #5
0
                id = ids.queryId(removeAllProxies(image))
                removeAllProxies(image.preview).generatePreview(width, height)
                info = {'id': id,
                        'name': image.__name__,
                        'title': image.title or image.__name__,
                        'width': image.width,
                        'height': image.height,
                        'size': len(image.data),
                        'modified': IDCTimes(image).modified.isoformat()[:19].replace('T',' '),
                        'url': '@@content.attachment/%s'%id,
                        'preview': '%s/content.attachment/%s/preview/%sx%s/'%(siteUrl, id, width, height),
                        }
                data.append(info)

        data.sort(key=lambda x: x[sort], reverse=sort_direction == 'DESC')
        return encoder.encode({'images': data[start:limit and start+limit or None], 'total': len(data)})


class FileUpload(object):

    @jsonable
    def __call__(self):
        request = self.request
        container = self.context.context
        image = request.form.get('file', '')

        if not image:
            return encoder.encode({'success': False, 'message': '', 'error': 'No image provided'})
        name = os.path.split(image.filename)[-1]

        image = FileData(image)
コード例 #6
0
ファイル: base.py プロジェクト: thepian/themaestro
                 self._lines = []
                 print "failed to load Asset Source: '%s' in '%s' (source=%s)" % (self.path, self.basedir, source), e
                 import traceback; traceback.print_stack()
     else:
         self._lines = source.split('\n')
     includes = []
     for line in self._lines[:25]:
         m = requires_statement.search(line)
         if m:
             includes.extend(m.groups())
         m = scope_statement.search(line)
         if m:
             self.scope = self.get_scope(m.groups()[0]) 
     self.includes = [join(basedir,i) for i in includes]
     
     self.attributes_json = encoder.encode(attributes)
     self.attributes = attributes
     
     self.stashes = set()
     
 def __repr__(self):
     return self.path
     
 def prepend_stashes(self,lines):
     return lines
 
 def get_scope(self,name):
     try:
         with open(join(self.basedir,name)) as f:
             return f.read()
     except: