mirror of
https://github.com/mistergibson/gxg-framework.git
synced 2026-08-15 03:46:00 -07:00
added as_segments to ::IO and ::GxG::ByteArray
This commit is contained in:
parent
b1e71001cc
commit
132fc22671
6 changed files with 543 additions and 471 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'gxg-framework'
|
s.name = 'gxg-framework'
|
||||||
s.version = '0.0.54'
|
s.version = '0.0.55'
|
||||||
s.licenses = ['UNLICENSED']
|
s.licenses = ['UNLICENSED']
|
||||||
s.summary = "GxG Framework"
|
s.summary = "GxG Framework"
|
||||||
s.description = "GxG Framework"
|
s.description = "GxG Framework"
|
||||||
|
|
@ -38,31 +38,31 @@ Gem::Specification.new do |s|
|
||||||
s.add_runtime_dependency 'state_machines'
|
s.add_runtime_dependency 'state_machines'
|
||||||
s.add_runtime_dependency 'net-ldap'
|
s.add_runtime_dependency 'net-ldap'
|
||||||
# ### Database Adapters:
|
# ### Database Adapters:
|
||||||
# if ::RUBY_ENGINE == "jruby"
|
if ::RUBY_ENGINE == "jruby"
|
||||||
# s.add_runtime_dependency 'jdbc-sqlite3'
|
s.add_runtime_dependency 'jdbc-sqlite3'
|
||||||
# s.add_runtime_dependency 'jdbc-mysql'
|
s.add_runtime_dependency 'jdbc-mysql'
|
||||||
# s.add_runtime_dependency 'jdbc-postgresql'
|
s.add_runtime_dependency 'jdbc-postgresql'
|
||||||
# s.add_runtime_dependency 'jdbc-as400'
|
s.add_runtime_dependency 'jdbc-as400'
|
||||||
# s.add_runtime_dependency 'jdbc-cassandra'
|
s.add_runtime_dependency 'jdbc-cassandra'
|
||||||
# s.add_runtime_dependency 'jdbc-crate'
|
s.add_runtime_dependency 'jdbc-crate'
|
||||||
# s.add_runtime_dependency 'jdbc-derby'
|
s.add_runtime_dependency 'jdbc-derby'
|
||||||
# s.add_runtime_dependency 'jdbc-filemaker'
|
s.add_runtime_dependency 'jdbc-filemaker'
|
||||||
# s.add_runtime_dependency 'jdbc-firebird'
|
s.add_runtime_dependency 'jdbc-firebird'
|
||||||
# s.add_runtime_dependency 'jdbc-h2'
|
s.add_runtime_dependency 'jdbc-h2'
|
||||||
# s.add_runtime_dependency 'jdbc-hive2'
|
s.add_runtime_dependency 'jdbc-hive2'
|
||||||
# s.add_runtime_dependency 'jdbc-hsqldb'
|
s.add_runtime_dependency 'jdbc-hsqldb'
|
||||||
# s.add_runtime_dependency 'jdbc-jt400'
|
s.add_runtime_dependency 'jdbc-jt400'
|
||||||
# s.add_runtime_dependency 'jdbc-jtds'
|
s.add_runtime_dependency 'jdbc-jtds'
|
||||||
# s.add_runtime_dependency 'jdbc-luciddb'
|
s.add_runtime_dependency 'jdbc-luciddb'
|
||||||
# s.add_runtime_dependency 'jdbc-mssql'
|
s.add_runtime_dependency 'jdbc-mssql'
|
||||||
# s.add_runtime_dependency 'jdbc-nuodb'
|
s.add_runtime_dependency 'jdbc-nuodb'
|
||||||
# ### FIX : openedge requires external .jars in classpath -- exclude for now.
|
### FIX : openedge requires external .jars in classpath -- exclude for now.
|
||||||
# s.add_runtime_dependency 'jdbc-openedge'
|
s.add_runtime_dependency 'jdbc-openedge'
|
||||||
# s.add_runtime_dependency 'jdbc-orientdb'
|
s.add_runtime_dependency 'jdbc-orientdb'
|
||||||
# s.add_runtime_dependency 'jdbc-phoenix'
|
s.add_runtime_dependency 'jdbc-phoenix'
|
||||||
# ### FIX : redshift is missing the RedshiftJDBC4.jar file -- exclude for now.
|
### FIX : redshift is missing the RedshiftJDBC4.jar file -- exclude for now.
|
||||||
# s.add_runtime_dependency 'jdbc-redshift'
|
s.add_runtime_dependency 'jdbc-redshift'
|
||||||
# s.add_runtime_dependency 'jdbc-splice'
|
s.add_runtime_dependency 'jdbc-splice'
|
||||||
# s.add_runtime_dependency 'jdbc-vertica'
|
s.add_runtime_dependency 'jdbc-vertica'
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -635,6 +635,42 @@ class IO
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
def as_segments(segment_size=65536, as_bytearrays=false, &block)
|
||||||
|
result = []
|
||||||
|
unless self.closed?
|
||||||
|
if segment_size.is_any?(::TrueClass, ::FalseClass, NilClass)
|
||||||
|
as_bytearrays = segment_size
|
||||||
|
segment_size = 65536
|
||||||
|
end
|
||||||
|
saved_position = self.pos
|
||||||
|
self.seek(0, :END)
|
||||||
|
current_size = self.pos + 1
|
||||||
|
#
|
||||||
|
self.rewind
|
||||||
|
if block.respond_to?(:call)
|
||||||
|
GxG::apportioned_ranges(current_size, segment_size).each do |portion_range|
|
||||||
|
self.seek(portion_range.first)
|
||||||
|
if as_bytearrays
|
||||||
|
block.call(bytes self.read(portion_range.size))
|
||||||
|
else
|
||||||
|
block.call(self.read(portion_range.size))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
GxG::apportioned_ranges(current_size, segment_size).each do |portion_range|
|
||||||
|
self.seek(portion_range.first)
|
||||||
|
if as_bytearrays
|
||||||
|
result << bytes self.read(portion_range.size)
|
||||||
|
else
|
||||||
|
result << self.read(portion_range.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#
|
||||||
|
self.pos = saved_position
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
class StringIO
|
class StringIO
|
||||||
|
|
@ -1297,467 +1333,467 @@ module Fcntl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# ### URI alterations
|
# ### URI alterations
|
||||||
module URI
|
# module URI
|
||||||
#
|
# #
|
||||||
def self.parse(*args)
|
# def self.parse(*args)
|
||||||
#::URI::Generic.new(*(::URI::split(*args)))
|
# #::URI::Generic.new(*(::URI::split(*args)))
|
||||||
::URI::Generic::parse(*args)
|
# ::URI::Generic::parse(*args)
|
||||||
end
|
# end
|
||||||
#
|
# #
|
||||||
class Generic
|
# class Generic
|
||||||
#
|
# #
|
||||||
def set_scheme(v)
|
# def set_scheme(v)
|
||||||
if v.is_a?(String)
|
|
||||||
@scheme = v
|
|
||||||
end
|
|
||||||
v
|
|
||||||
end
|
|
||||||
|
|
||||||
def scheme=(scheme="")
|
|
||||||
set_scheme(scheme)
|
|
||||||
scheme
|
|
||||||
end
|
|
||||||
|
|
||||||
def scheme()
|
|
||||||
@scheme
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_userinfo(user, password = nil)
|
|
||||||
unless password
|
|
||||||
user, password = split_userinfo(user)
|
|
||||||
end
|
|
||||||
if user.is_a?(String)
|
|
||||||
@user = URI::escape(user)
|
|
||||||
else
|
|
||||||
@user = user
|
|
||||||
end
|
|
||||||
if password.is_a?(String)
|
|
||||||
@password = URI::escape(password)
|
|
||||||
else
|
|
||||||
@password = password
|
|
||||||
end
|
|
||||||
result = []
|
|
||||||
if @user.is_a?(String)
|
|
||||||
result << URI::unescape(@user)
|
|
||||||
else
|
|
||||||
result << @user
|
|
||||||
end
|
|
||||||
if @password.is_a?(String)
|
|
||||||
result << URI::unescape(@password)
|
|
||||||
else
|
|
||||||
result << @password
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
def userinfo
|
|
||||||
if @user.nil?
|
|
||||||
nil
|
|
||||||
elsif @password.nil?
|
|
||||||
URI::unescape(@user)
|
|
||||||
else
|
|
||||||
URI::unescape(@user) + ':' + URI::unescape(@password)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def user=(user)
|
|
||||||
if user.is_a?(String)
|
|
||||||
user = (URI::escape(user))
|
|
||||||
end
|
|
||||||
set_user(user)
|
|
||||||
self.user
|
|
||||||
# returns user
|
|
||||||
end
|
|
||||||
|
|
||||||
def user
|
|
||||||
if @user.is_a?(String)
|
|
||||||
URI::unescape(@user)
|
|
||||||
else
|
|
||||||
@user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_password(v)
|
|
||||||
if v.is_a?(String)
|
|
||||||
@password = URI::escape(v)
|
|
||||||
end
|
|
||||||
if @password.is_a?(String)
|
|
||||||
URI::unescape(@password)
|
|
||||||
else
|
|
||||||
@password
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def password=(password)
|
|
||||||
if password.is_a?(String)
|
|
||||||
password = (URI::escape(password))
|
|
||||||
end
|
|
||||||
set_password(password)
|
|
||||||
# returns password
|
|
||||||
end
|
|
||||||
|
|
||||||
def password
|
|
||||||
if @password.is_a?(String)
|
|
||||||
URI::unescape(@password)
|
|
||||||
else
|
|
||||||
@password
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_host(v)
|
|
||||||
if v.is_a?(String)
|
|
||||||
@host = URI::escape(v)
|
|
||||||
else
|
|
||||||
@host = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def host=(v)
|
|
||||||
if v.is_a?(String)
|
|
||||||
v = (URI::escape(v))
|
|
||||||
end
|
|
||||||
set_host(v)
|
|
||||||
self.host
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def host()
|
|
||||||
if @host.is_a?(String)
|
|
||||||
URI::unescape(@host)
|
|
||||||
else
|
|
||||||
@host
|
|
||||||
end
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def hostname()
|
|
||||||
if @host.to_s.size > 0
|
|
||||||
self.host().to_s.dup.gsub("[","").gsub("]","")
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def hostname=(v)
|
|
||||||
if (v.to_s.include?(":") || (v.to_s.include?("[") && v.to_s.include?("]")))
|
|
||||||
# ipv6 ??
|
|
||||||
if v.to_s.include?("[") && v.to_s.include?("]")
|
|
||||||
self.host = v.to_s
|
|
||||||
else
|
|
||||||
self.host = "[" << v.to_s << "]"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.host = v.to_s
|
|
||||||
end
|
|
||||||
self.host()
|
|
||||||
end
|
|
||||||
#
|
|
||||||
# def set_registry(v)
|
|
||||||
# if v.is_a?(String)
|
# if v.is_a?(String)
|
||||||
# @registry = URI::escape(v)
|
# @scheme = v
|
||||||
|
# end
|
||||||
|
# v
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def scheme=(scheme="")
|
||||||
|
# set_scheme(scheme)
|
||||||
|
# scheme
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def scheme()
|
||||||
|
# @scheme
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def set_userinfo(user, password = nil)
|
||||||
|
# unless password
|
||||||
|
# user, password = split_userinfo(user)
|
||||||
|
# end
|
||||||
|
# if user.is_a?(String)
|
||||||
|
# @user = URI::escape(user)
|
||||||
# else
|
# else
|
||||||
# @registry = v
|
# @user = user
|
||||||
|
# end
|
||||||
|
# if password.is_a?(String)
|
||||||
|
# @password = URI::escape(password)
|
||||||
|
# else
|
||||||
|
# @password = password
|
||||||
|
# end
|
||||||
|
# result = []
|
||||||
|
# if @user.is_a?(String)
|
||||||
|
# result << URI::unescape(@user)
|
||||||
|
# else
|
||||||
|
# result << @user
|
||||||
|
# end
|
||||||
|
# if @password.is_a?(String)
|
||||||
|
# result << URI::unescape(@password)
|
||||||
|
# else
|
||||||
|
# result << @password
|
||||||
|
# end
|
||||||
|
# result
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def userinfo
|
||||||
|
# if @user.nil?
|
||||||
|
# nil
|
||||||
|
# elsif @password.nil?
|
||||||
|
# URI::unescape(@user)
|
||||||
|
# else
|
||||||
|
# URI::unescape(@user) + ':' + URI::unescape(@password)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def user=(user)
|
||||||
|
# if user.is_a?(String)
|
||||||
|
# user = (URI::escape(user))
|
||||||
|
# end
|
||||||
|
# set_user(user)
|
||||||
|
# self.user
|
||||||
|
# # returns user
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def user
|
||||||
|
# if @user.is_a?(String)
|
||||||
|
# URI::unescape(@user)
|
||||||
|
# else
|
||||||
|
# @user
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def set_password(v)
|
||||||
|
# if v.is_a?(String)
|
||||||
|
# @password = URI::escape(v)
|
||||||
|
# end
|
||||||
|
# if @password.is_a?(String)
|
||||||
|
# URI::unescape(@password)
|
||||||
|
# else
|
||||||
|
# @password
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def password=(password)
|
||||||
|
# if password.is_a?(String)
|
||||||
|
# password = (URI::escape(password))
|
||||||
|
# end
|
||||||
|
# set_password(password)
|
||||||
|
# # returns password
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def password
|
||||||
|
# if @password.is_a?(String)
|
||||||
|
# URI::unescape(@password)
|
||||||
|
# else
|
||||||
|
# @password
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def set_host(v)
|
||||||
|
# if v.is_a?(String)
|
||||||
|
# @host = URI::escape(v)
|
||||||
|
# else
|
||||||
|
# @host = v
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# #
|
# #
|
||||||
# def registry=(v)
|
# def host=(v)
|
||||||
# if v.is_a?(String)
|
# if v.is_a?(String)
|
||||||
# v = (URI::escape(v))
|
# v = (URI::escape(v))
|
||||||
# end
|
# end
|
||||||
# set_registry(v)
|
# set_host(v)
|
||||||
# self.registry
|
# self.host
|
||||||
# end
|
# end
|
||||||
|
# #
|
||||||
# def registry
|
# def host()
|
||||||
# if @registry.is_a?(String)
|
# if @host.is_a?(String)
|
||||||
# URI::unescape(@registry)
|
# URI::unescape(@host)
|
||||||
# else
|
# else
|
||||||
# @registry
|
# @host
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
# #
|
||||||
# def set_path(v)
|
# def hostname()
|
||||||
# if v.is_a?(String)
|
# if @host.to_s.size > 0
|
||||||
# @path = URI::escape(v)
|
# self.host().to_s.dup.gsub("[","").gsub("]","")
|
||||||
# else
|
# else
|
||||||
# @path = v
|
# nil
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
# #
|
||||||
# def path=(v)
|
# def hostname=(v)
|
||||||
# if v.is_a?(String)
|
# if (v.to_s.include?(":") || (v.to_s.include?("[") && v.to_s.include?("]")))
|
||||||
# v = (URI::escape(v))
|
# # ipv6 ??
|
||||||
# end
|
# if v.to_s.include?("[") && v.to_s.include?("]")
|
||||||
# set_path(v)
|
# self.host = v.to_s
|
||||||
# self.path
|
|
||||||
# end
|
|
||||||
|
|
||||||
# def path
|
|
||||||
# if @path.is_a?(String)
|
|
||||||
# URI::unescape(@path)
|
|
||||||
# else
|
# else
|
||||||
# @path
|
# self.host = "[" << v.to_s << "]"
|
||||||
# end
|
# end
|
||||||
# end
|
|
||||||
|
|
||||||
# def set_opaque(v)
|
|
||||||
# if v.is_a?(String)
|
|
||||||
# @opaque = URI::escape(v)
|
|
||||||
# else
|
# else
|
||||||
# @opaque = v
|
# self.host = v.to_s
|
||||||
# end
|
# end
|
||||||
|
# self.host()
|
||||||
# end
|
# end
|
||||||
|
# #
|
||||||
|
# # def set_registry(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # @registry = URI::escape(v)
|
||||||
|
# # else
|
||||||
|
# # @registry = v
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
# # #
|
||||||
|
# # def registry=(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # v = (URI::escape(v))
|
||||||
|
# # end
|
||||||
|
# # set_registry(v)
|
||||||
|
# # self.registry
|
||||||
|
# # end
|
||||||
|
|
||||||
# def opaque=(v)
|
# # def registry
|
||||||
# if v.is_a?(String)
|
# # if @registry.is_a?(String)
|
||||||
# v = (URI::escape(v))
|
# # URI::unescape(@registry)
|
||||||
# end
|
# # else
|
||||||
# set_opaque(v)
|
# # @registry
|
||||||
# self.opaque
|
# # end
|
||||||
# end
|
# # end
|
||||||
|
|
||||||
# def opaque
|
# # def set_path(v)
|
||||||
# if @opaque.is_a?(String)
|
# # if v.is_a?(String)
|
||||||
# URI::unescape(@opaque)
|
# # @path = URI::escape(v)
|
||||||
|
# # else
|
||||||
|
# # @path = v
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def path=(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # v = (URI::escape(v))
|
||||||
|
# # end
|
||||||
|
# # set_path(v)
|
||||||
|
# # self.path
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def path
|
||||||
|
# # if @path.is_a?(String)
|
||||||
|
# # URI::unescape(@path)
|
||||||
|
# # else
|
||||||
|
# # @path
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def set_opaque(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # @opaque = URI::escape(v)
|
||||||
|
# # else
|
||||||
|
# # @opaque = v
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def opaque=(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # v = (URI::escape(v))
|
||||||
|
# # end
|
||||||
|
# # set_opaque(v)
|
||||||
|
# # self.opaque
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def opaque
|
||||||
|
# # if @opaque.is_a?(String)
|
||||||
|
# # URI::unescape(@opaque)
|
||||||
|
# # else
|
||||||
|
# # @opaque
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
# # Review - query modifications bugger MatrixClient logins.
|
||||||
|
# # def set_query(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # @query = URI::escape(v)
|
||||||
|
# # else
|
||||||
|
# # @query = v
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def query=(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # v = (URI::escape(v))
|
||||||
|
# # end
|
||||||
|
# # set_query(v)
|
||||||
|
# # self.query
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def query
|
||||||
|
# # if @query.is_a?(String)
|
||||||
|
# # URI::unescape(@query)
|
||||||
|
# # else
|
||||||
|
# # @query
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def set_fragment(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # @fragment = URI::escape(v)
|
||||||
|
# # else
|
||||||
|
# # @fragment = v
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def fragment=(v)
|
||||||
|
# # if v.is_a?(String)
|
||||||
|
# # v = (URI::escape(v))
|
||||||
|
# # end
|
||||||
|
# # set_fragment(v)
|
||||||
|
# # self.fragment
|
||||||
|
# # end
|
||||||
|
|
||||||
|
# # def fragment
|
||||||
|
# # if @fragment.is_a?(String)
|
||||||
|
# # URI::unescape(@fragment)
|
||||||
|
# # else
|
||||||
|
# # @fragment
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
# #
|
||||||
|
# # def to_s
|
||||||
|
# # str = ''
|
||||||
|
# # if @scheme
|
||||||
|
# # str << @scheme
|
||||||
|
# # str << ':'
|
||||||
|
# # end
|
||||||
|
# # if @opaque
|
||||||
|
# # str << @opaque
|
||||||
|
# # else
|
||||||
|
# # if @registry
|
||||||
|
# # str << @registry
|
||||||
|
# # else
|
||||||
|
# # if @host
|
||||||
|
# # str << '//'
|
||||||
|
# # end
|
||||||
|
# # if self.userinfo
|
||||||
|
# # str << self.userinfo
|
||||||
|
# # str << '@'
|
||||||
|
# # end
|
||||||
|
# # if @host
|
||||||
|
# # str << @host
|
||||||
|
# # end
|
||||||
|
# # if @port && @port != self.default_port
|
||||||
|
# # str << ':'
|
||||||
|
# # str << @port.to_s
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
# # str << @path
|
||||||
|
# # if @query
|
||||||
|
# # str << '?'
|
||||||
|
# # str << @query
|
||||||
|
# # end
|
||||||
|
# # end
|
||||||
|
# # if @fragment
|
||||||
|
# # str << '#'
|
||||||
|
# # str << @fragment
|
||||||
|
# # end
|
||||||
|
# # URI::escape(str)
|
||||||
|
# # end
|
||||||
|
# #
|
||||||
|
# def from_hash(the_hash={})
|
||||||
|
# if the_hash[:scheme]
|
||||||
|
# self.scheme = the_hash[:scheme]
|
||||||
# else
|
# else
|
||||||
# @opaque
|
# @scheme = nil
|
||||||
# end
|
# end
|
||||||
# end
|
# if the_hash[:opaque]
|
||||||
# Review - query modifications bugger MatrixClient logins.
|
# self.opaque = the_hash[:opaque]
|
||||||
# def set_query(v)
|
# @registry = nil
|
||||||
# if v.is_a?(String)
|
# @user = nil
|
||||||
# @query = URI::escape(v)
|
# @password = nil
|
||||||
|
# @host = nil
|
||||||
|
# @port = nil
|
||||||
|
# @path = nil
|
||||||
|
# @query = nil
|
||||||
# else
|
# else
|
||||||
# @query = v
|
# @opaque = nil
|
||||||
# end
|
# if the_hash[:registry]
|
||||||
# end
|
# self.registry = the_hash[:registry]
|
||||||
|
# @user = nil
|
||||||
# def query=(v)
|
# @password = nil
|
||||||
# if v.is_a?(String)
|
# @host = nil
|
||||||
# v = (URI::escape(v))
|
# @port = nil
|
||||||
# end
|
|
||||||
# set_query(v)
|
|
||||||
# self.query
|
|
||||||
# end
|
|
||||||
|
|
||||||
# def query
|
|
||||||
# if @query.is_a?(String)
|
|
||||||
# URI::unescape(@query)
|
|
||||||
# else
|
# else
|
||||||
# @query
|
# @registry = nil
|
||||||
# end
|
# if the_hash[:user]
|
||||||
# end
|
# self.user = the_hash[:user]
|
||||||
|
|
||||||
# def set_fragment(v)
|
|
||||||
# if v.is_a?(String)
|
|
||||||
# @fragment = URI::escape(v)
|
|
||||||
# else
|
# else
|
||||||
# @fragment = v
|
# @user = nil
|
||||||
# end
|
# end
|
||||||
# end
|
# if the_hash[:password]
|
||||||
|
# self.password = the_hash[:password]
|
||||||
# def fragment=(v)
|
|
||||||
# if v.is_a?(String)
|
|
||||||
# v = (URI::escape(v))
|
|
||||||
# end
|
|
||||||
# set_fragment(v)
|
|
||||||
# self.fragment
|
|
||||||
# end
|
|
||||||
|
|
||||||
# def fragment
|
|
||||||
# if @fragment.is_a?(String)
|
|
||||||
# URI::unescape(@fragment)
|
|
||||||
# else
|
# else
|
||||||
# @fragment
|
# @password = nil
|
||||||
|
# end
|
||||||
|
# if the_hash[:host]
|
||||||
|
# self.host = the_hash[:host]
|
||||||
|
# else
|
||||||
|
# @host = nil
|
||||||
|
# end
|
||||||
|
# if the_hash[:port] && the_hash[:port] != self.default_port
|
||||||
|
# self.port = the_hash[:port].to_i
|
||||||
|
# else
|
||||||
|
# @port = nil
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
# if the_hash[:path]
|
||||||
# def to_s
|
# self.path = the_hash[:path]
|
||||||
# str = ''
|
# else
|
||||||
|
# @path = nil
|
||||||
|
# end
|
||||||
|
# if the_hash[:query]
|
||||||
|
# self.query = the_hash[:query]
|
||||||
|
# else
|
||||||
|
# @query = nil
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# if the_hash[:fragment]
|
||||||
|
# self.fragment = the_hash[:fragment]
|
||||||
|
# else
|
||||||
|
# @fragment = nil
|
||||||
|
# end
|
||||||
|
# self
|
||||||
|
# end
|
||||||
|
# #
|
||||||
|
# def to_hash()
|
||||||
|
# result = {}
|
||||||
# if @scheme
|
# if @scheme
|
||||||
# str << @scheme
|
# result[:scheme] = @scheme
|
||||||
# str << ':'
|
|
||||||
# end
|
# end
|
||||||
# if @opaque
|
# if @opaque
|
||||||
# str << @opaque
|
# result[:opaque] = URI::unescape(@opaque)
|
||||||
# else
|
# else
|
||||||
# if @registry
|
# if @registry
|
||||||
# str << @registry
|
# result[:registry] = URI::unescape(@registry)
|
||||||
# else
|
# else
|
||||||
# if @host
|
# if @user
|
||||||
# str << '//'
|
# result[:user] = URI::unescape(@user)
|
||||||
# end
|
# end
|
||||||
# if self.userinfo
|
# if @password
|
||||||
# str << self.userinfo
|
# result[:password] = URI::unescape(@password)
|
||||||
# str << '@'
|
|
||||||
# end
|
# end
|
||||||
# if @host
|
# if @host
|
||||||
# str << @host
|
# result[:host] = URI::unescape(@host)
|
||||||
# end
|
# end
|
||||||
# if @port && @port != self.default_port
|
# if @port && @port != self.default_port
|
||||||
# str << ':'
|
# result[:port] = URI::unescape(@port).to_i
|
||||||
# str << @port.to_s
|
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# str << @path
|
# if @path
|
||||||
|
# result[:path] = URI::unescape(@path)
|
||||||
|
# end
|
||||||
# if @query
|
# if @query
|
||||||
# str << '?'
|
# result[:query] = URI::unescape(@query)
|
||||||
# str << @query
|
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# if @fragment
|
# if @fragment
|
||||||
# str << '#'
|
# result[:fragment] = URI::unescape(@fragment)
|
||||||
# str << @fragment
|
|
||||||
# end
|
# end
|
||||||
# URI::escape(str)
|
# result
|
||||||
|
# end
|
||||||
|
# #
|
||||||
|
# def address_info()
|
||||||
|
# ::Addrinfo::parse(self)
|
||||||
|
# end
|
||||||
|
# #
|
||||||
|
# def resolve_host()
|
||||||
|
# case @scheme
|
||||||
|
# when "inproc"
|
||||||
|
# # no-op
|
||||||
|
# when "ipc", "unix"
|
||||||
|
# # no-op
|
||||||
|
# when "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"
|
||||||
|
# self.hostname = ::TCPSocket.getaddress(self.hostname)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# #
|
||||||
# end
|
# end
|
||||||
#
|
|
||||||
def from_hash(the_hash={})
|
|
||||||
if the_hash[:scheme]
|
|
||||||
self.scheme = the_hash[:scheme]
|
|
||||||
else
|
|
||||||
@scheme = nil
|
|
||||||
end
|
|
||||||
if the_hash[:opaque]
|
|
||||||
self.opaque = the_hash[:opaque]
|
|
||||||
@registry = nil
|
|
||||||
@user = nil
|
|
||||||
@password = nil
|
|
||||||
@host = nil
|
|
||||||
@port = nil
|
|
||||||
@path = nil
|
|
||||||
@query = nil
|
|
||||||
else
|
|
||||||
@opaque = nil
|
|
||||||
if the_hash[:registry]
|
|
||||||
self.registry = the_hash[:registry]
|
|
||||||
@user = nil
|
|
||||||
@password = nil
|
|
||||||
@host = nil
|
|
||||||
@port = nil
|
|
||||||
else
|
|
||||||
@registry = nil
|
|
||||||
if the_hash[:user]
|
|
||||||
self.user = the_hash[:user]
|
|
||||||
else
|
|
||||||
@user = nil
|
|
||||||
end
|
|
||||||
if the_hash[:password]
|
|
||||||
self.password = the_hash[:password]
|
|
||||||
else
|
|
||||||
@password = nil
|
|
||||||
end
|
|
||||||
if the_hash[:host]
|
|
||||||
self.host = the_hash[:host]
|
|
||||||
else
|
|
||||||
@host = nil
|
|
||||||
end
|
|
||||||
if the_hash[:port] && the_hash[:port] != self.default_port
|
|
||||||
self.port = the_hash[:port].to_i
|
|
||||||
else
|
|
||||||
@port = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if the_hash[:path]
|
|
||||||
self.path = the_hash[:path]
|
|
||||||
else
|
|
||||||
@path = nil
|
|
||||||
end
|
|
||||||
if the_hash[:query]
|
|
||||||
self.query = the_hash[:query]
|
|
||||||
else
|
|
||||||
@query = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if the_hash[:fragment]
|
|
||||||
self.fragment = the_hash[:fragment]
|
|
||||||
else
|
|
||||||
@fragment = nil
|
|
||||||
end
|
|
||||||
self
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def to_hash()
|
|
||||||
result = {}
|
|
||||||
if @scheme
|
|
||||||
result[:scheme] = @scheme
|
|
||||||
end
|
|
||||||
if @opaque
|
|
||||||
result[:opaque] = URI::unescape(@opaque)
|
|
||||||
else
|
|
||||||
if @registry
|
|
||||||
result[:registry] = URI::unescape(@registry)
|
|
||||||
else
|
|
||||||
if @user
|
|
||||||
result[:user] = URI::unescape(@user)
|
|
||||||
end
|
|
||||||
if @password
|
|
||||||
result[:password] = URI::unescape(@password)
|
|
||||||
end
|
|
||||||
if @host
|
|
||||||
result[:host] = URI::unescape(@host)
|
|
||||||
end
|
|
||||||
if @port && @port != self.default_port
|
|
||||||
result[:port] = URI::unescape(@port).to_i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if @path
|
|
||||||
result[:path] = URI::unescape(@path)
|
|
||||||
end
|
|
||||||
if @query
|
|
||||||
result[:query] = URI::unescape(@query)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if @fragment
|
|
||||||
result[:fragment] = URI::unescape(@fragment)
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def address_info()
|
|
||||||
::Addrinfo::parse(self)
|
|
||||||
end
|
|
||||||
#
|
|
||||||
def resolve_host()
|
|
||||||
case @scheme
|
|
||||||
when "inproc"
|
|
||||||
# no-op
|
|
||||||
when "ipc", "unix"
|
|
||||||
# no-op
|
|
||||||
when "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"
|
|
||||||
self.hostname = ::TCPSocket.getaddress(self.hostname)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
#
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.parse(uri)
|
# def self.parse(uri)
|
||||||
# Alterations:
|
# # Alterations:
|
||||||
# leading/trailing whitespace removal - intended to reduce false exception conditions (missing regexp bits)
|
# # leading/trailing whitespace removal - intended to reduce false exception conditions (missing regexp bits)
|
||||||
# I think first reported in 2007, but still not fixed. dunno why not.
|
# # I think first reported in 2007, but still not fixed. dunno why not.
|
||||||
while uri[0] == 32
|
# while uri[0] == 32
|
||||||
uri[0] = ""
|
# uri[0] = ""
|
||||||
end
|
# end
|
||||||
if uri.size > 0
|
# if uri.size > 0
|
||||||
while uri[-1] == 32
|
# while uri[-1] == 32
|
||||||
uri[-1] = ""
|
# uri[-1] = ""
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
# attempt to escape all strings going INTO the URI object?
|
# # attempt to escape all strings going INTO the URI object?
|
||||||
uri = URI::escape(uri)
|
# uri = URI::escape(uri)
|
||||||
# End Alterations
|
# # End Alterations
|
||||||
scheme, userinfo, host, port,
|
# scheme, userinfo, host, port,
|
||||||
registry, path, opaque, query, fragment = self.split(uri)
|
# registry, path, opaque, query, fragment = self.split(uri)
|
||||||
|
|
||||||
if scheme && @@schemes.include?(scheme.upcase)
|
# if scheme && @@schemes.include?(scheme.upcase)
|
||||||
@@schemes[scheme.upcase].new(scheme, userinfo, host, port,
|
# @@schemes[scheme.upcase].new(scheme, userinfo, host, port,
|
||||||
registry, path, opaque, query,
|
# registry, path, opaque, query,
|
||||||
fragment)
|
# fragment)
|
||||||
else
|
# else
|
||||||
Generic.new(scheme, userinfo, host, port,
|
# Generic.new(scheme, userinfo, host, port,
|
||||||
registry, path, opaque, query,
|
# registry, path, opaque, query,
|
||||||
fragment)
|
# fragment)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
#
|
#
|
||||||
class Addrinfo
|
class Addrinfo
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -569,6 +569,34 @@ module GxG
|
||||||
def data()
|
def data()
|
||||||
@data
|
@data
|
||||||
end
|
end
|
||||||
|
#
|
||||||
|
def as_segments(segment_size=65536, as_bytearrays=false, &block)
|
||||||
|
result = []
|
||||||
|
if segment_size.is_any?(::TrueClass, ::FalseClass, NilClass)
|
||||||
|
as_bytearrays = segment_size
|
||||||
|
segment_size = 65536
|
||||||
|
end
|
||||||
|
#
|
||||||
|
if block.respond_to?(:call)
|
||||||
|
GxG::apportioned_ranges(self.size, segment_size).each do |portion_range|
|
||||||
|
if as_bytearrays
|
||||||
|
block.call(self[portion_range])
|
||||||
|
else
|
||||||
|
block.call(self[portion_range].to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
GxG::apportioned_ranges(self.size, segment_size).each do |portion_range|
|
||||||
|
if as_bytearrays
|
||||||
|
result << (self[portion_range])
|
||||||
|
else
|
||||||
|
result << (self[portion_range].to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#
|
||||||
|
result
|
||||||
|
end
|
||||||
#
|
#
|
||||||
# instance methods:
|
# instance methods:
|
||||||
def initialize(*args,&block)
|
def initialize(*args,&block)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#
|
# See: https://github.com/crystal-lang/crystal-mysql
|
||||||
if defined?(::External::Database::Mysql)
|
if defined?(::External::Database::Mysql)
|
||||||
else
|
else
|
||||||
|
unless ::RUBY_ENGINE == "jruby"
|
||||||
require "mysql2"
|
require "mysql2"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#
|
# See: https://github.com/will/crystal-pg
|
||||||
if defined?(::External::Database::Postgres)
|
if defined?(::External::Database::Postgres)
|
||||||
else
|
else
|
||||||
|
unless ::RUBY_ENGINE == "jruby"
|
||||||
require "pg"
|
require "pg"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
#
|
# See: https://github.com/crystal-lang/crystal-sqlite3
|
||||||
|
# See: http://sequel.jeremyevans.net/documentation.html
|
||||||
|
# See: https://github.com/jeremyevans/sequel
|
||||||
if defined?(::External::Database::Sqlite)
|
if defined?(::External::Database::Sqlite)
|
||||||
else
|
else
|
||||||
|
unless ::RUBY_ENGINE == "jruby"
|
||||||
require "sqlite3"
|
require "sqlite3"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue