问题已发现,但不清楚为什么常量 T 会一直保留上次的值。 定位是这样: 在 A 文件中有定义了常量,有方法 test
module A
T="test"
def test(var)
var = var + "tt"
puts var
end
end
在B文件中include A,有方法test1
module B
include A
class TT
def test1(T)
test(T)
end
end
TT.new.test1
TT.new.test1
这样调用多次,
T的值就会不断增加
调用两次的结果。
DEBUG 13-04-30 19:18:51 dc_connect.rb:82:in `dc_get': /src/json_data.php?csv_download=1&page=1&sortorder=desc&qtype=json&rp=100&sortname=hot_spot&area_type=city&query=%7B%22realtime%22:true,%22hour%22:%220%22,%22timetype%22:0,%22city%22:%22%E4%BB%BB%E6%84%8F%22,%22date_range%22:%222013-04-30%202013-04-30%22%7D&type=service&
INFO 13-04-30 19:18:51 dcpatronclient.rb:173:in `get': uri:/src/json_data.php?csv_download=1&page=1&sortorder=desc&qtype=json&rp=100&sortname=hot_spot&area_type=city&query=%7B%22realtime%22:true,%22hour%22:%220%22,%22timetype%22:0,%22city%22:%22%E4%BB%BB%E6%84%8F%22,%22date_range%22:%222013-04-30%202013-04-30%22%7D&type=service&&csv_download=1&page=1&sortorder=desc&qtype=json&rp=100&sortname=ap&area_type=hotspot&query=%7B%22realtime%22:true,%22hour%22:%220%22,%22timetype%22:0,%22city%22:%22%22,%22date_range%22:%222013-04-30%202013-04-30%22,%22hotspot_name%22:%22%22,%22hotspot_type%22:%22%22%7
D&type=service&
url 是会变化的,,我单元测试的调用结果是这样,后面的 url 都被不断的加在后面,类似于 uri+=uri,这段代码是作用是向服务器发起 get 的请求,然后解析 csv,在 get 请求发现 uri 被不断 uri+=uri 了,最后长度超长,导致服务返回错误
INFO 13-04-30 19:01:14 judge_result.rb:354:in `judge_export': <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>414 Request-URI Too Large</title>
</head><body>
<h1>Request-URI Too Large</h1>
<p>The requested URL's length exceeds the capacity
limit for this server.<br />
</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at localhost.localdomain Port 80</address>
</body></html>
ERROR 13-04-30 19:01:14 keyword.rb:33:in `execute': 执行关键字中发生异常,异常类: CSV::IllegalFormatError, 异常消息: CSV::IllegalFormatError
ERROR 13-04-30 19:01:14 keyword.rb:43:in `print_bkt': C:/ATT_rake_server_ruby187/ruby/lib/ruby/1.8/csv.rb:607:in `get_row'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/1.8/csv.rb:567:in `shift'
./lib/judge_result.rb:356:in `judge_export'
./lib/operator_page_check.rb:50:in `target_dimension_export'
我在外层是直接调用类方法
def self.dc_get(php,get_header,mode,type="html")
dcclient = getlogon_dc_client(mode)
ATT::KeyLog::debug "#{php}"
ret = dcclient.get(php, get_header)
if type=="html"
return ret.body.to_s
else
res = ret.body.to_s
begin
hash = JSON.parse(res)
return hash
rescue JSON::ParserError
ATT::KeyLog.debug("the operation result is: #{hash.to_s}" )
raise
end
end
end
#coding: utf-8
class DCPatronClient < Patron::Session
attr_accessor :get_header,:post_header,:cookie,:cookie_hash
private:initialize
def initialize
super
@cookie_hash = {"SINFORSESSID"=>"","LifeTime"=>"3600","PHPSESSID"=>""}
end
def DCPatronClient.get_client(url, connect_timeout=120000, insecure=true)
@sess = DCPatronClient.new
@sess.insecure = insecure
@sess.base_url = url
@sess.connect_timeout = connect_timeout
@sess.timeout = connect_timeout/1000
#@sess.handle_cookies # req.headers = self.headers.merge(headers),由于需要手动维护cookie,因此这里不需要加上内部的维护
@sess.get_header={"User-Agent"=>" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E)"}
@sess.post_header={"User-Agent"=>" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E)"}
return @sess
end
def super_post(uri, data, header={})
#ATT::KeyLog::debug "uri:#{uri},data:#{data}"
Patron::Session.instance_method("post").bind(self).call(uri, data, header)
end
#封装get请求
def get(url, data)
get_header = @post_header
get_header["Content-Type"]= "application/x-www-form-urlencoded"
get_header.delete("x-requested-with")
uri = nil
uri = url
if data != nil
if uri.to_s.include?("?")
uri << "&"
else
uri << "?"
end
uri << hash_to_and(data)
end
ATT::KeyLog.info("uri:#{uri}")
return super(uri,get_header)
end
end
#6 楼 @edgar_wang_cn 怎样格式化?在编辑器里面是可以的
#coding: utf-8
class DCPatronClient < Patron::Session
attr_accessor :get_header,:post_header,:cookie,:cookie_hash
private:initialize
def initialize
super
@cookie_hash = {"SINFORSESSID"=>"","LifeTime"=>"3600","PHPSESSID"=>""}
end
def DCPatronClient.get_client(url, connect_timeout=120000, insecure=true)
@sess = DCPatronClient.new
@sess.insecure = insecure
@sess.base_url = url
@sess.connect_timeout = connect_timeout
@sess.timeout = connect_timeout/1000
#@sess.handle_cookies # req.headers = self.headers.merge(headers),由于需要手动维护cookie,因此这里不需要加上内部的维护
@sess.get_header={"User-Agent"=>" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E)"}
@sess.post_header={"User-Agent"=>" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E)"}
return @sess
end
def super_post(uri, data, header={})
#ATT::KeyLog::debug "uri:#{uri},data:#{data}"
Patron::Session.instance_method("post").bind(self).call(uri, data, header)
end
#封装get请求
def get(url, data)
get_header = @post_header
get_header["Content-Type"]= "application/x-www-form-urlencoded"
get_header.delete("x-requested-with")
uri = nil
uri = url
if data != nil
if uri.to_s.include?("?")
uri << "&"
else
uri << "?"
end
uri << hash_to_and(data)
end
ATT::KeyLog.info("uri:#{uri}")
return super(uri,get_header)
end
end
#6 楼 @edgar_wang_cn 谢谢你。
已排查了一遍,发现 Uri 每次都保有值,,即使 uri = nil,个人觉得是 super 的问题 #1 楼 @chenge
private:initialize def initialize super @cookie_hash = {"SINFORSESSID"=>"","LifeTime"=>"3600","PHPSESSID"=>""} end
#封装 get 请求 def get(url, data) get_header = @post_header get_header["Content-Type"]= "application/x-www-form-urlencoded" get_header.delete("x-requested-with") uri = nil uri = url if data != nil if uri.to_s.include?("?") uri << "&" else uri << "?" end uri << hash_to_and(data) end
ATT::KeyLog.info("uri:#{uri}") return super(uri,get_header) //问题 end
#10 楼 @luikore 你真厉害,得多向你学习。 是 1.87。 试了下,提示无效的正则表达式 test_create_mem_u_log(TestAreaCenterClientOperation): ATT::Exceptions::LoadError: loading C:/operator/keywords/helper/area_center/area_center_client_operation.rb error: C:/operator/keywords/helper/area_center/area_center_client_operation.rb:231: invalid regular expression: /(\xe4[xb8-\xbf][\x80-\xbf]|[\xe5-xe8][\x80-\xbf][\x80-\xbf]|\xe9[\x80-\xbd][\x80-\xbf]|\xe9\xbe[\x80-\xa5])+/ C:/operator/keywords/helper/area_center/area_center_client_operation.rb:237: invalid regular expression: /(\xe4[xb8-\xbf][\x80-\xbf]|[\xe5-xe8][\x80-\xbf][\x80-\xbf]|\xe9[\x80-\xbd][\x80-\xbf]|\xe9\xb e[\x80-\xa5])+/ C:/ATT_rake_server_ruby187/ruby/lib/ruby/gems/1.8/gems/att-1.1.0/lib/att/load_keyword.rb:76:in `require_file'
#15 楼 @luikore s = File.read("#{path}/#{filename}.dat").gsub(/"\r\n"/,"\n") File.open(s,"w"){|f| f << s }
1) Error: test_create_authinfo_log(TestAreaCenterClientOperation): Errno::EINVAL: Invalid argument - 491899858 00:05:00 1 2 2 90000 |21:1| 2 3158984320 00:05:00 1 2 2 90000 |21:1| 2 2 85000 |10000:5| 3508624407 00:05:00 1 2 2 90000 |21:1| 2 2 85000 |10000:5|
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:60:in initialize'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:60:in
open'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:60:in create_authinfo_log'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:50:in
times'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:50:in create_authinfo_log'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/1.8/delegate.rb:159:in
send'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/1.8/delegate.rb:159:in method_missing'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/gems/1.8/gems/att-1.1.0/lib/att/keyword_manager.rb/../../att/t
test_area_center_client_operation.rb:16:in
test_create_authinfo_log'
我代码是在 windows 服务器上创建的,ftp 上传到的 linux 服务器,2 台不同的服务器传输
偏方不能治本 (=@__@=) 哪。。
提示没有 to_csv 的方法,请教下是什么问题
class ConvertMacToint
def initialize
end
def crc32(c) n = c.length r = 0xFFFFFFFF n.times do |i| r ^= c[i] 8.times do if (r & 1)!=0 r = (r>>1) ^ 0xEDB88320 else r >>= 1 end end end puts r ^ 0xFFFFFFFF
end
end
mac = ConvertMacToint.new mac.crc32("aa::bb::cc::dd::ee::ff") 用了下这样的方法,不知道对不
谢谢大家
已经搞定,是回车问题。。,用 strip 再处理下就好了。
#4 楼 @themorecolor 项目因素,纠结。。。
#18 楼 @zj0713001 这样不行