一般问题:当我没有特定的文件格式,但其他人没有为其定义UTI时,我该如何使用该文件格式?
具体情况:我正在为.torrent和.nzb文件创建一个QuickLook插件.(注意:.nzb文件类似于.torrent文件,除了指向一个bittorrent跟踪器,它们指向一个Usenet服务器.)我希望插件显示.nzb/.torrent文件指向哪些数据,哪些文件如果打开它们将被下载,以及任何其他适用的元数据.为此,我必须为这两种文件类型设置统一类型标识符.虽然.torrent文件有指定的com.bittorrent.torrent UTI,但.nzb文件却没有 - NZB格式是由newzbin.com定义的,它不发布自己的应用程序(因此没有定义Mac OS X.统一类型标识符供我使用).
选项似乎是:
CFBundleTypeExtensions在我的Info.plist文件中使用.这似乎也是错误的,因为不仅仅是CFBundleTypeExtensions根据Apple的文档弃用,但我认为我不能混合使用CFBundleTypeExtensions和LSBundleContentTypes(如果LSBundleContentTypes存在,因为它必须是我使用com.bittorrent.torrent UTI,然后CFBundleTypeExtensions被忽略).在这种情况下做什么是正确的?
我知道Powershell可以调用.NET代码,它可能看起来像这样
PS> [Reflection.Assembly]::LoadFile(($ScriptDir + ".\SharpSvn-x64\SharpSvn.dll"))
PS> $SvnClient = New-Object SharpSvn.SvnClient
Run Code Online (Sandbox Code Playgroud)
而且我知道在C#有out参数的地方,Powershell有[ref]参数,可能看起来像这样:
PS> $info = $null
PS> $SvnClient.GetInfo($repo.local, ([ref]$info))
True
PS> $info
(...long output snipped...)
NodeKind : Directory
Revision : 16298
Uri : http://server/path/to/remoterepo
FullPath : C:\path\to\localrepo
(...long output snipped...)
Run Code Online (Sandbox Code Playgroud)
我知道在C#中你可以重载函数,就像SharpSvn库为它的SvnClient.Update()方法做的那样:
Update(ICollection(String)) - 递归更新指定的路径到最新(HEAD)修订版Update(String) - 递归更新指定的最新(HEAD)修订路径Update(ICollection(String), SvnUpdateArgs) - 更新指定修订的指定路径Update(ICollection(String), SvnUpdateResult) - 递归更新指定的路径到最新(HEAD)修订版Update(String, SvnUpdateArgs) - 递归更新指定的路径Update(String, SvnUpdateResult) - 递归更新指定的最新(HEAD)修订路径Update(ICollection(String), SvnUpdateArgs, SvnUpdateResult) - 更新指定修订的指定路径Update(String, SvnUpdateArgs, SvnUpdateResult) - 递归更新指定的最新(HEAD)修订路径但是,如果我们想把所有这些放在一起呢?比方说,如果我想调用第6个版本Update() …
我有一个需要身份验证的CherryPy Web应用程序.我有一个HTTP基本身份验证工作,其配置如下所示:
app_config = {
'/' : {
'tools.sessions.on': True,
'tools.sessions.name': 'zknsrv',
'tools.auth_basic.on': True,
'tools.auth_basic.realm': 'zknsrv',
'tools.auth_basic.checkpassword': checkpassword,
}
}
Run Code Online (Sandbox Code Playgroud)
HTTP auth在这一点上很有用.例如,这将为我提供我在内部定义的成功登录消息AuthTest:
curl http://realuser:realpass@localhost/AuthTest/
Run Code Online (Sandbox Code Playgroud)
自会话开始以来,我可以保存cookie并检查CherryPy设置的cookie:
curl --cookie-jar cookie.jar http://realuser:realpass@localhost/AuthTest/
Run Code Online (Sandbox Code Playgroud)
该cookie.jar文件最终将如下所示:
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
localhost FALSE / FALSE 1348640978 zknsrv 821aaad0ba34fd51f77b2452c7ae3c182237deb3
Run Code Online (Sandbox Code Playgroud)
但是,401 Not Authorized如果我在没有用户名和密码的情况下提供此会话ID ,我将收到HTTP 失败,如下所示:
curl --cookie 'zknsrv=821aaad0ba34fd51f77b2452c7ae3c182237deb3' http://localhost/AuthTest
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
非常感谢您的帮助.
我有一个使用自定义对象的脚本.我用这样的伪构造函数创建它们:
function New-TestResult
{
$trProps = @{
name = "";
repo = @{};
vcs = $Skipped;
clean = New-StageResult; # This is another pseudo-constructor
build = New-StageResult; # for another custom object.
test = New-StageResult; # - Micah
start = get-date;
finish = get-date;
}
$testResult = New-Object PSObject -Property $trProps
return $testResult
}
Run Code Online (Sandbox Code Playgroud)
这些都是有用的,因为它们可以被传递到类似ConvertTo-Csv或ConvertTo-Html(不像,说,一个哈希表,否则将完成我的目标).它们被输入为PSCustomObject对象.这段代码:
$tr = new-testresult
$tr.gettype()
Run Code Online (Sandbox Code Playgroud)
返回:
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False PSCustomObject System.Object
Run Code Online (Sandbox Code Playgroud)
我可以将Name …
看来SQLite从3.7.13开始支持多线程访问,Python的sqlite3模块从3.4开始支持它。要使用它,您可以编写如下代码:
import sqlite3
dburi = "file:TESTING_MEMORY_DB?mode=memory&cache=shared"
connection = sqlite3.connect(dburi, uri=True, check_same_thread=False)
with connection:
cursor = conneciton.cursor()
cursor.execute("SQL")
Run Code Online (Sandbox Code Playgroud)
这是可行的,但您会发现的第一件事是您需要锁定对数据库的访问,否则另一个线程可能会损坏您的数据。这可能看起来像这样:
import threading
import sqlite3
dburi = "file:TESTING_MEMORY_DB?mode=memory&cache=shared"
connection = sqlite3.connect(dburi, uri=True, check_same_thread=False)
# NOTE: You'll need to share this same lock object with every other thread using the database
lock = threading.Lock()
with lock:
with connection:
cursor = connection.cursor()
cursor.execute("SQL")
connection.commit()
Run Code Online (Sandbox Code Playgroud)
现在,如果一个线程获取了锁,则另一个线程无法获取它,直到第一个线程关闭它,并且只要所有线程使用相同的lock对象并记住with lock:它们之前的with connection:对象,您的数据就不会被损坏。
但是,现在我需要一种方法来通过连接传递锁。您可以使用单独的参数或自定义类来执行此操作:
import threading
import sqlite3
class LockableSqliteConnection(object):
def __init__(self, dburi): …Run Code Online (Sandbox Code Playgroud)