当前位置: 首页>>代码示例>>Python>>正文


Python DB.error方法代码示例

本文整理汇总了Python中kyotocabinet.DB.error方法的典型用法代码示例。如果您正苦于以下问题:Python DB.error方法的具体用法?Python DB.error怎么用?Python DB.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kyotocabinet.DB的用法示例。


在下文中一共展示了DB.error方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dbOpen

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
 def dbOpen(name):
     db = DB()
     if self.create:
         # if not db.open(abspath(self.path) + '/' + name + ".kch",
         #         DB.OWRITER | DB.OCREATE | DB.OAUTOSYNC | DB.OAUTOTRAN):
         if not db.open(abspath(self.path) + "/" + name + ".kch", DB.OWRITER | DB.OCREATE):
             raise IOError("open error: " + str(db.error()))
         return db
     else:
         # if not db.open(abspath(self.path) + '/' + name + ".kch",
         #         DB.OWRITER | DB.OAUTOSYNC | DB.OAUTOTRAN):
         if not db.open(abspath(self.path) + "/" + name + ".kch", DB.OWRITER):
             raise IOError("open error: " + str(db.error()))
         return db
开发者ID:agarrido,项目名称:ro-manager,代码行数:16,代码来源:KyotoCabinet.py

示例2: dbOpen

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
 def dbOpen(name):
     db = DB()
     dbpathname = abspath(self.path) + '/' + name + ".kch"
     if self.create:
         # if not db.open(abspath(self.path) + '/' + name + ".kch", 
         #         DB.OWRITER | DB.OCREATE | DB.OAUTOSYNC | DB.OAUTOTRAN):
         if not db.open(dbpathname, DB.OWRITER | DB.OCREATE):
             raise IOError("open error: %s %s" % (dbpathname, str(db.error())))  #pragma: NO COVER
         return db
     else:
         # if not db.open(abspath(self.path) + '/' + name + ".kch", 
         #         DB.OWRITER | DB.OAUTOSYNC | DB.OAUTOTRAN):
         if not db.open(dbpathname, DB.OWRITER):  #pragma: NO COVER
             raise IOError("open error: %s %s" % (dbpathname, str(db.error())))  #pragma: NO COVER
         return db
开发者ID:pebbie,项目名称:rdflib-kyotocabinet,代码行数:17,代码来源:KyotoCabinet.py

示例3: get_page_count

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
def get_page_count(item_filter = lambda x: True):
    count = 0
    db = DB()
    db_file = current_app.config['DB_FILE']
    if not db.open("{0}".format(db_file), DB.OREADER | DB.OWRITER | DB.OCREATE):
        print "Could not open database (get_page_count). Error: {}".format(db.error())

    cur = db.cursor()
    cur.jump_back()
    while True:
        rec = cur.get(False)
        if not rec:
            break

        if item_filter(rec):
            count = count + 1

        cur.step_back()

    cur.disable()
    db.close()
    return count / FILTER_MAX
开发者ID:lykkin,项目名称:merveilles_io,代码行数:24,代码来源:database.py

示例4: main

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
def main():
    db_file = argv[1]
    username = argv[2]

    if not db_file and not username:
        print "Need db_file and username."
        return -1

    db = DB()
    if not db.open("{0}".format(db_file), DB.OWRITER):
        print "Could not open database."
        return -1

    all_keys = []
    cur = db.cursor()
    cur.jump()
    while True:
        rec = cur.get(False)
        if not rec:
            break

        loaded = loads(rec[1])
        if loaded["person"] == username:
            all_keys.append(cur.get_key())

        cur.step()
    cur.disable()

    print "Found {} records.".format(len(all_keys))
    for key in all_keys:
        print "Pending {}...".format(key)
        if len(argv) > 3 and argv[3] == '--delete':
            print "Removing {}...".format(key)
            if not db.remove(key):
                print "Could not remove key: {}".format(db.error())

    db.close()
开发者ID:lykkin,项目名称:merveilles_io,代码行数:39,代码来源:expunge_user.py

示例5: FeatureSelector

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
class FeatureSelector( Frontend ):


  def __init__( self, fn, mode ):    

    Frontend.__init__( self, fn, mode );

    self._kdbfn = None;
    self._kdb = None;

    self._ldbdn = None;
    self._ldb = None;

    self._len_c = None;
    self._len_b = None;
    self._len_x = None;

    self._ic = None;
    self._icbp = None;

    self._needs_initialization = True;

    self._core_dims = set();
    self._satellite_dims = set();
    self._removed_dims = set();

    self._remove_c = set();
    self._remove_b = set();
    self._remove_x = set();

    self.bypass_c = False;
    self.bypass_b = False;
    self.bypass_x = False;


  def __enter__( self ):

    if self._mode == "r":
      with open( self._fn, "rb" ) as f:
        state = pickle_load( f );
        self._len_c = state[ "c" ];
        self._len_b = state[ "b" ];
        self._len_x = state[ "x" ];
        self._lenrow = self._len_c + self._len_b + self._len_x;
        self._ic = state[ "ic" ];
        self._icbp = state[ "icbp" ];

    if self._mode == "w":

      with NamedTemporaryFile() as tmpfn:
        self._kdbfn = tmpfn.name + '.kch';
      self._kdb = KDB();
      try:
        assert self._kdb.open( self._kdbfn, KDB.OWRITER | KDB.OCREATE );
      except:
        print( str( self._kdb.error() ) );
        raise;

      with TemporaryDirectory() as tmpdirname:
        self._ldbdn = tmpdirname;
      self._ldb = LDB( self._ldbdn, create_if_missing=True );

    return self;

  def __exit__( self, exc_type, exc_value, traceback ):

    assert Frontend.__exit__( self, exc_type, exc_value, traceback ) == False;

    if self._ldb is not None:
      sleep( 3.0 );
      self._ldb.close()

    if self._ldbdn is not None:
      rmtree( self._ldbdn );

    if self._kdb is not None:
      try:
        assert self._kdb.close();
      except:
        print( str( self._kdb.error() ) );
        raise;

    if self._kdbfn is not None:
      remove( self._kdbfn );


  def train( self, row ):

    ( y, c, b, x ) = row;

    if self._len_c is None:
      self._len_c = len(c);
    assert self._len_c == len(c);

    if self._len_b is None:
      self._len_b = len(b);
    assert self._len_b == len(b);

    if self._len_x is None:
      self._len_x = len(x);
#.........这里部分代码省略.........
开发者ID:rbergmair-utopiarefraktor,项目名称:recruitment_challenge,代码行数:103,代码来源:fe_fselector.py

示例6: insert_item

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
def insert_item(url, person, db_file, submitted_title=''):
    mimetype = "application/json"
    db = DB()

    if not db.open("{0}".format(db_file),
        DB.OWRITER | DB.OCREATE):

        response = {}
        response['What happened?'] = "Couldn't open the damn database. Error: {0}".format(db.error())
        return Response(dumps(response), mimetype=mimetype)

    if is_url_in_db(db, url):
        return Response('{"What happened?": "Someone '\
            'tried to submit a duplicate URL."}',
            mimetype=mimetype)

    title = url
    summary = "~?~"
    try:
        thing = urlopen(url, timeout=10)
        soup = BeautifulSoup(thing)
        title = soup.title.string
        # Do some dumb summarizing if we can
        def concat(a, v):
            return a + " " + v.strip()
        visible_stuff = filter(visible, soup.findAll(text=True))
        summary = reduce(concat, visible_stuff, "")[:900] + "..."
    except:
        pass
        #return Response('{"What happened?": '\
        #    'I dunno bs4 messed up somehow."}',
        #    mimetype=mimetype)

    created_at = int(mktime(datetime.now().utctimetuple()))

    is_image = url.lower().endswith(("jpg", "jpeg", "gif", "png"))
    thumbnail = gen_thumbnail_for_url(url, str(created_at))

    record = {
        "created_at": created_at,
        "title": title,
        "url": url,
        "person": person,
        "summary": summary,
        "person_color": PERSON_COLORS[random.randint(0, len(PERSON_COLORS)-1)],
        "is_image": is_image,
        "thumbnail": thumbnail,
        "comment": submitted_title
    }
    db.set(created_at, dumps(record))
    db.close()

    return Response('{"What happened?": "MUDADA"}',
        mimetype=mimetype)
开发者ID:lykkin,项目名称:merveilles_io,代码行数:56,代码来源:database.py

示例7: BKNNModel

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
class BKNNModel( Model ):


  def __init__( self, fn, mode, catfe, binfe, contfe, fdisc, fsel, kval ):

    Model.__init__( self, fn, mode, catfe, binfe, contfe, fdisc, fsel );

    self._kval = kval;

    self._fn_cdata = self._fn;
    self._fn_ddata = self._fn.replace( '.kch', '-discrete.kch' );
    self._fn_meta = self._fn.replace( '.kch', '-meta.pickle' );
    self._fn_icov = self._fn.replace( '.kch', '-icov.pickle' );

    self._cdata = None;
    self._ddata = None;

    self._len_c = None;
    self._len_b = None;
    self._len_x = None;

    self._rowcount = None;
    self._total_pos = None;
    self._total_neg = None;

    self._icov = None;
    self._co = None;

    self._sample_y = [];
    self._sample_c = [];
    self._sample_b = [];
    self._sample_x = [];
    self._sample_x_ = [];

    self._needs_finalization = False;
    self._needs_initialization = True;

    self._dmarginals = {};
    self._dscores = {};

    self._sparse_points = 0;

    self._bias = None;


  def __enter__( self ):

    self._cdata = DB();
    self._ddata = DB();

    try:
      if self._mode == "r":
        assert self._cdata.open( self._fn_cdata, DB.OREADER );
      elif self._mode == "w":
        if isfile( self._fn_cdata ):
          remove( self._fn_cdata );
        assert self._cdata.open( self._fn_cdata, DB.OWRITER | DB.OCREATE );
      else:
        assert False;
    except:
      if self._cdata is not None:
        print( str( self._cdata.error() ) );
      raise;

    try:
      if self._mode == "r":
        assert self._ddata.open( self._fn_ddata, DB.OREADER );
      elif self._mode == "w":
        if isfile( self._fn_ddata ):
          remove( self._fn_ddata );
        assert self._ddata.open( self._fn_ddata, DB.OWRITER | DB.OCREATE );
      else:
        assert False;
    except:
      if self._ddata is not None:
        print( str( self._ddata.error() ) );
      raise;

    if self._mode == "r":

      with open( self._fn_meta, 'rb' ) as f:
        r = pickle_load( f );
        self._len_c = r[ "c" ];
        self._len_b = r[ "b" ];
        self._len_x = r[ "x" ];
        self._co = r[ "co" ];

      with open( self._fn_icov, 'rb' ) as f:
        self._icov = pickle_load( f );

    return self;


  def __exit__( self, exc_type, exc_value, traceback ):

    ex_w_exc = False;
    ex_w_exc = ex_w_exc or ( exc_type is not None );
    ex_w_exc = ex_w_exc or ( exc_value is not None );
    ex_w_exc = ex_w_exc or ( traceback is not None );

#.........这里部分代码省略.........
开发者ID:rbergmair-utopiarefraktor,项目名称:recruitment_challenge,代码行数:103,代码来源:mdl_bknn.py

示例8: DataStorage

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
class DataStorage(object):
    """
    Parent class for RowData and KeyValueData.
    """

    def __init__(self, filename, headers=None):
        self.filename = filename
        self.ext = os.path.splitext(filename)[1]
        self.headers = headers

        if os.path.exists(self.filename):
            self.init_read()
        else:
            self.init_write()

    def init_write(self):
        self.mode = "write"

        if self.ext == ".csv":
            self._data_file = open(self.filename, "wb")
            self._writer = csv.writer(self._data_file)
            if self.headers:
                self._writer.writerow(self.headers)

        elif self.ext == ".json":
            self._storage = {}

        elif self.ext == ".kch":
            from kyotocabinet import DB

            self._storage = DB()
            if not self._storage.open(self.filename, DB.OWRITER | DB.OCREATE):
                msg = "Error opening kyotocabinet db: %s" % (self._storage.error())
                raise dexy.commands.UserFeedback(msg)

        elif self.ext == ".sqlite3":
            self.init_write_sqlite3()

        else:
            raise dexy.commands.UserFeedback("unsupported extension %s" % self.ext)

    def init_read(self):
        self.mode = "read"

        if self.ext == ".csv":
            self._file = open(self.filename, "rb")
        elif self.ext == ".json":
            with open(self.filename, "rb") as f:
                self._storage = json.load(f)
        elif self.ext == ".kch":
            from kyotocabinet import DB

            self._storage = DB()
            self._storage.open(self.filename, DB.OREADER)
        elif self.ext == ".sqlite3":
            import sqlite3

            self._storage = sqlite3.connect(self.filename)
            self._cursor = self._storage.cursor()
        else:
            raise dexy.commands.UserFeedback("unsupported extension %s" % self.ext)

    def save(self):
        if self.ext == ".csv":
            self._data_file.close()
        elif self.ext == ".json":
            with open(self.filename, "wb") as f:
                import json

                json.dump(self._storage, f)
        elif self.ext == ".kch":
            if not self._storage.close():
                raise dexy.commands.UserFeedback(self._storage.error())
        elif self.ext == ".sqlite3":
            self._storage.commit()
            self._cursor.close()
        else:
            raise dexy.commands.UserFeedback("unsupported extension %s" % self.ext)
开发者ID:viesrood,项目名称:dexy,代码行数:80,代码来源:helpers.py

示例9: format_datetime

# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import error [as 别名]
from kyotocabinet import DB
import sys,time


#format datetime
def format_datetime(timestamp):
         return time.strftime('%Y.%m.%d @ %H:%M',time.localtime(timestamp))

#创建数据库对象
db=DB()

# open the database
if not db.open("../data/db.kch", DB.OWRITER | DB.OCREATE):
         print >>sys.stderr, "open error: " + str(db.error())


cid='1'

#build for marks form
if not db.set("mark:"+cid+":markid", "1") or\
   not db.set("mark:"+cid+":userid", "1") or\
   not db.set("mark:"+cid+":boardid", "1") or\
   not db.set("mark:"+cid+":fileid", "1") or\
   not db.set("mark:"+cid+":description", "mark的内容描述") or\
   not db.set("mark:"+cid+":content", "哇。。阳光暖暖的,好惬意的。") or\
   not db.set("mark:"+cid+":ups", "100") or\
   not db.set("mark:"+cid+":downs", "10") or\
   not db.set("mark:"+cid+":hits", "110") or\
   not db.set("mark:"+cid+":order", "1") or\
   not db.set("maks:"+cid+":createdata", int(time.time())) or\
   not db.set("maks:"+cid+":commentcount", "8") or\
开发者ID:aviatorBeijing,项目名称:ptpy,代码行数:33,代码来源:model.py


注:本文中的kyotocabinet.DB.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。