小编Rob*_*och的帖子

Pythons str.join()的内部是什么?(隐藏输出密码)

我偶然发现了一种有趣的(?)方式来隐藏密码(和其他个人数据)从屏幕到日志文件的一般输出.

在他的书" 如何在Python中犯错"中, Mike Pirnat建议为敏感字符串实现一个类,并使其__str__- 和 - __repr__方法重载.

我试验过这个并得到了这个:

class secret(str):

    def __init__(self, s):
        self.string = s

    def __repr__(self):
        return "'" + "R"*len(self.string) + "'"

    def __str__(self):
        return "S" * len(self.string)

    def __add__(self, other):
        return str.__add__(self.__str__(), other)

    def __radd__(self, other):
        return str.__add__(other, self.__str__())

    def __getslice__(self, i, j):
        return ("X"*len(self.string))[i:j]
Run Code Online (Sandbox Code Playgroud)

(我知道使用len提供有关要隐藏的内容的信息.它仅用于测试.)

它在这种情况下工作正常:

pwd = secret("nothidden")

print("The passwort is " + pwd)                  # The passwort is SSSSSSSSS
print(pwd + " is the passwort.")                 # SSSSSSSSS is the …
Run Code Online (Sandbox Code Playgroud)

python

11
推荐指数
1
解决办法
208
查看次数

在复合组件内部引用组件(反之亦然)

我在使用 Primefaces (v5.2) 时遇到一两个问题:

复合组件中引用组件

假设我有一个包含输入字段的复合组件:

我的输入字段.xhtml

<composite:interface>
    <composite:attribute name="value" />
    ...
</composite:interface>

<composite:implementation>
    <h:inputText value="#{cc.attrs.value}" />
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

(当然,真正的应用程序做得“多一点”。)

在我的页面中,我现在像这样使用这个字段:

索引.xhtml

<my:myinputputfield value=#{controller.inputstring} />
Run Code Online (Sandbox Code Playgroud)

这有效。但是:知道我想从外部引用该内部输入字段,例如用于标签或消息。东西喜欢

<composite:interface>
    <composite:attribute name="value" />
    ...
</composite:interface>

<composite:implementation>
    <h:inputText value="#{cc.attrs.value}" />
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

当然这不起作用,因为id没有为myinputfield. 所以第一个想到的想法是像这样扩展 cc:

myinputfield.xhtml (新)

<composite:interface>
    <composite:attribute name="id" />
    <composite:attribute name="value" />
    ...
</composite:interface>

<composite:implementation>
    <h:inputText id="{cc.attrs.id}" value="#{cc.attrs.value}" />
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

这也不起作用。我尝试了不同的事情并阅读了不同的答案和文章,但没有找到答案。


第二个问题正好相反:

复合组件之外引用组件

这一次换个角度想象一下。我有一个自定义的标签、消息或在我的情况下是一个工具提示:

我的工具提示.xhtml

<composite:interface>
    <composite:attribute name="for" />
    <composite:attribute name="value" /> …
Run Code Online (Sandbox Code Playgroud)

jsf primefaces composite-component

3
推荐指数
1
解决办法
1466
查看次数

标签 统计

composite-component ×1

jsf ×1

primefaces ×1

python ×1