def __init__(self, name, description, lat, lon, db_cat_id, db_poi_id=None): self.id = db_poi_id # this probably handles some Unicode encoding issues name = u('%s') % name description = u('%s') % description Point.__init__(self, lat, lon, name=name, message=description) self._db_category_index = db_cat_id
def __init__(self, callback, label, description, lat, lon, catId, poiId=None): self.callback = callback self.id = poiId self.lat = lat self.lon = lon self.label = u('%s') % label self.description = u('%s') % description self.categoryId = catId
def encode(self, o): """Return a JSON string representation of a Python data structure. >>> from simplejson import JSONEncoder >>> JSONEncoder().encode({"foo": ["bar", "baz"]}) '{"foo": ["bar", "baz"]}' """ # This is for extremely simple cases and benchmarks. if isinstance(o, binary_type): _encoding = self.encoding if (_encoding is not None and not (_encoding == 'utf-8')): o = o.decode(_encoding) if isinstance(o, string_types): if self.ensure_ascii: return encode_basestring_ascii(o) else: return encode_basestring(o) # This doesn't pass the iterator directly to ''.join() because the # exceptions aren't as detailed. The list call should be roughly # equivalent to the PySequence_Fast that ''.join() would do. chunks = self.iterencode(o, _one_shot=True) if not isinstance(chunks, (list, tuple)): chunks = list(chunks) if self.ensure_ascii: return ''.join(chunks) else: return six.u('').join(chunks)
def encode(self, o): # Override JSONEncoder.encode because it has hacks for # performance that make things more complicated. chunks = self.iterencode(o, True) if self.ensure_ascii: return ''.join(chunks) else: return six.u('').join(chunks)
def isotime(s): """Convert timestamps in ISO8661 format to and from Unix time.""" if type(s) == type(1): return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s)) elif type(s) == type(1.0): date = int(s) msec = s - date date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s)) return date + "." + repr(msec)[3:] elif type(s) == type("") or type(s) == type(six.u("")): if s[-1] == "Z": s = s[:-1] if "." in s: (date, msec) = s.split(".") else: date = s msec = "0" # Note: no leap-second correction! return calendar.timegm(time.strptime(date, "%Y-%m-%dT%H:%M:%S")) + float("0." + msec) else: raise TypeError
def isotime(s): """Convert timestamps in ISO8661 format to and from Unix time.""" if type(s) == type(1): return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s)) elif type(s) == type(1.0): date = int(s) msec = s - date date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s)) return date + "." + repr(msec)[3:] elif type(s) == type("") or type(s) == type(six.u("")): if s[-1] == "Z": s = s[:-1] if "." in s: (date, msec) = s.split(".") else: date = s msec = "0" # Note: no leap-second correction! return calendar.timegm(time.strptime( date, "%Y-%m-%dT%H:%M:%S")) + float("0." + msec) else: raise TypeError
try: from . import _speedups return _speedups.encode_basestring_ascii, _speedups.make_encoder except ImportError: return None, None c_encode_basestring_ascii, c_make_encoder = _import_speedups() from simplejson.decoder import PosInf from core.backports import six #ESCAPE = re.compile(ur'[\x00-\x1f\\"\b\f\n\r\t\u2028\u2029]') # This is required because u() will mangle the string and ur'' isn't valid # python3 syntax ESCAPE = re.compile(six.u('[\\x00-\\x1f\\\\"\\b\\f\\n\\r\\t\u2028\u2029]')) ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])') HAS_UTF8 = re.compile(r'[\x80-\xff]') ESCAPE_DCT = { '\\': '\\\\', '"': '\\"', '\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t', } for i in range(0x20): #ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i)) ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i, )) for i in [0x2028, 0x2029]:
from .compat import u, unichr, binary_type, string_types, integer_types, PY3 def _import_speedups(): try: from . import _speedups return _speedups.encode_basestring_ascii, _speedups.make_encoder except ImportError: return None, None c_encode_basestring_ascii, c_make_encoder = _import_speedups() from simplejson.decoder import PosInf from core.backports import six #ESCAPE = re.compile(ur'[\x00-\x1f\\"\b\f\n\r\t\u2028\u2029]') # This is required because u() will mangle the string and ur'' isn't valid # python3 syntax ESCAPE = re.compile(six.u('[\\x00-\\x1f\\\\"\\b\\f\\n\\r\\t\u2028\u2029]')) ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])') HAS_UTF8 = re.compile(r'[\x80-\xff]') ESCAPE_DCT = { '\\': '\\\\', '"': '\\"', '\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t', } for i in range(0x20): #ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i)) ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,)) for i in [0x2028, 0x2029]:
def create_empty_db(self, db_path): """Create a new database, including tables and initial data :returns: the SQLite connection object """ log.debug("creating new database file in:\n%s", db_path) conn = sqlite3.connect(db_path) # create the category table conn.execute( 'CREATE TABLE category (cat_id integer PRIMARY KEY,label text, desc text, enabled integer)' ) # create the poi table conn.execute( 'CREATE TABLE poi (poi_id integer PRIMARY KEY, lat real, lon real, label text, desc text, cat_id integer)' ) # load the predefined categories # (currently the same ones as in MaemoMapper) defaultCats = [ (1, u('Service Station'), u('Stations for purchasing fuel for vehicles.'), 1), (2, u('Residence'), u('Houses, apartments, or other residences of import.'), 1), (3, u('Restaurant'), u('Places to eat or drink.'), 1), (4, u('Shopping/Services'), u('Places to shop or acquire services.'), 1), (5, u('Recreation'), u('Indoor or Outdoor places to have fun.'), 1), (6, u('Transportation'), u('Bus stops, airports, train stations, etc.'), 1), (7, u('Lodging'), u('Places to stay temporarily or for the night.'), 1), (8, u('School'), u('Elementary schools, college campuses, etc.'), 1), (9, u('Business'), u('General places of business.'), 1), (10, u('Landmark'), u('General landmarks.'), 1), (11, u('Other'), u('Miscellaneous category for everything else.'), 1) ] for cat in defaultCats: conn.execute('insert into category values(?,?,?,?)', cat) # commit the changes conn.commit() log.debug("new database file has been created") return conn
def createDatabase(self, path): """create a new database, including tables and initial data return the connection object""" print("storePOI: creating new database file in:\n%s" % path) conn = sqlite3.connect(path) # create the category table conn.execute('CREATE TABLE category (cat_id integer PRIMARY KEY,label text, desc text, enabled integer)') # create the poi table conn.execute( 'CREATE TABLE poi (poi_id integer PRIMARY KEY, lat real, lon real, label text, desc text, cat_id integer)') # load the predefined categories # (currently the same ones as in MaemoMapper) defaultCats = [(1, u('Service Station'), u('Stations for purchasing fuel for vehicles.'), 1), (2, u('Residence'), u('Houses, apartments, or other residences of import.'), 1), (3, u('Restaurant'), u('Places to eat or drink.'), 1), (4, u('Shopping/Services'), u('Places to shop or acquire services.'), 1), (5, u('Recreation'), u('Indoor or Outdoor places to have fun.'), 1), (6, u('Transportation'), u('Bus stops, airports, train stations, etc.'), 1), (7, u('Lodging'), u('Places to stay temporarily or for the night.'), 1), (8, u('School'), u('Elementary schools, college campuses, etc.'), 1), (9, u('Business'), u('General places of business.'), 1), (10, u('Landmark'), u('General landmarks.'), 1), (11, u('Other'), u('Miscellaneous category for everything else.'), 1)] for cat in defaultCats: conn.execute('insert into category values(?,?,?,?)', cat) # commit the changes conn.commit() print("storePoi: new database file has been created") return conn
def setDescription(self, newDescription, commit=True): self.description = u('%s') % newDescription if commit: self.storeToDb()
def setName(self, newLabel, commit=True): self.label = u('%s') % newLabel if commit: self.storeToDb()