Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7cc01b8

Browse files
ArniDaguralkim0
andcommitted
Add aliases argument to Engine.add_resource
Co-Authored-By: Albert Kim <alkim@alkim.org>
1 parent3fcd327 commit7cc01b8

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
55

66
##Unreleased
77
---
8+
###Added
9+
* Added`aliases` optional argument to`Engine.add_resource`
10+
811
###Changes
912
* Update PyO3 dependency to`0.16`.
1013
* Update upstream dependency to`0.5.6`.

‎adblock/adblock.pyi‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ class Engine:
117117
pass
118118
deftag_exists(self,tag:str)->bool:
119119
pass
120-
defadd_resource(self,name:str,content_type:str,content:str)->bool:
120+
defadd_resource(
121+
self,
122+
name:str,
123+
content_type:str,
124+
content:str,
125+
aliases:Optional[List[str]]=None,
126+
)->bool:
121127
pass
122128
defurl_cosmetic_resources(self,url:str)->UrlSpecificResources:
123129
pass

‎src/lib.rs‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,27 @@ impl Engine {
530530
///
531531
/// # Arguments
532532
/// * `name`: Represents the primary name of the resource, often a filename
533-
/// * `content_type`: How to interpret the resource data within `content`
533+
/// * `content_type`: How to interpret the resource data within `content`.
534+
/// Use `"template"` if wanting to specify a template resource type.
534535
/// * `content`: The resource data, encoded using standard base64 configuration
535-
#[pyo3(text_signature ="($self, name, content_type, content)")]
536-
pubfnadd_resource(&mutself,name:&str,content_type:&str,content:&str) ->PyResult<()>{
536+
/// * `aliases`: List of aliases for the resource
537+
#[pyo3(text_signature ="($self, name, content_type, content, aliases)")]
538+
pubfnadd_resource(
539+
&mutself,
540+
name:&str,
541+
content_type:&str,
542+
content:&str,
543+
aliases:Option<Vec<String>>,
544+
) ->PyResult<()>{
537545
let result =self.engine.add_resource(Resource{
538546
name: name.to_string(),
539-
aliases:vec![],
540-
kind:ResourceType::Mime(MimeType::from(std::borrow::Cow::from(
541-
content_type.to_string(),
542-
))),
547+
aliases: aliases.unwrap_or_default(),
548+
kind:match content_type{
549+
"template" =>ResourceType::Template,
550+
_ =>ResourceType::Mime(MimeType::from(std::borrow::Cow::from(
551+
content_type.to_string(),
552+
))),
553+
},
543554
content: content.to_string(),
544555
});
545556

‎tests/test_exceptions.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def test_add_resource_error():
3030
# }
3131
# xOO6ww== => base64.b64encode('你好'.encode('gbk'))
3232
engine.add_resource(
33-
name="aa",content_type="application/javascript",content="xOO6ww=="
33+
name="aa",
34+
content_type="application/javascript",
35+
content="xOO6ww==",
36+
aliases=[],
3437
)
3538
assert"invalid utf content"instr(exc.value)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp