小编Jam*_*son的帖子

在Parsed XML中忠实地保留注释(Python 2.7)

在操作XML时,我希望尽可能忠实地保留注释.

我设法保留了评论,但内容正在进行XML转义.

#!/usr/bin/env python
# add_host_to_tomcat.py

import xml.etree.ElementTree as ET
from CommentedTreeBuilder import CommentedTreeBuilder
parser = CommentedTreeBuilder()

if __name__ == '__main__':
    filename = "/opt/lucee/tomcat/conf/server.xml"

    # this is the important part: use the comment-preserving parser
    tree = ET.parse(filename, parser)

    # get the node to add a child to
    engine_node = tree.find("./Service/Engine")

    # add a node: Engine.Host
    host_node = ET.SubElement(
        engine_node,
        "Host",
        name="local.mysite.com",
        appBase="webapps"
    )
    # add a child to new node: Engine.Host.Context
    ET.SubElement(
        host_node,
        'Context',
        path="",
        docBase="/path/to/doc/base"
    )

    tree.write('out.xml')
Run Code Online (Sandbox Code Playgroud)
#!/usr/bin/env python …
Run Code Online (Sandbox Code Playgroud)

python xml elementtree python-2.7

13
推荐指数
4
解决办法
6979
查看次数

使用Maven进行Jar程序集时如何排除某些Jar依赖项

StackOverflow上有一些非常相似的问题,但是我找不到有用的东西.

现在,我正在尝试从构建的Jar中删除log4j.

虽然我是Maven的新手,但我确信我错了,这就是我正在尝试的.

pom.xml中:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.icf.onecpd</groupId>
    <artifactId>pdfgen</artifactId>
    <version>1.1</version>
    <packaging>jar</packaging>

    <name>PDF Generator</name>
    <url></url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.2.0</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                        </configuration>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <scm>
        <url>https://svn.tms.icfi.com/svn/HUD/onecpd/income_calculator_pdf_generator</url>
    </scm>
</project>
Run Code Online (Sandbox Code Playgroud)

assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" …
Run Code Online (Sandbox Code Playgroud)

jar maven maven-assembly-plugin

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

在Apache 2.2虚拟主机中组合基本身份验证和LimitExcept

我正在尝试满足以下要求(在Apache HTTPD 2.2中):

  • 如果HTTP方法不是HEAD,POST或GET,则不允许访问,无论以下是什么.
  • 如果用户是内部用户,则允许访问而不进行基本身份验证质询.
  • 如果用户是外部用户,请使用基本身份验证进行质询,并在他们拥有良好凭据时允许.

这是我尝试过的很多事情之一,但我尝试的所有事情都没有达到所有这三个要求:

<Directory /path/to/wwwroot>
    Options FollowSymLinks
    AllowOverride FileInfo

    # Basic Authentication
    AuthType Basic
    AuthName "Enter your site username and password."
    AuthUserFile /path/to/stage.passwords
    AuthGroupFile /path/to/stage.groups
    Require group stageusers

    # there's more logic for this variable in the real virtual_host.
    # for this simplified example, manually set (using the following)
    # or unset (using !internal_user).
    SetEnv internal_user

    Order deny,allow
    Deny from all
    Allow from env=internal_user

    <LimitExcept HEAD POST GET>
        Deny from all
    </LimitExcept>

    Satisfy all

</Directory>
Run Code Online (Sandbox Code Playgroud)

我已阅读有关满足,限制,限制,订单和基本身份验证的文档,但我无法将各个部分放在一起. …

apache virtualhost basic-authentication http-method

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

获得ColdFusion调用的Web服务以使用JavaLoader加载的对象

是否可以使用JavaLoader获取由CF调用的Web服务返回的对象,并且加载JavaLoader的对象是相同的类路径上下文?我的意思是,没有太多困难?

// get a web service
ws = createObject("webservice", local.lms.wsurl);
// user created by coldfusion
user = ws.GenerateUserObject();
/* user status created by java loader.
** this api provider requires that you move the stubs
** (generated when hitting the wsdl from CF for the first time)
** to the classpath.
** this is one of the stubs/classes that gets called from that.
*/
UserStatus = javaLoader.create("com.geolearning.geonext.webservices.Status");
// set user status: classpath context clash
user.setStatus(UserStatus.Active);
Run Code Online (Sandbox Code Playgroud)

错误:

  • 详细信息:要么没有指定方法名称和参数类型的方法,要么setStatus方法使用ColdFusion无法可靠解密的参数类型重载.ColdFusion找到了0个与提供的参数匹配的方法.如果这是一个Java对象并且您验证了该方法存在,请使用javacast函数来减少歧义.
  • 消息:找不到setStatus方法.
  • MethodName setStatus …

coldfusion web-services classpath coldfusion-9 javaloader

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

SQL中的聚合函数划分不符合预期

我正在尝试在SQL Server 2008 R2中做一些交叉表.那部分没关系,但是,如果我试图获得每个单元格的百分比,我就会遇到问题.

这是一个蒸馏用例:一项调查,人们给出他们喜欢的颜色和他们喜欢的水果.我想知道有多少像给定的水果和给定的颜色:

with survey as (
    select 'banana' fav_fruit, 'yellow' fav_color
     union select 'banana', 'red'
     union select 'apple', 'yellow'
     union select 'grape', 'red'
     union select 'apple', 'blue'
     union select 'orange', 'purple'
     union select 'pomegranate', 'green'
)
select
    s.fav_color, 
    sum(case 
          when s.fav_fruit = 'banana' then 1
          else 0
        end) as banana, 
    sum(case 
           when s.fav_fruit = 'banana' then 1
           else 0
         end) / sum(1)   -- why does division always yield 0? "+", "-", and "*" all behave as expected. …
Run Code Online (Sandbox Code Playgroud)

sql sql-server crosstab aggregate-functions division

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

Adobe ColdFusion 9中的"JVM和Java设置"CF管理页面在哪里

许多指南都引用了"JVM和Java设置"页面(在CF管理员中)来操作Adobe ColdFusion中的类路径.(我碰巧在ACF9上.)

我在Linux(Ubuntu)上运行多服务器ACF9,但我无法在任何地方找到该页面.

CF管理员http://i45.tinypic.com/1zfrm0z.png

它在哪里,和/或我如何操纵CF类路径?(特别是,我想为一个特定的实例修改它.)

java coldfusion classpath

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

为 Python Click CLI 脚本提供 STDIN 或文件路径名选项

我是第一次尝试 Click,但我遇到了绊脚石。

我希望我的(两个)子命令要么采用文件路径名选项,要么接受来自 STDIN 的文件内容。

  • 允许:使用 --compose-file 的路径

    ./docker-secret-helper.py secret-hash-ini --compose-file docker-compose-test.yml
    
    Run Code Online (Sandbox Code Playgroud)
  • 允许:使用文件内容作为标准输入

    cat docker-compose-test.yml | ./docker-secret-helper.py secret-hash-ini
    
    Run Code Online (Sandbox Code Playgroud)

    (是否应该有一个选项来指示标准输入,例如-i,,或其他什么?)

  • 不允许: --compose-file 和 stdin 都没有通过

    ./docker-secret-helper.py secret-hash-ini
    
    Run Code Online (Sandbox Code Playgroud)

    应该返回如下内容: You must either pass --compose-file or pipe in stdin.

当前脚本

我当前的脚本接受(仅)文件路径名(通过--compose-file):

#!/usr/bin/env python

import click
from DockerSecretHelper import DockerSecretHelper

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])

@click.group(context_settings=CONTEXT_SETTINGS)
def cli():
    pass

@cli.command(help="retrieves an ini-style file of variables to be used as env vars for docker-compose commmand")
@click.option('--compose-file', help='compose file to work …
Run Code Online (Sandbox Code Playgroud)

python python-click

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

使用详细信息在ColdFusion中记录慢速页面的时间超过[n]秒

(ACF9)

除非有一个我缺少的选项,"记录慢于[n]秒的慢速页面"设置对于基于前端控制器的站点没有用(例如,Model-Glue,FW/1,Fusebox,Mach-II,等等.).

例如,在Mura/Framework-One网站中,我最终得到:

"Warning","jrpp-186","04/25/13","15:26:36",,"Thread: jrpp-186, processing template: /home/mysite/public_html_cms/wwwroot/index.cfm, completed in 11 seconds, exceeding the 10 second warning limit"
"Warning","jrpp-196","04/25/13","15:27:11",,"Thread: jrpp-196, processing template: /home/mysite/public_html_cms/wwwroot/index.cfm, completed in 59 seconds, exceeding the 10 second warning limit"
"Warning","jrpp-214","04/25/13","15:28:56",,"Thread: jrpp-214, processing template: /home/mysite/public_html_cms/wwwroot/index.cfm, completed in 32 seconds, exceeding the 10 second warning limit"
"Warning","jrpp-134","04/25/13","15:31:53",,"Thread: jrpp-134, processing template: /home/mysite/public_html_cms/wwwroot/index.cfm, completed in 11 seconds, exceeding the 10 second warning limit"
Run Code Online (Sandbox Code Playgroud)

有没有办法在那里获取查询字符串或发布详细信息,还是有另一种方式来获取我所追求的内容?

coldfusion monitoring error-logging front-controller coldfusion-9

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