小编mad*_*mad的帖子

无法从输入中导入协议

我在 Windows 10 上全新安装了 Python 3.7-32。

我想尝试协议 python 方法,我接下来做:

文件 test_protocols.py 只有一行:

from typing import Protocol
Run Code Online (Sandbox Code Playgroud)

然后:

>python test_protocols.py
Run Code Online (Sandbox Code Playgroud)

我还有下一条需要解释的错误消息:

Traceback (most recent call last):
  File "test_protocols.py", line 1, in <module> 
    from typing import Protocol
ImportError: cannot import name 'Protocol' from 'typing' (C:\Programing\Python\Python37-32\lib\typing.py)
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

也许我读错了 PEP-0544,但从我的角度来看,我做的和记录的一样。

python python-3.x

10
推荐指数
3
解决办法
7235
查看次数

春季安全3.1.使用url参数自定义authentication-failure-url

我用谷歌搜索并尝试了很多变种,但没有任何成功.请帮我找一个解决方案.

春季版:春季3.1

我有登录页面.登录页面取决于URL参数:

/login?code=client1
Run Code Online (Sandbox Code Playgroud)

要么

/login?code=client2
Run Code Online (Sandbox Code Playgroud)

因此client1和client2具有不同的登录页面.

security.xml文件:

<sec:form-login login-page="/login" default-target-url="/start" authentication-failure-url="/login"/>
Run Code Online (Sandbox Code Playgroud)

因此,如果用户进行了错误的身份验证,我会向他显示/登录页面...但是我必须显示具有相应代码参数的登录页面.

我该怎么办?有tyou的例子吗?

非常感谢您的进步.

更新#1:

我创建了FailureHandler类:

public class GRSAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler implements AuthenticationFailureHandler {

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {

}

}
Run Code Online (Sandbox Code Playgroud)

我应该在里面写什么来重定向到所需的URL?如果你能给我更多细节,请.

非常感谢!

java spring-security

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

如何在Spring4d中从ServiceLocator获取子接口实例?

我是Spring4D框架中的新手并请求帮助.

我有下一个类和接口:

ICommand = interface

TCommand = class(TInterfacedObject, ICommand)

IVecadCommand = interface(ICommand)

TVecadCommand = class(TCommand, IVecadCommand)

TVecadCommandJPG = class(TVecadCommand, IVecadCommand)

TCommandDeckelJPG = class(TVecadCommandJPG, IVecadCommand)
Run Code Online (Sandbox Code Playgroud)

然后我注册一个组件:

GlobalContainer.RegisterComponent<TCommandDeckelJPG>.Implements<IVecadCommand>('deckel_jpg');
Run Code Online (Sandbox Code Playgroud)

然后我尝试在ServiceLocator的帮助下创建一个对象:

var
  i: Integer;
  com: ICommand;
begin
  Result := nil;
  com := ServiceLocator.GetService<ICommand>(actionName);
  com.setSession(designSession);
  Result := com;
end;
Run Code Online (Sandbox Code Playgroud)

作为执行的结果,我有一个例外:

Invalid class typecast
Run Code Online (Sandbox Code Playgroud)

为了避免异常,我这样做:

var
  i: Integer;
  com: IVecadCommand;
begin
  Result := nil;
  com := ServiceLocator.GetService<IVecadCommand>(actionName);
  com.setSession(designSession);
  Result := com;
end;
Run Code Online (Sandbox Code Playgroud)

一切都好.

要点是我必须在这种情况下使用TContainer作为TCommand的Repository和继承的类.所以我必须先使用ServiceLocator.

我该怎么做才能避免异常并在TContainer中使用ICommand而不是IVecadCommand?

谢谢.将愉快地提供额外的细节.

delphi spring4d

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

如何在Spring4D GlobalContainer中初始化主应用程序表单?

所以例如我有一个主窗体,并希望将一个记录器实例注入私有字段.

我注册了记录器

GlobalContainer.RegisterType<TCNHInMemoryLogger>.Implements<ILogger>;
Run Code Online (Sandbox Code Playgroud)

我的主要表格中有一个私人字段

private
   FLogger: ILogger;
Run Code Online (Sandbox Code Playgroud)

所有我想要的是这样做:

private
   [Inject]
   FLogger: ILogger;
Run Code Online (Sandbox Code Playgroud)

在我的DPR文件中,我有典型的delphi方式来创建主窗体:

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(Tfrm_CNH, frm_CNH);
  Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)

在表单创建方式中我应该更改哪些内容可以正确注入私有字段?

顺便说一句,如果我使用GlobalContainer.Resolve解决Form.OnCreate中的字段,它可以正常工作.但我想避免在表单中使用GlobalContainer变量.

delphi spring4d

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

如何正确注入一个属性来形成?

我会在第二时间提出这个问题.请不要怪我.

情况:

我有一张表格

TfrmMain = class(TForm)
private
   [Inject('IniFileSettings')]
   FSettings: ISettings;
public
end;
Run Code Online (Sandbox Code Playgroud)

我有容器初始化程序:

procedure BuildContainer(const container: TContainer);
begin
  container.RegisterType<TIniSettings>.Implements<ISettings>('IniFileSettings');

  container.RegisterType<TfrmMain, TfrmMain>.DelegateTo(
    function: TfrmMain
    begin
      Application.CreateForm(TfrmMain, Result);
    end);

  container.Build;
end;
Run Code Online (Sandbox Code Playgroud)

所以我通过容器初始化TfrmMain和TIniSettings.

在.DPR我有:

begin
  BuildContainer(GlobalContainer);
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TfrmMain, frmMain);
  Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)

我还有TApplication的助手:

procedure TApplicationHelper.CreateForm(InstanceClass: TComponentClass; var Reference);
var
  locator: IServiceLocator;
begin
  locator := TServiceLocatorAdapter.Create(GlobalContainer);
  if locator.HasService(InstanceClass.ClassInfo) then
    TObject(Reference) := GlobalContainer.Resolve(InstanceClass.ClassInfo).AsObject
  else
    inherited CreateForm(InstanceClass, Reference);
end;
Run Code Online (Sandbox Code Playgroud)

问题:当我尝试时

procedure TfrmMain.FormCreate(Sender: TObject);
begin
   s := FSettings.ReadString('Connection', 'Server', 'localhost');
end;
Run Code Online (Sandbox Code Playgroud)

我得到AV异常,因为FSettings目前是NIL.

从容器中获取FSettings对象的正确方法是什么?

更新:

FSettings …
Run Code Online (Sandbox Code Playgroud)

delphi dependency-injection inversion-of-control spring4d

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

BobJenkinsHash函数的结果可能是否定的?

环境:Win7 64bit,Delphi 2010,Win32项目.

我尝试在Generics.Defaults的BobJenkinsHash()函数的帮助下获取字符串集的整数哈希值.

它有效,但有些观点对我来说并不清楚.

  1. 功能结果可能是否定的?

正如我在源站点上看到的那样 ,它使用uint32_t作为hashword()函数的结果类型:

uint32_t hashword(
const uint32_t *k,                   /* the key, an array of uint32_t values  */
size_t          length,               /* the length of the key, in uint32_ts    */
uint32_t        initval)         /* the previous hash, or an arbitrary value */
{
Run Code Online (Sandbox Code Playgroud)

它是unsigned int吗?

  1. 第二个问题是我对具有相同值的不同字符串有不同的结果:

    'DEFPROD001' => 759009858
    'DEFPROD001' => 1185633302
    
    Run Code Online (Sandbox Code Playgroud)

这是正常的行为吗?

我的全部函数来计算哈希值(如果第一个参数为空则返回第二个):

function TAmWriterJD.ComposeID(const defaultID: string; const GUID: String): String;
var
  bjh: Integer;
begin
  if defaultID = '' then
  begin
    Result := GUID …
Run Code Online (Sandbox Code Playgroud)

delphi string hash

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

为什么我的通用匿名方法不兼容?

在我的学习过程中,我使用Nick Hodges撰写的"Delphi中的编码"一书.我正在使用Delphi 2010.

在关于匿名方法的章节中,他提供了一个关于伪造.NET的非常有趣的例子using.当我尝试编译示例时,我从编译器中收到错误.请帮我看一下结果.

我的课:

type
  TgrsObj = class
    class procedure Using<T: class>(O: T; Proc: TProc<T>); static;
  end;

implementation

{ TgrsObj }

class procedure TgrsObj.Using<T>(O: T; Proc: TProc<T>);
begin
  try
    Proc(O);
  finally
    O.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

以下是我尝试使用上述代码的方法:

procedure TForm4.Button1Click(Sender: TObject);
begin
  TgrsObj.Using(TStringStream.Create,
    procedure(ss: TStringStream)
    begin
      ss.WriteString('test string');
      Memo1.Lines.Text := ss.DataString;
    end);
end;
Run Code Online (Sandbox Code Playgroud)

编译错误:

[DCC Error] uMain.pas(36): E2010 Incompatible types: 'TProc<ugrsObj.Using<T>.T>' and 'Procedure'
Run Code Online (Sandbox Code Playgroud)

delphi generics anonymous-methods delphi-2010

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

@PreAuthorize中的自定义类主体

更新(17.04.2012):所以我得到了什么。

root-context.xml:

<context:annotation-config/>
<context:component-scan base-package="com.grsnet.qvs.controller.web"/>  
<security:global-method-security pre-post-annotations="enabled" />
<bean id="permissionManager" class="com.grsnet.qvs.auth.PermissionManager"/>
Run Code Online (Sandbox Code Playgroud)

PermissionManager.java

package com.grsnet.qvs.auth;

import com.grsnet.qvs.model.Benutzer;

public class PermissionManager {

public PermissionManager() {}

public boolean hasPermissionU01(Object principal, Integer permissionLevel) {
    return ((Benutzer)principal).getPermission().getU_01() >= permissionLevel;
}
}
Run Code Online (Sandbox Code Playgroud)

控制器:

@PreAuthorize("@permissionManager.hasPermissionU01(principal, 1)")
@RequestMapping(value = "/u01", method = RequestMethod.GET)
public String listU01(HttpServletRequest request, Map<String, Object> map) throws Exception {
    setGridFilters(map);
    return "u01panel";      
}
Run Code Online (Sandbox Code Playgroud)

我在PermissionManager.hasPermissionU01中设置断点。看来我的安全注释只是被忽略了。

是什么原因?我的错误在哪里?

谢谢。

更新结束

经过数小时的搜寻后,我必须在这里询问。我有

  1. Spring MVC应用
  2. CustomUserDetailService
  3. 自定义UserDetails类

    public class Benutzer extends User implements UserDetails {
    ...
      private Permission …
    Run Code Online (Sandbox Code Playgroud)

java spring-security

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

在java spring项目中使用delphi dll

请帮我把细节放在一起.我已经扫描了很长时间的网络,但结果并不好.

所以我有:

  1. Delphi为JNI编写的DLL(来自32位Delphi的32位comp)

  2. 我的64位MAC上的Java Web项目(Tomcat,Spring)

  3. System.out.println(System.getProperty("java.library.path"))写入"/ tmp",它是正确的

  4. 在/ tmp我有来自delphi的qvs.dll

当我开始项目时,我得到例外:

java.lang.UnsatisfiedLinkError: no qvs in java.library.path
Run Code Online (Sandbox Code Playgroud)
  1. 加载库的Java代码:

    的System.loadLibrary( "QVS")

我尝试了很多具有相同结果的组合.只有一个原因我不能尝试.我可以在64位MAC上使用32位DLL吗?

非常感谢.

java delphi dll java-native-interface

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

不正确的week_of_year

有下一个功能来获得一周中的一周:

static public Integer getWeek(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setMinimalDaysInFirstWeek(1);
    cal.setTime(date);
    Integer week = cal.WEEK_OF_YEAR;
    Integer month = cal.MONTH;
    if ((week == 1) && (month == 12)) week = 52;
    return week;
}
Run Code Online (Sandbox Code Playgroud)

使用date = 02.01.2013调用该函数

我在调试中看到的内容:

  1. date = Wed Jan 02 00:00:00 SAMT 2013
  2. 周= 3
  3. 月= 2

我想得到:周= 1,月= 1.对?

我哪里错了?

JRE 1.6

非常感谢您的进步.

java

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

为什么表单不是自动调整当前分辨率?

我有一个Firemonkey HD应用程序并将其部署在iPad 2上.工作正常.

当我在带有Retina显示屏的iPad 4上部署相同的应用程序时,我遇到了问题.

关键是我在表单上有一些绘图操作,需要精确的表格宽度和高度.

ShowMessage('form wh = ' + FloatToStr(TForm(FImage.Parent.Parent). Width) + ':' + FloatToStr(TForm(FImage.Parent.Parent).Height));
Run Code Online (Sandbox Code Playgroud)

在两台设备上我收到一条消息:

form wh = 1024:748
Run Code Online (Sandbox Code Playgroud)

我需要的是自动更改表单大小.

我该怎么做才能得到它?

更新:我尝试使用Screen.Size.Width但在Retina显示屏上有Screen.Size.Width = 1024.我做错了什么?

delphi ios retina-display firemonkey delphi-xe5

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