def toUnicode(s): """Convert a binary string to Unicode using UTF-8 (fallback to ISO-8859-1).""" try: u = compat.to_unicode(s, "utf8") except ValueError: log("toUnicode(%r) *** UTF-8 failed. Trying ISO-8859-1" % s) u = compat.to_unicode(s, "ISO-8859-1") return u
def toUnicode(s): """Convert a binary string to Unicode using UTF-8 (fallback to ISO-8859-1).""" try: u = compat.to_unicode(s, "utf8") except ValueError: _logger.error("toUnicode({!r}) *** UTF-8 failed. Trying ISO-8859-1".format(s)) u = compat.to_unicode(s, "ISO-8859-1") return u
def to_unicode_safe(s): """Convert a binary string to Unicode using UTF-8 (fallback to ISO-8859-1).""" try: u = compat.to_unicode(s, "utf8") except ValueError: _logger.error( "to_unicode_safe({!r}) *** UTF-8 failed. Trying ISO-8859-1".format(s) ) u = compat.to_unicode(s, "ISO-8859-1") return u
class Lock(object): __tablename__ = 'my_locks' token = Column(UnicodeText, primary_key=True, unique=True, nullable=False) depth = Column(Unicode(32), unique=False, nullable=False, default=to_unicode('infinity')) root = Column(UnicodeText, unique=False, nullable=False) type = Column(Unicode(32), unique=False, nullable=False, default=to_unicode('write')) scope = Column(Unicode(32), unique=False, nullable=False, default=to_unicode('exclusive')) owner = Column(UnicodeText, unique=False, nullable=False) expire = Column(Float, unique=False, nullable=False) principal = Column(Unicode(255), ForeignKey('my_users.display_name', ondelete="CASCADE")) timeout = Column(Float, unique=False, nullable=False)
def toUnicode(s): """Convert a binary string to Unicode using UTF-8 (fallback to latin-1).""" try: u = compat.to_unicode(s, "utf8") except ValueError: log("toUnicode(%r) *** UTF-8 failed. Trying latin-1" % s) u = compat.to_unicode(s, "latin-1") # if not isinstance(s, str): # return s # try: # u = s.decode("utf8") # # log("toUnicode(%r) = '%r'" % (s, u)) # except: # log("toUnicode(%r) *** UTF-8 failed. Trying latin-1 " % s) # u = s.decode("latin-1") return u
def getMember(self, name): assert compat.is_native(name), "%r" % name fp = os.path.join(self._filePath, compat.to_unicode(name)) path = util.joinUri(self.path, name) if os.path.isdir(fp): res = WTFolderResource(path, self.environ, fp, self.pathMapper) elif os.path.isfile(fp): res = WTFileResource(path, self.environ, fp, self.pathMapper) else: res = None return res
def get_member(self, name): assert compat.is_native(name), "{!r}".format(name) fp = compat.to_unicode(name) # name = name.encode("utf8") path = name if self.db.is_dir(fp): res = FolderResource(path, self.environ, fp) elif self.db.is_file(fp): res = FileResource(path, self.environ, fp) else: _logger.debug("Skipping non-file {}".format(path)) res = None return res
def get_member(self, name): """Return direct collection member (DAVResource or derived). See DAVCollection.get_member() """ assert compat.is_native(name), "{!r}".format(name) fp = os.path.join(self._file_path, compat.to_unicode(name)) # name = name.encode("utf8") path = util.join_uri(self.path, name) if os.path.isdir(fp): res = FolderResource(path, self.environ, fp) elif os.path.isfile(fp): res = FileResource(path, self.environ, fp) else: _logger.debug("Skipping non-file {}".format(path)) res = None return res
def _is_user(self, user_name, domain, server): resume = "init" while resume: if resume == "init": resume = 0 try: users, _total, resume = win32net.NetUserEnum( server, 0, win32netcon.FILTER_NORMAL_ACCOUNT, 0) # Make sure, we compare unicode un = compat.to_unicode(user_name).lower() for userinfo in users: uiname = userinfo.get("name") assert uiname assert compat.is_unicode(uiname) if un == userinfo["name"].lower(): return True except win32net.error as e: _logger.exception("NetUserEnum: %s" % e) return False _logger.info("User '%s' not found on server '%s'" % (user_name, server)) return False
def tearDown(self): shutil.rmtree(compat.to_unicode(self.rootpath)) del self.app