class Email(ComplexModel): _type_info = [ # # Metadata # ('id', JmapId( sub_name='id', doc="Id (immutable; server-set) The id of the Email object. Note " "that this is the JMAP object id, NOT the Message-ID header " "field value of the message [@!RFC5322].")), ('blob_id', JmapId(sub_name='blobId', doc="Id (immutable; server-set) The id representing the raw " "octets of the message [@!RFC5322] for this Email. This may " "be used to download the raw original message or to attach it " "directly to another Email, etc.")), ('thread_id', JmapId(sub_name='threadId', doc="(immutable; server-set) The id of the Thread to which " "this Email belongs.")), ( 'mailbox_ids', AnyDict( # this is supposed to be a JmapId: Boolean dict sub_name='mailboxIds', doc="The set of Mailbox ids this Email belongs to. An " "Email in the mail store MUST belong to one or more Mailboxes " "at all times (until it is destroyed). The set is represented " "as an object, with each key being a Mailbox id. The value " "for each key in the object MUST be true.")), ( 'keywords', AnyDict( # this is supposed to be a String: Boolean dict sub_name='keywords', doc="(default: {}) A set of keywords that apply " "to the Email. The set is represented as an object, with the " "keys being the keywords. The value for each key in the " "object MUST be true.")), ('size', UnsignedInteger( sub_name='size', doc="(immutable; server-set) The size, in octets, " "of the raw data for the message [@!RFC5322] (as referenced " "by the blobId, i.e., the number of octets in the file the " "user would download).")), ('received_at', UtcDate(sub_name='receivedAt', doc="(immutable; default: time of creation on server) The " "date the Email was received by the message store. This is " "the internal date in IMAP [@?RFC3501].")), ]
class LogEntryMixin(TableModel): __mixin__ = True __table_args__ = {"sqlite_autoincrement": True} id = Integer64(primary_key=True) time = DateTime(timezone=False) user = Unicode(256, index='btree') method = Unicode(64, index='btree') req_xml = AnyXml req_json = AnyDict(store_as='json') err_code = Integer resp_err = AnyDict(store_as='json') resp_int = Integer duration = Integer
class HelloWorldService(ServiceBase): @srpc(Float, Float, float, _returns=AnyDict()) def checkcrime(lat, lon, radius): # type: (object, object, object) -> object url = 'https://api.spotcrime.com/crimes.json?lat={}&lon={}&radius={}&key=.'.format(lat, lon, radius) data = requests.get(url).json() response = {} total_crimes = len(data["crimes"]) response["total_crimes"] = total_crimes crimeTypeCount = crimeType(data) crimePlaces = topThree(data) eventTimes = eventTimeCounts(data) report={ "total_crime":total_crimes, "crime_type_count": crimeTypeCount, "event_time_count": eventTimes, "the_most_dangerous_streets": crimePlaces } return report
def test_anydict_customization(self): from spyne.model import json assert isinstance( AnyDict.customize(store_as='json').Attributes.store_as, json)
class Email(ComplexModel): _type_info = [ # # Metadata # ('id', JmapId( sub_name='id', doc="(immutable; server-set) The id of the Email object. Note " "that this is the JMAP object id, NOT the Message-ID header " "field value of the message [@!RFC5322]." )), ('blob_id', JmapId( sub_name='blobId', doc="(immutable; server-set) The id representing the raw " "octets of the message [@!RFC5322] for this Email. This may " "be used to download the raw original message or to attach it " "directly to another Email, etc." )), ('thread_id', JmapId( sub_name='threadId', doc="(immutable; server-set) The id of the Thread to which " "this Email belongs." )), ('mailbox_ids', AnyDict( # this is supposed to be a JmapId: bool dict sub_name='mailboxIds', doc="The set of Mailbox ids this Email belongs to. An " "Email in the mail store MUST belong to one or more Mailboxes " "at all times (until it is destroyed). The set is represented " "as an object, with each key being a Mailbox id. The value " "for each key in the object MUST be true." )), ('keywords', AnyDict( # this is supposed to be a str: bool dict sub_name='keywords', doc="(default: {}) A set of keywords that apply " "to the Email. The set is represented as an object, with the " "keys being the keywords. The value for each key in the " "object MUST be true." )), ('size', UnsignedInteger( sub_name='size', doc="(immutable; server-set) The size, in octets, " "of the raw data for the message [@!RFC5322] (as referenced " "by the blobId, i.e., the number of octets in the file the " "user would download)." )), ('received_at', UtcDate( default_factory=lambda: datetime.utcnow().replace(tzinfo=pytz.utc) .isoformat(), sub_name='receivedAt', doc="(immutable; default: time of creation on server) The " "date the Email was received by the message store. This is " "the internal date in IMAP [@?RFC3501]." )), # # Header fields # ('message_id', Array(Unicode, sub_name='messageId', doc="(immutable) The value is identical to the " "value of header:Message-ID:asMessageIds. For messages " "conforming to RFC 5322 this will be an array with a single " "entry." )), ('in_reply_to', Array(Unicode, sub_name='inReplyTo', doc="(immutable) The value is identical to the " "value of header:In-Reply-To:asMessageIds." )), ('references', Array(Unicode, sub_name='references', doc="(immutable) The value is identical to the " "value of header:References:asMessageIds." )), ('sender', Array(EmailAddress, sub_name='sender', doc="(immutable) The value is identical to " "the value of header:Sender:asAddresses." )), ('from_', Array(Unicode, sub_name='from', doc="(immutable) The value is identical to " "the value of header:From:asAddresses." )), ('to', Array(Unicode, sub_name='to', doc="(immutable) The value is identical to " "the value of header:To:asAddresses." )), ('cc', Array(Unicode, sub_name='cc', doc="(immutable) The value is identical to " "the value of header:Cc:asAddresses." )), ('bcc', Array(Unicode, sub_name='bcc', doc="(immutable) The value is identical to " "the value of header:Bcc:asAddresses." )), ('reply_to', Unicode( sub_name='replyTo', doc="(immutable) The value is identical to " "the value of header:Reply-To:asAddresses." )), ('subject', Unicode( sub_name='subject', doc="(immutable) The value is identical to the value " "of header:Subject:asText." )), ('sent_at', DateTime( sub_name='sentAt', doc="(immutable; default on creation: current server " "time) The value is identical to the value of " "header:Date:asDate." )), # # Body Parts # ('body_structure', Array(EmailBodyPart, sub_name='bodyStructure', doc="(immutable) This is the full MIME structure of the message " "body, without recursing into message/rfc822 or message/global " "parts. Note that EmailBodyParts may have subParts if they " "are of type multipart." )), ('body_values', AnyDict( sub_name='bodyValues', doc="(immutable) This is a map of partId to an EmailBodyValue " "object for none, some, or all text parts. Which parts are " "included and whether the value is truncated is determined " "by various arguments to Email/get and Email/parse." )), ('text_body', Array(EmailBodyPart, sub_name='textBody', doc="(immutable) A list of text/plain, text/html, image, audio, " "and/or video parts to display (sequentially) as the message " "body, with a preference for text/plain when alternative " "versions are available." )), ('html_body', Array(EmailBodyPart, sub_name='htmlBody', doc="(immutable) A list of text/plain, text/html, image, audio, " "and/or video parts to display (sequentially) as the message " "body, with a preference for text/html when alternative " "versions are available." )), ('attachments', Array(EmailBodyPart, sub_name='attachments', doc="(immutable) A list, traversing depth-first, " "of all parts in bodyStructure that satisfy either of the " "following conditions:" )), ('has_attachment', M(Boolean( sub_name='hasAttachment', default=False, doc="(immutable; server-set) This is true if there are " "one or more parts in the message that a client UI should " "offer as downloadable. A server SHOULD set hasAttachment to " "true if the attachments list contains at least one item that " "does not have Content-Disposition: inline. The server MAY " "ignore parts in this list that are processed automatically " "in some way or are referenced as embedded images in one of " "the text/html parts of the message." ))), ('preview', Unicode(256, sub_name='preview', default=u'', doc="(immutable; server-set) A plaintext fragment of the " "message body. This is intended to be shown as a preview line " "when listing messages in the mail store and may be truncated " "when shown. The server may choose which part of the message " "to include in the preview; skipping quoted sections and " "salutations and collapsing white space can result in a more " "useful preview." )), ]