按字典顺序排序?

发布于 2024-07-19 00:32:13 字数 510 浏览 9 评论 0原文

我正在努力与 Photobucket API 集成,我在他们的 API 文档

“按名称对参数进行排序 按字典顺序 [原文如此](字节排序, 标准排序,非自然排序或大小写排序 不敏感)。 如果参数有 相同的名称,然后按值排序。”

这是什么意思?我如何按字典顺序对某些内容进行排序?字节排序?

到目前为止,他们的其余文档都没有问题,但是(对我来说)看起来像这样不幸的是,没有进一步的解释,

无论如何,我正在用 Python 编写应用程序(它最终会成为 Django 应用程序),以防您想要推荐特定的模块。帮我处理这样的排序^_^

I am working on integrating with the Photobucket API and I came across this in their api docs:

"Sort the parameters by name
lexographically [sic] (byte ordering, the
standard sorting, not natural or case
insensitive). If the parameters have
the same name, then sort by the value."

What does that mean? How do I sort something lexicographically? byte ordering?

The rest of their docs have been ok so far, but (to me) it seems like this line bears further explanation. Unfortunately there was none to be had.

Anyway, I'm writing the application in Python (it'll eventually become a Django app) in case you want to recommend specific modules that will handle such sorting for me ^_^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迎风吟唱 2024-07-26 00:32:13

我认为这里的字典顺序是ascii排序的“别名”?

Lexicographic          Natural  
z1.doc                  z1.doc    
z10.doc                 z2.doc    
z100.doc                z3.doc    
z101.doc                z4.doc    
z102.doc                z5.doc    
z11.doc                 z6.doc    
z12.doc                 z7.doc    
z13.doc                 z8.doc    
z14.doc                 z9.doc     
z15.doc                z10.doc    
z16.doc                z11.doc    
z17.doc                z12.doc    
z18.doc                z13.doc     
z19.doc                z14.doc     
z2.doc                 z15.doc    
z20.doc                z16.doc    
z3.doc                 z17.doc    
z4.doc                 z18.doc    
z5.doc                 z19.doc    
z6.doc                 z20.doc    
z7.doc                z100.doc    
z8.doc                z101.doc    
z9.doc                z102.doc    

I think that here lexicographic is a "alias" for ascii sort?

Lexicographic          Natural  
z1.doc                  z1.doc    
z10.doc                 z2.doc    
z100.doc                z3.doc    
z101.doc                z4.doc    
z102.doc                z5.doc    
z11.doc                 z6.doc    
z12.doc                 z7.doc    
z13.doc                 z8.doc    
z14.doc                 z9.doc     
z15.doc                z10.doc    
z16.doc                z11.doc    
z17.doc                z12.doc    
z18.doc                z13.doc     
z19.doc                z14.doc     
z2.doc                 z15.doc    
z20.doc                z16.doc    
z3.doc                 z17.doc    
z4.doc                 z18.doc    
z5.doc                 z19.doc    
z6.doc                 z20.doc    
z7.doc                z100.doc    
z8.doc                z101.doc    
z9.doc                z102.doc    
扎心 2024-07-26 00:32:13

该单词应按“字典顺序”

http://www.thefreedictionary.com/Lexicography

字典顺序。 使用字符串中出现的字母。

正如他们建议的那样,不要将大写和小写字母折叠在一起。 只需使用 Python 内置的 list.sort() 方法即可。

The word should be "lexicographic"

http://www.thefreedictionary.com/Lexicographic

Dictionary order. Using the letters as they appear in the strings.

As they suggest, don't fold upper- and lower-case together. Just use the Python built-in list.sort() method.

剩余の解释 2024-07-26 00:32:13

这与 Facebook API 类似——在生成签名哈希之前需要对查询字符串进行规范化。

您可能有一个参数字典,如下所示:

params = {
  'consumer_key': "....",
  'consumer_secret': "....",
  'timestamp': ...,
  ...
}

创建查询字符串,如下所示:

urllib.urlencode(sorted(params.items()))

params.items()以列表元组的形式返回字典的键和值,sorted() > 对列表进行排序,urllib.urlencode() 在转义时将它们连接成单个字符串。

This is similar to the Facebook API — the query string needs to be normalized before generating the signature hash.

You probably have a dictionary of parameters like:

params = {
  'consumer_key': "....",
  'consumer_secret': "....",
  'timestamp': ...,
  ...
}

Create the query string like so:

urllib.urlencode(sorted(params.items()))

params.items() returns the keys and values of the dictionary as a list tuples, sorted() sorts the list, and urllib.urlencode() concatenates them into a single string while escaping.

空袭的梦i 2024-07-26 00:32:13

引用该部分的更多内容:

2 生成基本字符串:

标准化参数:

  • 将此请求的 OAuth 特定参数添加到输入参数中,包括:

    oauth_consumer_key = ; 
      oauth_timestamp = <时间戳>; 
      oauth_nonce = ; 
      oauth_version = <版本>; 
      oauth_signature_method = ; 
      
  • 按名称字典顺序对参数进行排序 [原文如此](字节排序,标准排序,不自然或不区分大小写)。 如果参数名称相同,则按值排序。

  • 按照 RFC3986 第 2 部分对参数值进行编码(即 urlencode)。
    创建参数字符串()。 这与 HTTP 'postdata' 或 'querystring' 的格式相同,即每个参数表示为 name=value,并用 & 分隔。 例如,a=1&b=2&c=hello%20there&c=something%20else

我认为他们是说参数必须按排序顺序出现 - oauth_consumer_key< /code> 之前 oauth_nonce 之前 ...

Quote a bit more from the section:

2 Generate the Base String:

Normalize the parameters:

  • Add the OAuth specific parameters for this request to the input parameters, including:

    oauth_consumer_key = <consumer_key>
    oauth_timestamp = <timestamp>
    oauth_nonce = <nonce>
    oauth_version = <version>
    oauth_signature_method = <signature_method>
    
  • Sort the parameters by name lexographically [sic] (byte ordering, the standard sorting, not natural or case insensitive). If the parameters have the same name, then sort by the value.

  • Encode the parameter values as in RFC3986 Section 2 (i.e., urlencode).
    Create parameter string (). This is the same format as HTTP 'postdata' or 'querystring', that is, each parameter represented as name=value separated by &. For example, a=1&b=2&c=hello%20there&c=something%20else

I think that they are saying that the parameters must appear in the sorted order - oauth_consumer_key before oauth_nonce before ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文