예제 #1
0
"""
This is where all the error classes for Lightning are defined.
"""

from __future__ import absolute_import
from lightning.utils import enum
import logging
from pyodbc import Error as SQLError

# Define Service Errors
Error = enum(
    BAD_PARAMETERS='Bad Parameters',
    DUPLICATE_POST='Duplicate post',
    INSUFFICIENT_PERMISSIONS='Insufficient permissions granted',
    INVALID_REDIRECT='Invalid redirect_uri',
    INVALID_TOKEN='Invalid access_token',
    NOT_FOUND='Not found',
    OVER_CAPACITY='Service over capacity',
    RATE_LIMITED='Rate limited',
    REFRESH_TOKEN='Refreshed access_token',
    UNKNOWN_RESPONSE='Unknown response',
)


def error_format(message, **kwargs):
    """Format an error response for the client"""
    kwargs['message'] = message or "Unknown error"
    for x in kwargs.keys():
        if not kwargs[x]:
            del kwargs[x]
    return {'error': kwargs}
예제 #2
0
from lightning.model import LimitedDict
from lightning.utils import enum

# Define Status Codes
StatusCode = enum(
    OK=200,
    NOT_FOUND=404,
    UNKNOWN=502
)
# Define Status Messages
StatusMessage = enum(
    OK="OK",
    NOT_FOUND="GUID not found",
)
# Note: All other Status responses come from lightning.error


class Status(LimitedDict):
    """Status class.
    Represents a Status.
    """
    def __init__(self, *args, **kwargs):
        keys = [
            'code',
            'guid',
            'is_refreshable',
            'message',
            'service_name',
        ]
        super(Status, self).__init__(keys, **kwargs)
예제 #3
0
from lightning.model import LimitedDict
from lightning.utils import enum

# Define Stream Types
StreamType = enum(
    ARTICLE='article',
    PHOTO='photo',
    STATUS='status',
    TRANSACTION='transaction',
    VIDEO='video',
    VIDEO_EMBED='video_embed',
)

def get_type(event):
    """Given a StreamEvent, determine its proper type."""
    # Default to STATUS
    stream_type = StreamType.STATUS

    if event['name'] and event['description']:
        stream_type = StreamType.ARTICLE
    elif event['video_id']:
        stream_type = StreamType.VIDEO_EMBED
    elif event['video_link']:
        stream_type = StreamType.VIDEO
    elif event['picture_link']:
        stream_type = StreamType.PHOTO
    return stream_type


class StreamEvent(LimitedDict):
    """StreamEvent class.