小编Mic*_*ski的帖子

为什么上下文在with语句后会出现?

我想知道为什么使用with语句或块中打开的文件对象在退出后仍在范围内.正在<closed file>对象曾经清理?

>>> with open('test.txt','w') as f:
...     f.write('test')
...
>>> f
<closed file 'test.txt', mode 'w' at 0x00E014F0>
>>> f.close()


>>> if True:
...     fal = open('demo.txt','w')
...     fal.write('stuff')
...     fal.close()
...
>>> fal
<closed file 'demo.txt', mode 'w' at 0x00E015A0>
Run Code Online (Sandbox Code Playgroud)

python file-io

8
推荐指数
1
解决办法
307
查看次数

LDAP集成后无法在计算机(RHEL7)中使用本地用户登录

我是RedHat IDM的新手.以下是我的要求.请帮忙.

假设我们有两台RHEL7机器

  1. Redhat IDM服务器
  2. Redhat IDM客户端机器

    现在我们在IDM客户端计算机上创建了两个用户,条件如下

    • 使用简单的linux命令创建第一个用户

useradd ravendra

第二个我们使用IPA命令创建用户

IPA用户添加JSMITH --first =约翰--last =史密斯--manager = bjensen --email=johnls@example.com --homedir = /家庭/工作/约翰 - 密码

现在我们有以下要求.

  1. 如果IDM服务器正在运行,那么我们想要限制通过普通linux命令创建的用户"ravendra"的ssh.只有"jsmith"可以在IDM客户端计算机上使用sshs
  2. 如果IDM服务器已停止,则两个用户都可以在IDM客户端计算机上执行ssh.

所以请建议我任何插件或任何方式我如何能够实现这一目标.

提前致谢

linux redhat ldap

5
推荐指数
1
解决办法
79
查看次数

Restful webservice调用中的Spring错误

当我尝试使用restful webservice访问rezgo sample api时,我会遇到异常.我想在示例对象中转换此响应

package com.mycompany.hr.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import org.springframework.ws.client.core.WebServiceTemplate;
public class Main {

    public static void main(String[] args) throws Exception {

        List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
          acceptableMediaTypes.add(MediaType.APPLICATION_XML);
          HttpHeaders headers = new HttpHeaders();
          headers.setAccept(acceptableMediaTypes);
          //ResponseEntity<String> result = restTemplate.exchange("http://localhost:8080/spring-rest-provider/krams/person/{id}", HttpMethod.PUT, entity, String.class, id);
          Map<String,String> urlParam=new …
Run Code Online (Sandbox Code Playgroud)

java spring web-services

4
推荐指数
1
解决办法
7744
查看次数

如何从format()方法的字符串中获取变量名称

可以说我有这条线:

"My name is {name}".format(name="qwerty")
Run Code Online (Sandbox Code Playgroud)

我知道变量名是name,所以我可以填写它.但是,如果内部的词{}总是在变化,如下:

"My name is {name}"
"My name is {n}"
"My name is {myname}"
Run Code Online (Sandbox Code Playgroud)

我希望能够这样做:

"My name is {*}".format(*=get_value(*))
Run Code Online (Sandbox Code Playgroud)

哪里*是什么都词是内给定{}

希望我很清楚.


编辑:

def get_value(var):
    return mydict.get(var)

def printme(str):
    print str.format(var1=get_value(var1), var2=get_value(var2))

printme("my name is {name} {lastname}")
printme("your {gender} is a {sex}")
Run Code Online (Sandbox Code Playgroud)

有了这个,我不能硬编码printme函数内部的任何变量.

python

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

使用 Java 的 AES-256-GCM 解密中的标签不匹配错误

我用 Javascript 编写了以下函数,用于使用 aes-256-gcm 进行加密:

encrypt: function (text, masterkey){
    try {
        // random initialization vector
        var iv = crypto.randomBytes(12);

        // random salt
        var salt = crypto.randomBytes(64);

        // derive key: 32 byte key length - in assumption the masterkey is a cryptographic and NOT a password there is no need for
        // a large number of iterations. It may can replaced by HKDF
        var key = crypto.pbkdf2Sync(masterkey, salt, 2145, 32, 'sha512');

        // AES 256 GCM Mode
        var cipher = crypto.createCipheriv('aes-256-gcm', key, …
Run Code Online (Sandbox Code Playgroud)

javascript java cryptography aes-gcm

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

python中dedent()的作用是什么

代码如下。我真的很困惑 dedent() 的功能是什么,当我运行这些代码时,结果几乎相同。

print(dedent("""
Like a world class boxer you dodge, weave, slip and
slide right as the Gothon's blaster cranks a laser
past your head. In the middle of your artful dodge
your foot slips and you bang your head on the metal
wall and pass out. You wake up shortly after only to
die as the Gothon stomps on your head and eats you.
"""))

print("""
Like a world class boxer you dodge, weave, slip and
slide right …
Run Code Online (Sandbox Code Playgroud)

python

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