文本编码“简体中文 (Mac OS)”不适用

未能打开文稿“xxxxxx.txt”。文本编码“简体中文 (Mac OS)”不适用。

该文件可能已使用了不同的文本编码来存储,或者可能不是文本文件。

如果你用Mac这些文字一定并不陌生吧。

当你在mac os打开windows拷贝过来的文件时很可以出现这种问题,当然也不是全部,还得满足一个条件,就是这个文件在windows上保存的时候选择的是gbk编码。

这个问题其实应该算是mac的一个bug,不知道mac为什么一直不修复,在mac上面有2种中文编码,一种是和windows上面的中文编码一样的中文(GB 18030)此编码是中文gbk编码的一种扩展,所以完全兼容gbk,但是除了这个之外mac还另外搞了一种中文编码叫简体中文(Mac OS),此编码和gbk还有GB 18030是不一样;当你打开gbk编码的文件时,mac识别成了简体中文(Mac OS),所有就打不开喽。

解决办法:

打开文本编辑的偏好设置,选择打开和存储选项卡,在下面的纯文本文件编码 下面的打开文件后面选择中文(GB 18030)就可以了。

下面是google到的内容

如何将 Macintosh 简体中文编码转换成相应的 GB 标准?
简体中文的 Mac 编码是一种移位的 GB2312。从 GB2312 转成 Mac 编码, 每个字符要加上0×8080。 相反从 Mac 编码转成 GB2312, 则每个字符都减去 0×8080。
字符集西方字符区域不能加减。下面的例子说明了如何进行这种转换。

// 如字符需要转换则返回true,反之单字节字符则返回false(意味着只处理了首字节)
// (i.e. false 表示是西方字符)
boolean MacToGB2312(unsigned char first, unsigned char second,
    unsigned short *output)
{
    if (first < 0x81) {
        *output = first;
        return false;
    } else {
        unsigned short temp;
        temp = (first - 0x80) << 8;
        temp += (second - 0x80);
        *output = temp;
        return true;
    }
}
// 总是转换, 无需单独获取字节,无需返回是否转换
void GB2312ToMac(unsigned short input, unsigned short *output)
{
    *output = input + 0x8080;
}

从代码中可以看出, 需要移动双字节字符的每个字节。这样确定一个字符是双字节字符的一部分还是单字节西方字符就显而易见了。

Posted in Mac OS X | Tagged | 2 Comments

web.py 0.36发布

距离0.35还没多久就发布了0.36,此版本主要修复0.35的问题,更新内容如下:

* Upgraded to CherryPy WSGIServer 3.2.0. — #66
* Various Jython compatibility fixes (tx Ben Noordhuis)
* allow strips to accept lists — #69
* Improvements to setcookie (tx lovelylain) — #65
* Added __contains__ method to Session. (tx lovelylain) #65
* Added secure option to session. — #38
* Fixed db.delete error with `using` clause (tx berndtj) — #28
* Fixed the case of no where-clauses in db.where
* Fixed threadlocal error in python2.3 — #77
* Fixed TemplateResult inconsistant behavior — #78
* Fixed query execution issues with MSSQL — #71

Posted in Python | Tagged | Leave a comment

Ambiguous output redirect

在FreeBSD中使用command > file 2>&1时候会得到这个错误
Ambiguous output redirect

出错的原因在于Freebsd默认使用csh,在csh中如果想把标准输出和错误输出同时重定向到一个文件,需要用下面命令
command >& file

Posted in FreeBSD | Leave a comment

web.py升级到0.35

本地升级了,简单的看了一下,之前的程序还未发现在0.35下有问题的情况,另外更新日志中所说的新的表单样式,我还未发现新的Form的render和老的有什么区别。

Posted in Python | Tagged | Leave a comment

web.py 0.35发布

ChangeLog

  • Better ThreaedDict implementation using threadlocal (tx Ben Hoyt)
  • Make Form a new-style class — #53
  • Optimized SQLQuery.join and generation of multiple_insert query — #58
  • New: support for Amazon’s Simple Email Service
  • Added httponly keyword to setcookie (tx Justin Davis)
  • Added httponly only option to sessions and enabled it by default (tx Justin Davis)
  • made htmlquote and htmlunquote work with unicode
  • Added doseq support for web.url
  • New flag web.config.debug_sql to control printing of db queries (tx Nimrod S. Kerrett)
  • Fixed inserting default values into MySQL — #49
  • Fixed rendering of Dropdown with mutliple values (tx krowbar) — #43
  • Fixed mutliple set-cookie header issue with session — #45
  • Fixed error in safeunicode when used with appengine datastore objects
  • Fixed unicode error in generating debugerror — #26
  • Fixed GAE compilation issue — #24
  • Fixed unicode encoding issue in templates — #17
  • Fixed a bug in form.RadioButton when called with tuple options (tx fhsm) — #13
  • Fixed error in creating PostgresDB with pgdb driver (tx cninucci) — #23
  • Support auto convertion of timestamp/date datatypes in sqlite to datetime.data objects — #22
  • Fixed escaping issue on GAE — #10
  • fixed form.validates for checkbox (tx Justin Davis).
  • fixed duplicate content-type in web.sendmail — #20
  • Fix: create session dirs if required (tx Martin Marcher)
  • Fixed safestr to make use of encoding argument (tx s7v7nislands)
  • Don’t allow /static/../foo urls in dev webserver (tx Arnar Lundesgaard)
  • Disabled debug mode in flup server (tx irrelative) — #35
  • And a lot of unicode fixes

值得注意的有这几点

  • 表单使用新的样式
  • cookie增加httponly
  • 修复模版中unicode编码问题
  • 修复很多unicode问题
Posted in Python | Tagged | Leave a comment

yum增加源

默认的yum源中很多软件都没有,要想使用yum,首先得些增加yum的源

一般增加2个就够了

1.添加[CentALT]源
在/etc/yum.repos.d 目下创建 alt.ru.repo 文件内容如下:

[CentALT]
name=CentALT Packages for Enterprise Linux 5 - $basearch
baseurl=http://centos.alt.ru/repository/centos/5/$basearch/
enabled=1
gpgcheck=0

2.添加EPEL

64位系统
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

32位系统
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Posted in Linux | Tagged , , | Leave a comment

郑州景安VPS可用率

一个月的郑州景安VPS可用率数据

Posted in VPS评测 | Tagged | Leave a comment

亿恩科技vps评测

亿恩科技的ENVPS-512标准型,线路为北京高端双线,带宽为3m峰值。

官方所称为高端双线,但实际情况并不理想,电信速度还可以,联通速度很慢。

chinaz ping数据:

 

监控宝ping数据:
监控宝可用率统计(ping):

后2个监控点故障时间少是因为后2个监控点是后来加进来的,一开始没有,以上监控宝的数据均为最近30天的。

Posted in VPS评测 | Tagged | Leave a comment

ZOC 6注册码

ZOC官方地址:http://www.emtec.com/zoc/

3组注册码:

s/n1: 05306/01031/53990 s/n2: 26051
s/n1: 30250/01026/30781 and s/n2: 63823
s/n1: 53866/01028/18861 and s/n2: 45757

Posted in Mac OS X | Tagged | Leave a comment

Mac OS安装Python PIL

之前看到很多在Mac下安装PIL会有问题的内容,很多人推荐使用MacPorts安装,这个东西我不使用。

先看看到底什么问题:
easy_install pil之后看到
— TKINTER support available
*** JPEG support not available
— ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available

很明显缺少JPEG, FREETYPE2, LITTLECMS,逐个安装之后JPEG和FREETYPE2都没问题了,就LITTLECMS还是不行,在stackoverflow上查到原来LITTECMS版本只有使用1.x,不能使用2.x,重新安装LITTLECMS 1.19之后问题搞定

唯一的问题也就是PIL不兼容LITTECMS 2的问题,我找了找PIL官方也没找到这方面的说明

stackoverflow:

http://stackoverflow.com/questions/5345348/what-is-the-best-way-to-install-pil-on-mac-snow-leopard-with-xcode-4-installed

Posted in Mac OS X, Python | Tagged , | 1 Comment