小编aba*_*rik的帖子

使用Ctrl + A选择文本框Selenium RC中的所有文本

我试图选择文本框中的所有文本以清除文本框.我使用Ctrl + A在Selenium RC独立2.20.0.jar上使用以下Python 2.7代码执行此操作Windows 7 Firefox上的服务器:

from selenium import selenium
s = selenium('remote-machine-ip', 4444, '*chrome', 'http://my-website-with-textbox')
locator = 'mylocator-of-textbox'
s.open()
s.type(locator, 'mytext')
s.focus(locator)
s.control_key_down()
s.key_down(locator, "A")
s.key_press(locator, "A")
s.key_up(locator, "A")
s.control_key_up()

# Nothing happens here... I cannot see the text getting selected...

# Nothing gets cleared here except the last char
s.key_down(locator, chr(8))  # Pressing backspace
s.key_press(locator, chr(8))
s.key_up(locator, chr(8))
Run Code Online (Sandbox Code Playgroud)

有帮助吗?谢谢,阿米特

python selenium

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

检查 Collection 或 Map 是否为空或 null 的方法?

我想检查 Map、HashMap、ArrayList、List 或 Collections 中的任何内容是否为空或为 null?

我有这个,但当我传递地图时它不起作用:

protected static <T extends Collection, Map> boolean isCollectionMapNullOrEmpty(final T c) {
  if (c == null) {
      return true;
  }

  return c.isEmpty();
 }
Run Code Online (Sandbox Code Playgroud)

失败:

  List<String> aList = Arrays.asList("a1", "a2", "a4");
  Map<String, Object> aMap = new HashMap<String, Object>();
  aMap.put("a2", "foo");
  aMap.put("a1", "foo");
  aMap.put("a3", "foo");
  aMap.put("a4", "foo");
  System.out.println(isCollectionMapNullOrEmpty(aList));  // works

  // fails with The method isCollectionMapNullOrEmpty(T) in the type LearnHashMap is not applicable for the arguments (Map<String,Object>)
  System.out.println(isCollectionMapNullOrEmpty(aMap));
Run Code Online (Sandbox Code Playgroud)

java generics collections dictionary

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

使用ImageMagick和Tesseract从图像获取文本

我想知道是否有人使用过Tesseract和ImageMagick来从图像中获取精确的文本。我主要关心的是图像中的小字体文本(或一些看不清的文本)。我能够检索那些不清楚的文本的唯一方法是通过ImageMagick修改图像,例如-缩放图像,有时裁剪图像。

我想知道是否有人集成了ImageMagick和Tesseract来创建甚至功能强大的工具?

tesseract imagemagick

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

d3 js可以达到多少

我正在尝试构建一个网络图(如大脑网络)来显示数百万个节点.我想知道在一个图表上添加更多网络节点方面我可以在多大程度上推动d3 js?

例如,http://linkedjazz.org/network/http://fatiherikli.github.io/programming-language-network/#foundation:Cappuccino

我不熟悉d3.js(虽然我是一个JS开发人员),我只是想知道d3.js是否是构建大规模网络可视化(一百万个节点+)的正确工具,然后我开始查看其他一些工具.

我的要求很简单:构建一个可扩展的基于互动网络的网络可视化

javascript scalability neural-network d3.js

3
推荐指数
2
解决办法
3353
查看次数

一对标记传单之间并排的两条折线

如何在 leaflet.js 中的一对标记之间并排放置两条或多条折线?

\n\n

这是代码,我没有看到这种情况发生:http ://jsfiddle.net/abarik/q9bxL1z6/1/

\n\n
// HTML\n<div id="map" style="height:500px;"></div>\n\n//example user location\nvar userLocation = new L.LatLng(35.974, -83.496);\n\nvar map = L.map(\'map\', \n      {center: userLocation,\n        zoom: 1,\n          worldCopyJump: true,\n      });\nL.tileLayer(\'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png\', {\n    maxZoom: 18,\n    attribution: \'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery \xc2\xa9 <a href="http://cloudmade.com">CloudMade</a>\'\n}).addTo(map);\n\n\nvar marker = new L.circleMarker(userLocation, {radius:10, fillColor:\'red\'});\nmap.addLayer(marker);\n\n//random locations around the world\nvar items = [{\n    //china\n    lat: "65.337",\n    lon: "158.027"\n}, {\n    //colombia\n    lat: "2.389",\n    lon: "-72.598"\n}];\n\ndrawData();\n\n//draw all the data on the map\nfunction drawData() {\n    var …
Run Code Online (Sandbox Code Playgroud)

javascript leaflet

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

使用node.js加密加密aes256并使用python2.7 PyCrypto解密

我正在尝试使用node.js进行加密,如下所示(node.js v0.10.33):

var crypto = require('crypto');
var assert = require('assert');

var algorithm = 'aes256'; // or any other algorithm supported by OpenSSL
var key = 'mykey';
var text = 'this-needs-to-be-encrypted';

var cipher = crypto.createCipher(algorithm, key);  
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex');
console.log('encrypted', encrypted, encrypted.length)
/*
var decipher = crypto.createDecipher(algorithm, key);
try {
    var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
} catch (e) {
    console.error('Couldnt decipher encrypted text. Invalid key provided', e)
} finally {
    assert.equal(decrypted, text);
} …
Run Code Online (Sandbox Code Playgroud)

python cryptography pycrypto node.js

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

每个数据库行发出一次socket.io性能

我试图了解什么是读取和发送大量数据库行(50K-100K)到客户端的最佳方法.

  1. 我应该只是从后端的数据库中读取所有行,然后以json格式发送所有行吗?由于用户只是等待了很长时间,因此响应速度不是很快,但对于小编号而言,这个速度更快.的行.

  2. 我应该从数据库中流式传输行,每次从数据库中读取行时,我都会调用socket.emit()吗?这导致套接字发出太多,但响应速度更快,但速度慢......

我正在使用node.js,socket.io

mysql node.js socket.io

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

Django - allauth - 防止未经身份验证的用户查看针对经过身份验证的用户的页面

我试图使用Django与allauth尝试创建一个登录页面.

我能够成功登录并将用户重定向到LOGIN_REDIRECT_URL(="users/{id}/mypage")页面.我有/ users/{id}/mypage的单独视图,名为views.py中定义的UserHomePageView:

from django.views.generic import TemplateView

class UserHomePageView(TemplateView):
    template_name = "user_homepage.html"
Run Code Online (Sandbox Code Playgroud)

我想要一个安全措施来阻止任何人(基本上是非登录用户)导航到"/ users/{id}/mypage"(例如/ users/5/mypage).ei如果未经身份验证的用户尝试导航到/ users/5/mypage,他/她应该被重定向到登录页面/主页.

基本上,我如何呈现未经身份验证的用户来查看针对经过身份验证的用户的页面(我不想使用模板标签users.authenitcated,但希望覆盖TemplateView)

django django-allauth

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

在dict Python列表中的相同dict对象

为什么在Python中,使用n*[dict()]来创建嵌套字典导致相同的字典对象?

>>> d = [(111, 2222), (3333, 4444), (555, 666)]
>>> d
[(111, 2222), (3333, 4444), (555, 666)]
>>> x = len(d) * [dict().copy()][:]
>>> x
[{}, {}, {}]
>>> x[0]['x'] = 'u'
>>> x # All entries of x gets modified
[{'x': 'u'}, {'x': 'u'}, {'x': 'u'}]
>>> 
>>> x = [dict(), dict(), dict()]
>>> x
[{}, {}, {}]
>>> x[0]['x'] = 'u'
>>> x # only one entry of x gets modified
[{'x': 'u'}, {}, {}]
>>> 
Run Code Online (Sandbox Code Playgroud)

python dictionary list

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

为什么python tarfile gz没有减少文件大小

所以,我试图将每个10MB的3个文本文件压缩为一个文件作为tar.gz,但它似乎没有减少最终的tar.gz. 最终的tar.gz文件大小仍然是30MB.

谁能告诉我为什么会这样?我有最高级别的压缩

>>> import os
>>> import sys
>>> import tarfile
>>> import tempfile
tarmode="w:gz"):
    ''>>> size_in_mb = 10
>>>
>>> def compress_str_to_tar(tmppath, files_str, tarfileprefix, tarmode="w:gz"):
...     ''' compress string contents in files and tar. finally creates a tar file in tmppath
...     @param tmppath: (str) pathdirectory where temp files to be compressed will be created
...     @param files_str: (dict) {filename: filecontent_in_str} these will be compressed
...     @param tarfileprefix: (str) output filename (without suffix) of tar
...     @param tarmode: …
Run Code Online (Sandbox Code Playgroud)

python compression gzip tar

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

使用python mock测试子模块中的函数的最佳实践

所以,考虑我有一个简单的库,我正在尝试编写单元测试.该库与数据库通信,然后使用该数据调用SOAP API.我有三个模块,每个模块都有一个测试文件.

目录结构:

./mypkg
    ../__init__.py
    ../main.py
    ../db.py
    ../api.py

./tests
    ../test_main
    ../test_db
    ../test_api
Run Code Online (Sandbox Code Playgroud)

码:

#db.py
import mysqlclient
class Db(object):
    def __init__(self):
        self._client = mysqlclient.Client()

    @property
    def data(self):
        return self._client.some_query()


#api.py
import soapclient
class Api(object):
    def __init__(self):
        self._client = soapclient.Client()

    @property
    def call(self):
        return self._client.some_external_call()


#main.py
from db import Db
from api import Api

class MyLib(object):
    def __init__(self):
        self.db = Db()
        self.api = Api()

    def caller(self):
        return self.api.call(self.db.data)
Run Code Online (Sandbox Code Playgroud)

单元测试:

#test_db.py
import mock
from mypkg.db import Db

@mock.patch('mypkg.db.mysqlclient')
def test_db(mysqlclient_mock):
    mysqlclient_mock.Client.return_value.some_query = {'data':'data'} …
Run Code Online (Sandbox Code Playgroud)

python unit-testing mocking python-mock

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