def __init__(self,
                 title=None,
                 content=None,
                 guid=None,
                 tags=None,
                 notebookGuid=None,
                 updateSequenceNum=None,
                 whole_note=None,
                 db_note=None):
        """

        :type whole_note: evernote.edam.type.ttypes.Note
        :type db_note: sqlite3.dbapi2.Row
        """

        self.Status = EvernoteAPIStatus.Uninitialized
        self.TagNames = tags
        if whole_note is not None:
            if self.TagNames is None:
                self.TagNames = whole_note.tagNames
            self.Title = EvernoteNoteTitle(whole_note)
            self.Content = whole_note.content
            self.Guid = whole_note.guid
            self.NotebookGuid = whole_note.notebookGuid
            self.UpdateSequenceNum = whole_note.updateSequenceNum
            self.Status = EvernoteAPIStatus.Success
            return
        if db_note is not None:
            self.Title = EvernoteNoteTitle(db_note)
            db_note_keys = db_note.keys()
            for key in [
                    'content', 'guid', 'notebookGuid', 'updateSequenceNum',
                    'tagNames', 'tagGuids'
            ]:
                if not key in db_note_keys:
                    log_error(
                        "FATAL ERROR: Unable to find key %s in db note %s! \n%s"
                        % (key, self.FullTitle, db_note_keys))
                    log(
                        "Values: \n\n" +
                        str({k: db_note[k]
                             for k in db_note_keys}),
                        'EvernoteNotePrototypeInit')
                else:
                    setattr(self, upperFirst(key), db_note[key])
            self.TagNames = decode(self.TagNames)
            self.Content = decode(self.Content)
            self.process_tags()
            self.Status = EvernoteAPIStatus.Success
            return
        self.Title = EvernoteNoteTitle(title)
        self.Content = content
        self.Guid = guid
        self.NotebookGuid = notebookGuid
        self.UpdateSequenceNum = updateSequenceNum
        self.Status = EvernoteAPIStatus.Manual
示例#2
0
def HandleUnicodeError(log_header,
                       e,
                       guid,
                       title,
                       action='',
                       attempt=1,
                       content=None,
                       field=None,
                       attempt_max=3,
                       attempt_min=1):
    global lastUnicodeError
    object = ""
    e_type = e.__class__.__name__
    is_unicode = e_type.find("Unicode") > -1
    if is_unicode:
        content_type = e.object.__class__.__name__
        object = e.object[e.start - 20:e.start + 20]
    elif not content:
        content = "Not Provided"
        content_type = "N/A"
    else:
        content_type = content.__class__.__name__
    log_header += ': ' + e_type + ': {field}' + content_type + (
        ' <%s>' % action if action else '')
    save_header = log_header.replace('{field}', '') + ': ' + title
    log_header = log_header.format(field='%s: ' % field if field else '')

    new_error = lastUnicodeError != save_header

    if is_unicode:
        return_val = 1 if attempt < attempt_max else -1
        if new_error:
            log(save_header + '\n' + '-' * ANKNOTES.FORMATTING.LINE_LENGTH,
                'unicode',
                replace_newline=False)
            lastUnicodeError = save_header
        log(ANKNOTES.FORMATTING.TIMESTAMP_PAD + '\t - ' +
            (('Field %s' % field if field else 'Unknown Field') +
             ': ').ljust(20) + str_safe(object),
            'unicode',
            timestamp=False)
    else:
        return_val = 0
        if attempt is 1 and content:
            log_dump(content, log_header, 'NonUnicodeErrors')
    if (new_error and attempt >= attempt_min) or not is_unicode:
        log_error(log_header +
                  "\n -  Error: %s\n -   GUID: %s\n -  Title: %s%s" %
                  (str(e), guid, str_safe(title),
                   '' if not object else "\n - Object: %s" % str_safe(object)))
    return return_val
示例#3
0
def HandleEDAMRateLimitError(e, strError):
    global latestEDAMRateLimit
    if not e.errorCode is EDAMErrorCode.RATE_LIMIT_REACHED:
        return False
    latestEDAMRateLimit = e.rateLimitDuration
    m, s = divmod(e.rateLimitDuration, 60)
    strError = "Error: Rate limit has been reached while %s\r\n" % strError
    strError += "Please retry your request in {} min".format("%d:%02d" % (m, s))
    log_strError = " EDAMErrorCode.RATE_LIMIT_REACHED:  " + strError.replace('\r\n', '\n')
    log_error(log_strError)
    log(log_strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
示例#4
0
文件: db.py 项目: holycrepe/anknotes
 def executemany(self, sql, data, **kw):
     sql = self._create_query_(sql, **kw)
     log_sql(sql, data, self=self)
     self.mod = True
     t = time.time()
     try:
         self._db.executemany(sql, data)
     except (sqlite.OperationalError, sqlite.ProgrammingError, sqlite.Error, Exception) as e:
         log_sql(sql, data, self=self, filter_disabled=False)
         import traceback
         log_error('Error with ankDB().executemany(): %s\n Query: %s\n Trace: %s' % (str(e), sql, traceback.format_exc()))
         raise
     if self.echo:
         print sql, "%0.3fms" % ((time.time() - t) * 1000)
         if self.echo == "2":
             print data
示例#5
0
def HandleEDAMRateLimitError(e, strError):
    global latestEDAMRateLimit
    if not e.errorCode is EDAMErrorCode.RATE_LIMIT_REACHED:
        return False
    latestEDAMRateLimit = e.rateLimitDuration
    m, s = divmod(e.rateLimitDuration, 60)
    strError = "Error: Rate limit has been reached while %s\r\n" % strError
    strError += "Please retry your request in {} min".format("%d:%02d" %
                                                             (m, s))
    log_strError = " EDAMErrorCode.RATE_LIMIT_REACHED:  " + strError.replace(
        '\r\n', '\n')
    log_error(log_strError)
    log(log_strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
    def __init__(self, title=None, content=None, guid=None, tags=None, notebookGuid=None, updateSequenceNum=None,
                 whole_note=None, db_note=None):
        """

        :type whole_note: evernote.edam.type.ttypes.Note
        :type db_note: sqlite3.dbapi2.Row
        """

        self.Status = EvernoteAPIStatus.Uninitialized
        self.TagNames = tags
        if whole_note is not None:
            if self.TagNames is None:
                self.TagNames = whole_note.tagNames
            self.Title = EvernoteNoteTitle(whole_note)
            self.Content = whole_note.content
            self.Guid = whole_note.guid
            self.NotebookGuid = whole_note.notebookGuid
            self.UpdateSequenceNum = whole_note.updateSequenceNum
            self.Status = EvernoteAPIStatus.Success
            return
        if db_note is not None:
            self.Title = EvernoteNoteTitle(db_note)
            db_note_keys = db_note.keys()
            for key in ['content', 'guid', 'notebookGuid', 'updateSequenceNum', 'tagNames', 'tagGuids']:
                if not key in db_note_keys:
                    log_error(
                        "FATAL ERROR: Unable to find key %s in db note %s! \n%s" % (key, self.FullTitle, db_note_keys))
                    log("Values: \n\n" + str({k: db_note[k] for k in db_note_keys}), 'EvernoteNotePrototypeInit')
                else:
                    setattr(self, upperFirst(key), db_note[key])
            self.TagNames = decode(self.TagNames)
            self.Content = decode(self.Content)
            self.process_tags()
            self.Status = EvernoteAPIStatus.Success
            return
        self.Title = EvernoteNoteTitle(title)
        self.Content = content
        self.Guid = guid
        self.NotebookGuid = notebookGuid
        self.UpdateSequenceNum = updateSequenceNum
        self.Status = EvernoteAPIStatus.Manual
示例#7
0
def HandleSocketError(e, strErrorBase):
    global latestSocketError
    errorcode = e[0]
    friendly_error_msgs = {
        errno.ECONNREFUSED:  "Connection was refused",
        errno.WSAECONNRESET: "Connection was reset or forcibly closed by the remote host",
        errno.ETIMEDOUT:     "Connection timed out"
    }
    if errorcode not in errno.errorcode:
        log_error("Unknown socket error (%s) occurred: %s" % (str(errorcode), str(e)))
        return False
    error_constant = errno.errorcode[errorcode]
    if errorcode in friendly_error_msgs:
        strError = friendly_error_msgs[errorcode]
    else:
        strError = "Unhandled socket error (%s) occurred" % error_constant
    latestSocketError = {'code': errorcode, 'friendly_error_msg': strError, 'constant': error_constant}
    strError = "Error: %s while %s\r\n" % (strError, strErrorBase)
    log_error(" SocketError.%s:  " % error_constant + strError)
    log_error(str(e))
    log(" SocketError.%s:  " % error_constant + strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
示例#8
0
文件: db.py 项目: holycrepe/anknotes
 def execute(self, sql, a=None, kw=None, auto=None, **kwargs):
     if is_dict_type(a):
         kw, a = a, kw
     if not is_seq_type(a):
         a = item_to_list(a)
     if is_dict_type(sql):
         auto = sql
         sql = ' AND '.join(["`{0}` = :{0}".format(key) for key in auto.keys()])
     if kw is None:
         kw = {}
     kwargs.update(kw)
     sql = self._create_query_(sql, **kwargs)
     if auto:
         kw = auto
     log_sql(sql, a, kw, self=self)
     self.ankdb_lastquery = sql
     if self._is_stmt_(sql):
         self.mod = True
     t = time.time()
     try:
         if a:
             # execute("...where id = ?", 5)
             res = self._db.execute(sql, a)
         elif kw:
             # execute("...where id = :id", id=5)
             res = self._db.execute(sql, kw)
         else:
             res = self._db.execute(sql)
     except (sqlite.OperationalError, sqlite.ProgrammingError, sqlite.Error, Exception) as e:
         log_sql(sql, a, kw, self=self, filter_disabled=False)
         import traceback
         log_error('Error with ankDB().execute(): %s\n Query: %s\n Trace: %s' %
                   (str(e), sql, traceback.format_exc()))
         raise
     if self.echo:
         # print a, ka
         print sql, "%0.3fms" % ((time.time() - t) * 1000)
         if self.echo == "2":
             print a, kw
     return res
示例#9
0
def HandleSocketError(e, strErrorBase):
    global latestSocketError
    errorcode = e[0]
    friendly_error_msgs = {
        errno.ECONNREFUSED: "Connection was refused",
        errno.WSAECONNRESET:
        "Connection was reset or forcibly closed by the remote host",
        errno.ETIMEDOUT: "Connection timed out"
    }
    if errorcode not in errno.errorcode:
        log_error("Unknown socket error (%s) occurred: %s" %
                  (str(errorcode), str(e)))
        return False
    error_constant = errno.errorcode[errorcode]
    if errorcode in friendly_error_msgs:
        strError = friendly_error_msgs[errorcode]
    else:
        strError = "Unhandled socket error (%s) occurred" % error_constant
    latestSocketError = {
        'code': errorcode,
        'friendly_error_msg': strError,
        'constant': error_constant
    }
    strError = "Error: %s while %s\r\n" % (strError, strErrorBase)
    log_error(" SocketError.%s:  " % error_constant + strError)
    log_error(str(e))
    log(" SocketError.%s:  " % error_constant + strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
示例#10
0
def HandleUnicodeError(log_header, e, guid, title, action='', attempt=1, content=None, field=None, attempt_max=3,
                       attempt_min=1):
    global lastUnicodeError
    object = ""
    e_type = e.__class__.__name__
    is_unicode = e_type.find("Unicode") > -1
    if is_unicode:
        content_type = e.object.__class__.__name__
        object = e.object[e.start - 20:e.start + 20]
    elif not content:
        content = "Not Provided"
        content_type = "N/A"
    else:
        content_type = content.__class__.__name__
    log_header += ': ' + e_type + ': {field}' + content_type + (' <%s>' % action if action else '')
    save_header = log_header.replace('{field}', '') + ': ' + title
    log_header = log_header.format(field='%s: ' % field if field else '')

    new_error = lastUnicodeError != save_header

    if is_unicode:
        return_val = 1 if attempt < attempt_max else -1
        if new_error:
            log(save_header + '\n' + '-' * ANKNOTES.FORMATTING.LINE_LENGTH, 'unicode', replace_newline=False)
            lastUnicodeError = save_header
        log(ANKNOTES.FORMATTING.TIMESTAMP_PAD + '\t - ' + (
            ('Field %s' % field if field else 'Unknown Field') + ': ').ljust(20) + str_safe(object), 'unicode',
            timestamp=False)
    else:
        return_val = 0
        if attempt is 1 and content:
            log_dump(content, log_header, 'NonUnicodeErrors')
    if (new_error and attempt >= attempt_min) or not is_unicode:
        log_error(log_header + "\n -  Error: %s\n -   GUID: %s\n -  Title: %s%s" % (
            str(e), guid, str_safe(title), '' if not object else "\n - Object: %s" % str_safe(object)))
    return return_val