Beispiel #1
0
def load_pref_style(prefname):

    try:
        stylepref = pref(prefname)

        if isinstance(stylepref, basestring):
            style = Storage(Font = makeFont(stylepref))
        else:
            style = Storage(stylepref)
    except Exception:
        print_exc()
        style = {}

    if type(style.Font) is tuple:
        try:
            font = tuple_to_font(style.Font)
        except Exception:
            print_exc()
            font = default_msg_font()
    else:
        font = style.Font
    fgc  = try_this(lambda: wx.Colour(*style.TextColour), None) or wx.BLACK
    bgc  = try_this(lambda: wx.Colour(*style.BackgroundColour), None) or wx.WHITE

    return font, fgc, bgc
Beispiel #2
0
def export_csv(sources, min_date, max_date, place_id_filters, csv_path):
    if min_date:
        min_date = from_utc(min_date)
        max_date = from_utc(max_date)

        place_id_to_timestamps = Storage().load_sources(sources, min_timestamp=min_date, max_timestamp=max_date)
        export_place_id_to_timestamps_csv(place_id_to_timestamps, min_date, csv_path, place_id_filters=place_id_filters)

    else:
        existing_dates = set()
        for root, dirs, files in os.walk(csv_path):
            for fn in files:
                if fn.endswith(".csv"):
                    try:
                        existing_dates.add(
                            datetime.datetime.strptime(fn[:10], "%Y-%m-%d").date()
                        )
                    except ValueError:
                        pass

        yesterday = to_utc(datetime.datetime.now() - datetime.timedelta(days=1)).date()
        current_date = datetime.date(2020, 3, 24)  # my earliest records
        print(f"exporting {current_date} - {yesterday}")
        print(f"already existing: {existing_dates}")

        while current_date <= yesterday:
            if current_date not in existing_dates:
                min_date = datetime.datetime(current_date.year, current_date.month, current_date.day)
                max_date = min_date + datetime.timedelta(days=1) - datetime.timedelta(seconds=1)

                place_id_to_timestamps = Storage().load_sources(sources, min_timestamp=min_date, max_timestamp=max_date)
                export_place_id_to_timestamps_csv(
                    place_id_to_timestamps, min_date, csv_path, place_id_filters=place_id_filters
                )
            current_date += datetime.timedelta(days=1)
Beispiel #3
0
    def _update_ccard_album(self, elt):
        photos = []
        for subel in elt:
            if subel._attrs.get('type', '') == 'Photo':
                photos.append(Storage((e._name, e._cdata) for e in subel))

        album = self.space.setdefault('album',Storage())
        album.update((e._name, e._cdata) for e in elt if 'type' not in e._attrs)
        album.photos = photos
Beispiel #4
0
    def _update_ccard_musiclist(self, elt):
        musiclist = self.space.setdefault('musiclist', Storage())
        songs = []

        for song in elt:
            if song._attrs.get('type', '') == 'MusicListEntry':
                songs.append(Storage((e._name, e._cdata) for e in song))

        musiclist.update((e._name, e._cdata) for e in elt if 'type' not in e._attrs)
        musiclist.songs = songs
Beispiel #5
0
    def _update_ccard_profile(self, elt):
        profiles = self.space.setdefault('profiles',Storage())

        for profile in elt:
            p_type = profile._attrs.get('type','')
            if p_type.endswith('Profile'):
                prof = profiles.setdefault(p_type.lower()[:-7], Storage())
                prof.update((e._name, e._cdata) for e in profile)

        profiles.update((e._name, e._cdata) for e in elt if 'type' not in e._attrs)
Beispiel #6
0
    def _update_ccard_booklist(self, elt):
        booklist = self.space.setdefault('booklist',Storage())
        books = []

        for book in elt:
            if book._attrs.get('type','') == 'BookListEntry':
                books.append(Storage((e._name, e._cdata) for e in book))

        booklist.update((e._name, e._cdata) for e in elt if 'type' not in e._attrs)
        booklist.books = books
Beispiel #7
0
    def _update_ccard_blog(self, elt):
        blog = self.space.setdefault('blog',Storage())

        posts = []

        for post in elt:
            if post._attrs.get('type','') == 'Post':
                posts.append(Storage((e._name, e._cdata) for e in post))

        blog.update((e._name, e._cdata) for e in elt if 'type' not in e._attrs)
        blog.posts = posts
Beispiel #8
0
    def _update_ccard_genericlist(self, elt):
        gen_lists = self.space.setdefault('gen_lists', [])

        entries = []
        for entry in elt:
            if entry._attrs.get('type','') == 'GenericListEntry':
                entries.append(Storage((e._name, e._cdata) for e in entry))

        new_list = Storage((e._name, e._cdata) for e in elt if 'type' not in e._attrs)
        new_list.entries = entries
        gen_lists.append(new_list)
Beispiel #9
0
    def __init__(self, profile):
        Observable.__init__(self)

        self.accounts_loaded = False

        self.profile = profile
        self.connected_accounts = ObservableList()
        self.reconnect_timers   = {}

        # holds "cancel" objects from Popups
        self.cancellers = {}

        self.profile.add_observer(self.on_state_change,   'state')
        self.profile.add_observer(self.on_offline_change, 'offline_reason')
        self.profile.add_observer(self.profile_state_changed, 'state')

        import wx
        wx.GetApp().OnBuddyListShown.append(lambda *a, **k: Timer(.25,
            threaded(self.release_accounts), *a, **k).start())

        self._hash = sentinel

        self.got_accounts = False

        self.acct_calls = Delegate()
        self.delay_accounts = True
        self.acct_delay_lock = RLock()

        self._all_acct_hash = {}
        self.last_server_order = None

        self._all_accounts = Storage()
        for type_ in ('im', 'em', 'so'):

            s = Storage(accounts = ObservableList(),
                        old = [])

            setattr(self._all_accounts, type_, s)

            # when the order of accounts changes, or accounts are added or deleted,
            # calls profile.accounts_changed('im', list)
            s.accounts.add_observer(getattr(self, type_ + '_accounts_changed'))

        self.accounts = self._all_accounts.im.accounts
        self.emailaccounts = self._all_accounts.em.accounts
        self.socialaccounts = self._all_accounts.so.accounts

        self.buddywatcher = BuddyWatcher()

        import services.service_provider as sp
        container = sp.ServiceProviderContainer(self.profile)
        container.on_order_changed += self._set_order
Beispiel #10
0
    def __init__(self, name, status = None, protocol = 'aim', capabilities=None):
        Observable.__init__(self)
        self.remote_alias = self.name = name

        self.mockprofile       = getattr(MockProfiles,name,'')
        self.buddy             = Storage()
        self.buddy.name        = name
        self.buddy.nice_name   = name
        self.buddy.profile     = self.mockprofile
        self.icon              = skin.get('BuddiesPanel.BuddyIcons.NoIcon')
        self.icon_path         = self.icon.path
        self.icon = self.icon.PIL
        self.id                = 5
        self.status_message    = random.choice(status_messages)
        self.sightly_status    = self.status_orb = self.status = status if status else random.choice(statuses)
        self.buddy.away        = self.status=='away'

        self.protocol          = MockProtocol(protocol)
        self.protocol.icq      = random.choice([True, False])
        self.protocol.username = self.protocol.name

        self.mockcaps          = capabilities if capabilities else [caps.BLOCKABLE, caps.EMAIL, caps.FILES, caps.IM, caps.PICTURES, caps.SMS]
        self.online_time       = None
        self.buddy.protocol    = self.protocol
        self.caps              = self.mockcaps
Beispiel #11
0
    def get_iterator(self):
        iterator_info = Storage(id=self.id,
                                context=self.context,
                                iterator=self.get_feed_items())

        # allow plugins to wrap/transform the generator
        return hooks.reduce('social.feed.iterator', iterator_info).iterator
Beispiel #12
0
    def info_email(self, info):
        info.update(Storage(updatefreq = int(self.updatefreq.Value)*60))

        if hasattr(self, 'mailclient'):
            assert isinstance(self.mailclient, basestring)
            info.update(dict(mailclient = self.mailclient,
                             custom_inbox_url = self.custom_inbox_url,
                             custom_compose_url = self.custom_compose_url))

        if hasattr(self, 'emailserver'):
            # email server information
            servertype = self.protocolinfo.needs_server.lower()
            info.update({servertype + 'server': self.emailserver.Value,
                         servertype + 'port' : int(self.emailport.Value) \
                             if self.emailport.Value else '',
                         'require_ssl': self.require_ssl.Value})

            if hasattr(self, 'smtp_server'):
                info.update(email_address     = self.email_address.Value,
                            smtp_server       = self.smtp_server.Value,
                            smtp_port         = int(self.smtp_port.Value) if self.smtp_port.Value else '',
                            smtp_require_ssl  = self.smtp_require_ssl.Value)

                if self.smtp_same.Value:
                    info.update(smtp_username = self.name.Value,
                                smtp_password = self.password.Value)
                else:
                    info.update(smtp_username = self.smtp_username.Value,
                                smtp_password = self.smtp_password.Value)
Beispiel #13
0
def benchmark(fbdata):
    from util import Storage
    account = Storage(protocol='fb20',
                      connection=Storage(last_stream=fbdata['stream'],
                                         last_alerts=fbdata['alerts'],
                                         last_status=fbdata['status']))

    from fb20.fbacct import FBIB

    def doit():
        before = clock()
        FBIB(account, cache=False).get_html(None)
        return clock() - before

    print 'first ', doit()
    print 'second', doit()
Beispiel #14
0
def get_SI2_anchor(image):
    retval = Storage()
    if hasattr(image, 'offset'):
        retval['offset'] = image.offset
    if hasattr(image, 'valign'):
        retval['valign'] = image.valign
    if hasattr(image, 'halign'):
        retval['halign'] = image.halign
    return retval
 def __init__(self, mqtt_client: MQTTClient,
              device_sessions: typing.Dict[str, Session]):
     super().__init__(name="discovery", daemon=True)
     self.__mqtt_client = mqtt_client
     self.__device_sessions = device_sessions
     self.__device_pool: typing.Dict[str, Device] = dict()
     self.__publish_flag = False
     self.__lock = threading.Lock()
     self.__local_storage = Storage(conf.Discovery.db_path, "devices",
                                    (Discovery.__devices_table, ))
Beispiel #16
0
def make_format_storage(font, fgc, bgc):
    return Storage(backgroundcolor = bgc,
                   foregroundcolor = fgc,
                   face            = font.FaceName,
                   size            = font.PointSize,
                   underline       = font.Underlined,
                   bold            = font.Weight == wx.BOLD,
                   italic          = font.Style == wx.ITALIC,
                   family          = FamilyNameFromFont(font),
                   )
Beispiel #17
0
 def encoder(fmtstr):
     singleformat = fmtstr.format_as('singleformat')
     if singleformat is not None:
         from gui.uberwidgets.formattedinput2.fontutil import StorageToStyle
         formatstorage = singleformat['format']
         if not isinstance(formatstorage, Storage):
             formatstorage = Storage(formatstorage)
         textattr = StorageToStyle(formatstorage)
         return RTFToX().Convert(singleformat['text'], fmt, 'plaintext',
                                 textattr)
Beispiel #18
0
def find_attachments(email):
    attachments = {}

    for part in email:
        if (('Content-Disposition' in part.keys())
                and ('attachment' in part['Content-Disposition'])):
            attachments[part.get_filename()] = Storage(
                data=part.get_payload(decode=True),
                content_type=part.get_content_type())

    return attachments
Beispiel #19
0
    def __init__(self, client, io_loop=None):
        self.client = client
        self.client_config = client.client_config
        self._io_loop = io_loop or IOLoop.current()

        self.stream = None
        self._connection_timeout_handler = None

        self._header_data = None
        self._body_data = None
        self._message = Storage()
Beispiel #20
0
 def handle_packet(self, pkt, session):
     from util import Storage
     header = Storage()
     header.command = int(pkt['Command'])
     header.status = int(pkt['Status'])
     account_id, session_id = session['SessionId'].split('-', 1)
     self.account_id = account_id
     header.session_id = self.session_id = int(session_id)
     data = pkt._cdata.strip().encode('utf-8')
     YahooConnectionBase.handle_packet(self, header, data)
     if header.command == 241 and header.status == 0:
         self.server_update()
Beispiel #21
0
    def info(self):
        'Returns a Storage containing the attributes edited by this dialog.'

        info = Storage(name = self.name.Value,
                       protocol = self.protocol_name)

        info.protocol, info.name = strip_acct_id(info.protocol, info.name)

        if hasattr(self, 'password'):
            info.password_len = len(self.password.Value)
            try:
                info.password = profile.crypt_pw(self.password.Value)
            except UnicodeEncodeError:
                # the database has corrupted the password.
                log.warning('corrupted password')
                info.password = ''
                self.password.Value = ''
                import hub
                hub.get_instance().on_error('This account\'s password has been corrupted somehow. Please report it immediately.')

        if hasattr(self, 'host'):
            info.server = (self.host.Value, int(self.port.Value) if self.port.Value else '')

        if hasattr(self, 'remote_alias'):
            info.remote_alias = self.remote_alias.Value

        if hasattr(self, 'autologin'):
            info.autologin = bool(self.autologin.Value)

        if hasattr(self, 'resource'):
            info.update(resource = self.resource.Value,
                        priority = try_this(lambda: int(self.priority.Value), DEFAULT_JABBER_PRIORITY))
#                        ,
#                        confserver = self.confserver.Value
        if hasattr(self, 'dataproxy'):
            info.update(dataproxy = self.dataproxy.Value)

        for d in getattr(self.protocolinfo, 'more_details', []):
            attr = d['store']
            ctrl = getattr(self, attr)
            info[attr] = ctrl.Value

        getattr(self, 'info_' + self.formtype, lambda *a: {})(info)

        for info_cb in self.info_callbacks:
            info_cb(info)

        defaults = self.protocolinfo.get('defaults', {})
        for k in defaults:
            if k not in info:
                info[k] = getattr(self.account, k, defaults.get(k))

        return info
Beispiel #22
0
def StyleToStorage(textattr):

    font = textattr.Font

    return Storage(backgroundcolor=tuple(textattr.BackgroundColour),
                   foregroundcolor=tuple(textattr.TextColour),
                   family=FamilyNameFromFont(font),
                   face=font.FaceName,
                   size=font.PointSize,
                   underline=font.Underlined,
                   bold=font.Weight == wx.BOLD,
                   italic=font.Style == wx.ITALIC)
Beispiel #23
0
    def __init__(self, name, url, whenDoneCB, onCancelCB, onErrorCB):

        self.whenDoneCB = whenDoneCB
        self.onCancelCB = onCancelCB
        self.onErrorCB = onErrorCB

        from gui import skin
        protocol = None
        buddy = Storage(name="Digsby Servers",
                        alias="Digsby Servers",
                        serviceicon=skin.get('serviceicons.digsby'))

        IncomingHTTPFileTransfer.__init__(self, protocol, buddy, name, url)
Beispiel #24
0
    def GetStyleAsStorage(self):
        tc = self.tc
        font = tc.Font

        return Storage(
            backgroundcolor = tuple(tc.BackgroundColour),
            foregroundcolor = tuple(tc.ForegroundColour),
            family = FamilyNameFromFont(font),
            face = font.FaceName,
            size = font.PointSize,
            underline = font.Underlined,
            bold = font.Weight == wx.BOLD,
            italic = font.Style == wx.ITALIC)
Beispiel #25
0
    def __init__(self, images):
        self.images = images
        self.tags = {}
        self.drawrects = {}

        # record anchors
        for image in self.images:
            if hasattr(image, 'anchors'):
                for anchor in image.anchors:
                    if 'tag' in anchor and anchor['tag'] is not None:
                        self.tags[anchor['tag']] = image

        self.cached_result = Storage(bitmap=None, size=(0, 0))
Beispiel #26
0
def main():
    app = testapp()

    import cPickle

    fbdata_file = os.path.join(os.path.dirname(__file__), r'fbdata.dat')
    fbdata = cPickle.loads(open(fbdata_file, 'rb').read())

    from util import Storage
    account = Storage(protocol='fb20',
                      connection=Storage(last_stream=fbdata['stream'],
                                         last_alerts=fbdata['alerts'],
                                         last_status=fbdata['status']))

    from fb20.fbacct import FBIB

    def doit():
        before = clock()
        FBIB(account).get_html(None)
        return clock() - before

    print 'first ', doit()
    print 'second', doit()
Beispiel #27
0
    def __init__(self):
        Observable.__init__(self)

        bud = MockBuddy('fakebuddy')

        self.name = 'fakebuddy'
        self.me = MockBuddy('digsby007')

        self.room_list = ObservableList([bud, self.me])
        self.typing_status = ObservableDict()
        self.buddy = bud
        self.messages = Queue()
        self.protocol = Storage(self_buddy=self.me,
                                buddies={'digsby007': self.me})
        self.ischat = False
Beispiel #28
0
class OFTHeader(Packable):
    fmt = strlist('''
        protocol_version 4s  # Always 'OFT2'
        length           H   # includes all data, including version and length
        type             H   # one of "types" below
    ''')

    invars = [lambda self: self.protocol_version == 'OFT2',
              lambda self: self.type in self.types.values()]

    types = Storage(prompt          = 0x0101,
                    ack             = 0x0202,
                    done            = 0x0204,
                    receiver_resume = 0x0205,
                    sender_resume   = 0x0106,
                    rcv_resume_ack  = 0x0207,
                    )
Beispiel #29
0
    def __init__(self,
                 host,
                 port,
                 af=socket.AF_INET,
                 connect_timeout=0.2,
                 waiting_timeout=0.2,
                 request_timeout=2):
        self.host = host
        self.port = port
        self.af = af
        self.connect_timeout = connect_timeout
        self.waiting_timeout = waiting_timeout
        self.request_timeout = request_timeout

        self.request_message = Storage()
        self._request_callback = None
        self._user_request_callback = None
Beispiel #30
0
        def _f(_message):
            log.debug("Request Message {}".format(_message.__dict__))

            status = _message.topic
            content = _message.body
            if status == RESPONSE_ERROR_TAG:
                raise gen.Return(content)

            if not content:
                raise gen.Return(content)

            v = content
            try:
                v = Storage(json.loads(content))
            except:
                v = content
            raise gen.Return(v)